@mainsoft/agent-cms 0.6.1 → 0.10.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 (111) hide show
  1. package/CHANGELOG.md +65 -0
  2. package/README.md +303 -32
  3. package/TODO.md +72 -26
  4. package/UPGRADE-0.10.md +36 -0
  5. package/UPGRADE-0.8.md +117 -0
  6. package/dist/agent.cjs +39 -17
  7. package/dist/agent.d.cts +2 -2
  8. package/dist/agent.d.ts +2 -2
  9. package/dist/agent.js +9 -7
  10. package/dist/bin.js +4528 -355
  11. package/dist/{chunk-OQ55GEF3.js → chunk-3OPKTBEI.js} +1 -1
  12. package/dist/chunk-6PB4ZCHH.js +328 -0
  13. package/dist/chunk-7SCYDG2G.js +2943 -0
  14. package/dist/chunk-7WJIIJCI.js +544 -0
  15. package/dist/chunk-7Y6TU2UA.js +150 -0
  16. package/dist/{chunk-BTO42652.js → chunk-AKCXMT3X.js} +19 -24
  17. package/dist/{chunk-QC2M4NZY.js → chunk-BFVBHIHV.js} +72 -1
  18. package/dist/chunk-DSJETZT4.js +493 -0
  19. package/dist/{chunk-IW3D4I7Q.js → chunk-IU2SMWAM.js} +246 -4
  20. package/dist/{chunk-VICZ76TR.js → chunk-KAO3Z3CF.js} +43 -2
  21. package/dist/{chunk-CRDW6Q72.js → chunk-MA6VKJ3F.js} +87 -25
  22. package/dist/{chunk-6K5ZTGHQ.js → chunk-PEQY4N73.js} +16 -0
  23. package/dist/{chunk-DOADAH4L.js → chunk-PGV2QPIL.js} +40 -0
  24. package/dist/{chunk-QIUXAUQ6.js → chunk-TOZQYJFG.js} +1 -1
  25. package/dist/cli.cjs +4528 -355
  26. package/dist/cli.d.cts +19 -3
  27. package/dist/cli.d.ts +19 -3
  28. package/dist/cli.js +206 -16
  29. package/dist/client.cjs +72 -1
  30. package/dist/client.d.cts +308 -6
  31. package/dist/client.d.ts +308 -6
  32. package/dist/client.js +1 -1
  33. package/dist/cms-C_vkAxYV.d.cts +1537 -0
  34. package/dist/cms-pqJyowu1.d.ts +1537 -0
  35. package/dist/config.d.cts +7 -1
  36. package/dist/config.d.ts +7 -1
  37. package/dist/drizzle-repo-CviH3EX7.d.cts +146 -0
  38. package/dist/drizzle-repo-DWLD0rWe.d.ts +146 -0
  39. package/dist/errors.cjs +82 -1
  40. package/dist/errors.d.cts +43 -3
  41. package/dist/errors.d.ts +43 -3
  42. package/dist/errors.js +2 -2
  43. package/dist/frontmatter.d.cts +5 -4
  44. package/dist/frontmatter.d.ts +5 -4
  45. package/dist/http.cjs +644 -97
  46. package/dist/http.d.cts +59 -2
  47. package/dist/http.d.ts +59 -2
  48. package/dist/http.js +204 -14
  49. package/dist/index.cjs +3759 -575
  50. package/dist/index.d.cts +8 -8
  51. package/dist/index.d.ts +8 -8
  52. package/dist/index.js +226 -30
  53. package/dist/markdown.cjs +89 -25
  54. package/dist/markdown.d.cts +57 -3
  55. package/dist/markdown.d.ts +57 -3
  56. package/dist/markdown.js +5 -1
  57. package/dist/mcp.cjs +319 -39
  58. package/dist/mcp.d.cts +15 -4
  59. package/dist/mcp.d.ts +15 -4
  60. package/dist/mcp.js +14 -9
  61. package/dist/messages/en.cjs +40 -0
  62. package/dist/messages/en.js +1 -1
  63. package/dist/messages/ko.cjs +40 -0
  64. package/dist/messages/ko.js +40 -0
  65. package/dist/registry/cms-audit.json +1 -1
  66. package/dist/registry/cms-doc-editor.json +15 -4
  67. package/dist/registry/cms-doc-list.json +2 -1
  68. package/dist/registry/cms-files.json +29 -0
  69. package/dist/registry/cms-lib.json +3 -3
  70. package/dist/registry/cms-media-picker.json +29 -0
  71. package/dist/registry/cms-media.json +28 -0
  72. package/dist/registry/cms-preview-comments.json +24 -0
  73. package/dist/registry/cms-releases.json +28 -0
  74. package/dist/registry/cms-shell.json +2 -2
  75. package/dist/registry/cms-trash.json +24 -0
  76. package/dist/registry/cms-versions.json +2 -1
  77. package/dist/registry/registry.json +163 -3
  78. package/dist/storage-s3.cjs +168 -0
  79. package/dist/storage-s3.d.cts +53 -0
  80. package/dist/storage-s3.d.ts +53 -0
  81. package/dist/storage-s3.js +143 -0
  82. package/dist/storage.cjs +373 -0
  83. package/dist/storage.d.cts +183 -0
  84. package/dist/storage.d.ts +183 -0
  85. package/dist/storage.js +49 -0
  86. package/dist/tables.cjs +251 -3
  87. package/dist/tables.d.cts +4965 -681
  88. package/dist/tables.d.ts +4965 -681
  89. package/dist/tables.js +14 -2
  90. package/dist/tools.cjs +331 -20
  91. package/dist/tools.d.cts +54 -7
  92. package/dist/tools.d.ts +54 -7
  93. package/dist/tools.js +16 -7
  94. package/dist/types.cjs +99 -1
  95. package/dist/types.d.cts +205 -5
  96. package/dist/types.d.ts +205 -5
  97. package/dist/types.js +5 -3
  98. package/package.json +32 -22
  99. package/dist/ai.cjs +0 -555
  100. package/dist/ai.d.cts +0 -48
  101. package/dist/ai.d.ts +0 -48
  102. package/dist/ai.js +0 -73
  103. package/dist/chunk-52NUUZC7.js +0 -1446
  104. package/dist/chunk-IGL2V6US.js +0 -324
  105. package/dist/chunk-QQV6VLYJ.js +0 -204
  106. package/dist/cms-BPp01z-8.d.ts +0 -411
  107. package/dist/cms-D6D89-qZ.d.cts +0 -411
  108. package/dist/drizzle-repo-B1rt7r4j.d.ts +0 -90
  109. package/dist/drizzle-repo-Cn-kL2FK.d.cts +0 -90
  110. package/dist/repo-BWI2Pkrv.d.ts +0 -162
  111. package/dist/repo-CeDxUxO6.d.cts +0 -162
@@ -0,0 +1,24 @@
1
+ {
2
+ "$schema": "https://ui.shadcn.com/schema/registry-item.json",
3
+ "name": "cms-preview-comments",
4
+ "type": "registry:component",
5
+ "title": "Preview comments",
6
+ "description": "For your public page when it shows a draft through a preview link made with \"Allow comments\": the comments on the draft and a box for someone without an account to add one. Needs no provider.",
7
+ "dependencies": [
8
+ "@mainsoft/agent-cms"
9
+ ],
10
+ "registryDependencies": [
11
+ "button",
12
+ "input",
13
+ "label",
14
+ "textarea",
15
+ "cms-lib"
16
+ ],
17
+ "files": [
18
+ {
19
+ "path": "registry/cms/cms-preview-comments.tsx",
20
+ "type": "registry:component",
21
+ "content": "// agent-cms registry: cms-preview-comments (0.10.0). Copied into your app by `npx agent-cms add`; edit freely.\n//\n// For your public page when it shows a draft through a preview link that\n// was made with \"Allow comments\": the comments on that draft, and a box for\n// someone without an account to add one. It needs no <CmsProvider>.\n//\n// {token && preview.comments ? <CmsPreviewComments token={token} /> : null}\n\"use client\";\n\nimport * as React from \"react\";\nimport { createRestClient, type CommentThread } from \"@mainsoft/agent-cms/client\";\nimport { Button } from \"@/components/ui/button\";\nimport { Input } from \"@/components/ui/input\";\nimport { Label } from \"@/components/ui/label\";\nimport { Textarea } from \"@/components/ui/textarea\";\nimport { cn } from \"@/lib/utils\";\nimport { createT, errorMessage, type CmsMessages } from \"./cms-messages\";\n\nexport interface CmsPreviewCommentsProps {\n /** The preview token (`?cms_preview=...`). */\n token: string;\n /** Where the CMS routes are mounted. Default \"/api/cms\". */\n baseUrl?: string;\n /** UI text; pass `ko` for Korean. */\n messages?: Partial<CmsMessages>;\n className?: string;\n}\n\nconst NAME_KEY = \"cms-preview-name\";\n\nexport function CmsPreviewComments({ token, baseUrl = \"/api/cms\", messages, className }: CmsPreviewCommentsProps) {\n const client = React.useMemo(() => createRestClient({ url: baseUrl }), [baseUrl]);\n const t = React.useMemo(() => createT(messages), [messages]);\n const [threads, setThreads] = React.useState<CommentThread[] | null>(null);\n const [name, setName] = React.useState(\"\");\n const [body, setBody] = React.useState(\"\");\n const [busy, setBusy] = React.useState(false);\n const [error, setError] = React.useState<string | null>(null);\n const id = React.useId();\n\n const load = React.useCallback(() => {\n client.previewComments(token).then(setThreads, (e) => setError(errorMessage(e, t)));\n }, [client, token, t]);\n React.useEffect(load, [load]);\n React.useEffect(() => {\n try {\n setName(window.localStorage.getItem(NAME_KEY) ?? \"\");\n } catch {\n /* private mode */\n }\n }, []);\n\n const open = (threads ?? []).filter((x) => !x.resolvedAt);\n const who = (c: { authorAgent: string | null; authorLabel: string | null }) => c.authorAgent ?? c.authorLabel ?? \"\";\n\n return (\n <section aria-labelledby={`${id}-h`} className={cn(\"flex flex-col gap-4 rounded-lg border p-4 text-sm\", className)}>\n <h2 id={`${id}-h`} className=\"text-base font-semibold\">\n {open.length ? t(\"comments_n\", { n: open.length }) : t(\"comments\")}\n </h2>\n {open.length ? (\n <ul className=\"flex flex-col gap-3\">\n {open.map((th) => (\n <li key={th.id} className=\"flex flex-col gap-1.5 border-b pb-3 last:border-b-0 last:pb-0\">\n <span className=\"font-medium\">{who(th)}</span>\n {th.quote ? <span className=\"truncate border-l-2 pl-2 font-mono text-[12.5px] text-muted-foreground\">{th.quote}</span> : null}\n <p className=\"whitespace-pre-wrap break-words\">{th.body}</p>\n {th.replies.length ? (\n <ul className=\"ml-3 flex flex-col gap-1.5 border-l pl-3\">\n {th.replies.map((r) => (\n <li key={r.id}>\n <span className=\"font-medium\">{who(r)}</span>\n <p className=\"whitespace-pre-wrap break-words\">{r.body}</p>\n </li>\n ))}\n </ul>\n ) : null}\n </li>\n ))}\n </ul>\n ) : null}\n <form\n className=\"flex flex-col gap-2.5\"\n onSubmit={(e) => {\n e.preventDefault();\n const text = body.trim();\n if (!text) return;\n setBusy(true);\n setError(null);\n client.addPreviewComment(token, { name: name.trim() || null, body: text }).then(\n () => {\n try {\n window.localStorage.setItem(NAME_KEY, name.trim());\n } catch {\n /* private mode */\n }\n setBody(\"\");\n setBusy(false);\n load();\n },\n (err) => (setBusy(false), setError(errorMessage(err, t)))\n );\n }}\n >\n <div className=\"grid gap-1.5\">\n <Label htmlFor={`${id}-name`}>{t(\"name\")}</Label>\n <Input id={`${id}-name`} maxLength={60} autoComplete=\"name\" value={name} onChange={(e) => setName(e.target.value)} />\n </div>\n <div className=\"grid gap-1.5\">\n <Label htmlFor={`${id}-body`}>{t(\"comment_write\")}</Label>\n <Textarea id={`${id}-body`} rows={3} maxLength={4000} value={body} onChange={(e) => setBody(e.target.value)} />\n </div>\n {error ? (\n <p role=\"alert\" className=\"text-destructive\">\n {error}\n </p>\n ) : null}\n <Button type=\"submit\" className=\"self-end\" disabled={busy || !body.trim()}>\n {t(\"comment_add\")}\n </Button>\n </form>\n </section>\n );\n}\n"
22
+ }
23
+ ]
24
+ }
@@ -0,0 +1,28 @@
1
+ {
2
+ "$schema": "https://ui.shadcn.com/schema/registry-item.json",
3
+ "name": "cms-releases",
4
+ "type": "registry:component",
5
+ "title": "Releases",
6
+ "description": "Documents that are published (or unpublished) together: the list of releases and one release with its documents, the version of each, what blocks it, publish now or at a set time.",
7
+ "dependencies": [
8
+ "@mainsoft/agent-cms",
9
+ "lucide-react"
10
+ ],
11
+ "registryDependencies": [
12
+ "button",
13
+ "checkbox",
14
+ "dialog",
15
+ "dropdown-menu",
16
+ "input",
17
+ "label",
18
+ "table",
19
+ "cms-lib"
20
+ ],
21
+ "files": [
22
+ {
23
+ "path": "registry/cms/cms-releases.tsx",
24
+ "type": "registry:component",
25
+ "content": "// agent-cms registry: cms-releases (0.10.0). Copied into your app by `npx agent-cms add`; edit freely.\n//\n// Releases: documents that go out (or come down) together. <CmsReleases> is\n// the list, <CmsRelease> is one release: what is in it, which version of\n// each document, what stands in the way, publish now or at a set time.\n\"use client\";\n\nimport * as React from \"react\";\nimport { CalendarClock, CircleAlert, MoreHorizontal, Plus, RefreshCw, Search, X } from \"lucide-react\";\nimport { isCmsRemoteError, type BlockedItem, type ReleaseView } from \"@mainsoft/agent-cms/client\";\nimport type { CmsRelease as Release, DocSummary } from \"@mainsoft/agent-cms/types\";\nimport { Button, buttonVariants } from \"@/components/ui/button\";\nimport { Checkbox } from \"@/components/ui/checkbox\";\nimport { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from \"@/components/ui/dialog\";\nimport { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from \"@/components/ui/dropdown-menu\";\nimport { Input } from \"@/components/ui/input\";\nimport { Label } from \"@/components/ui/label\";\nimport { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from \"@/components/ui/table\";\nimport { cn } from \"@/lib/utils\";\nimport { errorMessage } from \"./cms-messages\";\nimport { ConfirmDialog, PageHeader, Segmented, StateBadge, StatusText, type BadgeState } from \"./cms-parts\";\nimport { formatZoned, toInput, useCms, useDebounced, zonedParts, zonedToIso } from \"./use-cms\";\n\nconst SELECT = \"h-9 rounded-md border border-input bg-background px-2.5 text-sm outline-none focus-visible:ring-2 focus-visible:ring-ring\";\nconst BADGE: Record<Release[\"state\"], BadgeState> = { open: \"draft\", scheduled: \"scheduled\", published: \"published\" };\n\nfunction ReleaseBadge({ state }: { state: Release[\"state\"] }) {\n const { t } = useCms();\n return <StateBadge state={BADGE[state]} label={state === \"open\" ? t(\"release_state_open\") : undefined} />;\n}\n\nfunction NameDialog({ title, initial = \"\", action, onClose, onSubmit }: { title: string; initial?: string; action: string; onClose: () => void; onSubmit: (name: string) => Promise<unknown> }) {\n const { t } = useCms();\n const [name, setName] = React.useState(initial);\n const [error, setError] = React.useState<string | null>(null);\n const [busy, setBusy] = React.useState(false);\n return (\n <Dialog open onOpenChange={(o) => !o && onClose()}>\n <DialogContent className=\"max-w-[400px]\">\n <form\n className=\"grid gap-4\"\n onSubmit={(e) => {\n e.preventDefault();\n setBusy(true);\n onSubmit(name.trim()).then(onClose, (err) => (setBusy(false), setError(errorMessage(err, t))));\n }}\n >\n <DialogHeader>\n <DialogTitle>{title}</DialogTitle>\n <DialogDescription className=\"sr-only\">{t(\"nav_releases\")}</DialogDescription>\n </DialogHeader>\n <div className=\"grid gap-1.5\">\n <Label htmlFor=\"cms-release-name\">{t(\"name\")}</Label>\n <Input id=\"cms-release-name\" autoFocus maxLength={120} value={name} onChange={(e) => setName(e.target.value)} aria-invalid={error ? true : undefined} />\n {error ? <StatusText tone=\"error\">{error}</StatusText> : null}\n </div>\n <DialogFooter>\n <Button type=\"button\" variant=\"outline\" onClick={onClose}>\n {t(\"cancel\")}\n </Button>\n <Button type=\"submit\" disabled={busy || !name.trim() || name.trim() === initial}>\n {action}\n </Button>\n </DialogFooter>\n </form>\n </DialogContent>\n </Dialog>\n );\n}\n\n// ── list ─────────────────────────────────────────────────────────────────────\n\nexport interface CmsReleasesProps {\n /** Open one release (row click, and right after making one). */\n onOpenRelease?: (id: string) => void;\n /** Make names real links. */\n hrefFor?: (id: string) => string;\n className?: string;\n}\n\nexport function CmsReleases({ onOpenRelease, hrefFor, className }: CmsReleasesProps) {\n const { client, t, locale, me } = useCms();\n const [list, setList] = React.useState<Release[] | null>(null);\n const [error, setError] = React.useState<unknown>(null);\n const [tick, setTick] = React.useState(0);\n const [dialog, setDialog] = React.useState<null | { kind: \"new\" } | { kind: \"rename\" | \"delete\"; release: Release }>(null);\n const [busy, setBusy] = React.useState(false);\n const reload = () => setTick((n) => n + 1);\n\n React.useEffect(() => {\n let live = true;\n client.releases().then(\n (r) => live && (setList(r), setError(null)),\n (e) => live && setError(e)\n );\n return () => {\n live = false;\n };\n }, [client, tick]);\n\n const canWrite = !!me?.collections.some((c) => c.canWrite);\n const name = (r: Release) =>\n hrefFor ? (\n <a\n href={hrefFor(r.id)}\n className=\"font-medium hover:underline\"\n onClick={(e) => {\n if (onOpenRelease && !e.metaKey && !e.ctrlKey && !e.shiftKey && e.button === 0) {\n e.preventDefault();\n onOpenRelease(r.id);\n }\n }}\n >\n {r.name}\n </a>\n ) : (\n <button type=\"button\" className=\"text-left font-medium hover:underline\" onClick={() => onOpenRelease?.(r.id)}>\n {r.name}\n </button>\n );\n\n return (\n <div className={cn(\"flex min-h-0 flex-1 flex-col\", className)}>\n <PageHeader title={t(\"nav_releases\")}>\n {canWrite ? (\n <Button type=\"button\" className=\"gap-1.5\" onClick={() => setDialog({ kind: \"new\" })}>\n <Plus aria-hidden className=\"h-4 w-4\" />\n {t(\"release_new\")}\n </Button>\n ) : null}\n </PageHeader>\n <div className=\"flex-1 px-4 py-4 md:px-6\">\n {error ? <StatusText tone=\"error\">{errorMessage(error, t)}</StatusText> : null}\n {list && !list.length ? <p className=\"py-16 text-center text-sm text-muted-foreground\">{t(\"release_empty\")}</p> : null}\n {list?.length ? (\n <Table>\n <TableHeader>\n <TableRow>\n <TableHead>{t(\"name\")}</TableHead>\n <TableHead className=\"w-[80px] text-right\">{t(\"release_col_docs\")}</TableHead>\n <TableHead className=\"w-[140px] pl-6\">{t(\"col_state\")}</TableHead>\n <TableHead className=\"hidden w-[200px] md:table-cell\">{t(\"sched_publish_at\")}</TableHead>\n <TableHead className=\"hidden w-[140px] md:table-cell\">{t(\"release_col_by\")}</TableHead>\n <TableHead className=\"w-10\">\n <span className=\"sr-only\">{t(\"col_actions\")}</span>\n </TableHead>\n </TableRow>\n </TableHeader>\n <TableBody>\n {list.map((r) => {\n const at = r.publishedAt ?? r.publishAt;\n return (\n <TableRow key={r.id}>\n <TableCell>{name(r)}</TableCell>\n <TableCell className=\"text-right tabular-nums\">{r.items.length}</TableCell>\n <TableCell className=\"pl-6\">\n <ReleaseBadge state={r.state} />\n </TableCell>\n <TableCell className={cn(\"hidden tabular-nums md:table-cell\", !at && \"text-muted-foreground\")}>{at ? formatZoned(at, locale, me?.timeZone) : t(\"none\")}</TableCell>\n <TableCell className=\"hidden max-w-0 truncate md:table-cell\">{r.createdBy ?? \"\"}</TableCell>\n <TableCell>\n <DropdownMenu>\n <DropdownMenuTrigger className={buttonVariants({ variant: \"ghost\", size: \"icon\", className: \"h-7 w-7\" })} aria-label={t(\"row_actions\", { title: r.name })}>\n <MoreHorizontal aria-hidden className=\"h-4 w-4\" />\n </DropdownMenuTrigger>\n <DropdownMenuContent align=\"end\">\n <DropdownMenuItem onClick={() => onOpenRelease?.(r.id)}>{t(\"open\")}</DropdownMenuItem>\n {r.state !== \"published\" && canWrite ? (\n <>\n <DropdownMenuItem onClick={() => setDialog({ kind: \"rename\", release: r })}>{t(\"media_rename\")}</DropdownMenuItem>\n <DropdownMenuItem className=\"text-destructive\" onClick={() => setDialog({ kind: \"delete\", release: r })}>\n {t(\"release_delete\")}\n </DropdownMenuItem>\n </>\n ) : null}\n </DropdownMenuContent>\n </DropdownMenu>\n </TableCell>\n </TableRow>\n );\n })}\n </TableBody>\n </Table>\n ) : null}\n </div>\n {dialog?.kind === \"new\" ? (\n <NameDialog\n title={t(\"release_new\")}\n action={t(\"release_new\")}\n onClose={() => setDialog(null)}\n onSubmit={async (n) => {\n const r = await client.createRelease(n);\n reload();\n onOpenRelease?.(r.id);\n }}\n />\n ) : null}\n {dialog?.kind === \"rename\" ? <NameDialog title={t(\"media_rename\")} initial={dialog.release.name} action={t(\"save\")} onClose={() => setDialog(null)} onSubmit={(n) => client.renameRelease(dialog.release.id, n).then(reload)} /> : null}\n <ConfirmDialog\n open={dialog?.kind === \"delete\"}\n onOpenChange={(o) => !o && setDialog(null)}\n title={dialog?.kind === \"delete\" ? t(\"release_delete_title\", { name: dialog.release.name }) : \"\"}\n description={t(\"release_delete_note\")}\n confirmLabel={t(\"release_delete\")}\n destructive\n busy={busy}\n onConfirm={async () => {\n if (dialog?.kind !== \"delete\") return;\n setBusy(true);\n await client.removeRelease(dialog.release.id).then(reload, setError);\n setBusy(false);\n setDialog(null);\n }}\n />\n </div>\n );\n}\n\n// ── one release ──────────────────────────────────────────────────────────────\n\nexport interface CmsReleaseProps {\n id: string;\n /** Back to the list (the breadcrumb, and after deleting). */\n onBack?: () => void;\n /** Open a document of the release. */\n onOpenDocument?: (collection: string, slug: string) => void;\n className?: string;\n}\n\ntype Item = ReleaseView[\"items\"][number];\n\nexport function CmsRelease({ id, onBack, onOpenDocument, className }: CmsReleaseProps) {\n const { client, t, locale, me } = useCms();\n const [rel, setRel] = React.useState<ReleaseView | null>(null);\n const [error, setError] = React.useState<unknown>(null);\n const [problems, setProblems] = React.useState<Record<string, number>>({});\n const [blocked, setBlocked] = React.useState<BlockedItem[]>([]);\n const [dialog, setDialog] = React.useState<null | \"add\" | \"schedule\" | \"publish\" | \"rename\" | \"delete\">(null);\n const [busy, setBusy] = React.useState(false);\n const [status, setStatus] = React.useState<{ text: string; tone: \"ok\" | \"error\" } | null>(null);\n const [tick, setTick] = React.useState(0);\n const reload = () => setTick((n) => n + 1);\n const zone = me?.timeZone;\n\n React.useEffect(() => {\n let live = true;\n client.release(id).then(\n (r) => live && (setRel(r), setError(null)),\n (e) => live && setError(e)\n );\n return () => {\n live = false;\n };\n }, [client, id, tick]);\n\n // What the checks say about each document that is to be published.\n const open = !!rel && rel.state !== \"published\";\n const itemsKey = rel?.items.map((i) => `${i.documentId}:${i.currentVersion}:${i.action}`).join(\",\") ?? \"\";\n React.useEffect(() => {\n if (!rel || !open) return;\n let live = true;\n void Promise.all(\n rel.items\n .filter((i) => i.action === \"publish\" && i.currentVersion !== null)\n .map(async (i) => {\n try {\n const d = await client.get(i.collection, i.slug, { draft: true });\n const found = await client.diagnose(i.collection, toInput(d, d.fields), d.slug);\n return [i.documentId, found.filter((x) => x.severity === \"error\").length] as const;\n } catch {\n return [i.documentId, 0] as const;\n }\n })\n ).then((rows) => live && setProblems(Object.fromEntries(rows)));\n return () => {\n live = false;\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [client, itemsKey, open]);\n\n const act = async (fn: () => Promise<unknown>, done?: string) => {\n setBusy(true);\n setStatus(null);\n try {\n await fn();\n if (done) setStatus({ text: done, tone: \"ok\" });\n reload();\n } catch (e) {\n setStatus({ text: errorMessage(e, t), tone: \"error\" });\n } finally {\n setBusy(false);\n }\n };\n\n if (error && !rel)\n return (\n <div className={cn(\"p-6\", className)}>\n <StatusText tone=\"error\">{errorMessage(error, t)}</StatusText>\n </div>\n );\n if (!rel)\n return (\n <div className={cn(\"p-6\", className)}>\n <StatusText>{t(\"loading\")}</StatusText>\n </div>\n );\n\n const at = rel.publishedAt ?? rel.publishAt;\n const change = (i: Item) => {\n if (i.currentVersion === null) return <span className=\"text-muted-foreground\">{t(\"release_gone\")}</span>;\n if (i.action === \"unpublish\") return t(\"release_unpublish\");\n if (i.stale)\n return (\n <span className=\"inline-flex items-center gap-1.5 tabular-nums\">\n v{i.version} → v{i.currentVersion}\n {open ? (\n <Button\n type=\"button\"\n variant=\"ghost\"\n size=\"icon\"\n className=\"h-6 w-6\"\n aria-label={`${i.title}: ${t(\"release_refresh_item\", { version: i.currentVersion })}`}\n title={t(\"release_refresh_item\", { version: i.currentVersion })}\n disabled={busy}\n onClick={() => void act(() => client.addToRelease(rel.id, [{ collection: i.collection, slug: i.slug, action: \"publish\" }]))}\n >\n <RefreshCw aria-hidden className=\"h-3.5 w-3.5\" />\n </Button>\n ) : null}\n </span>\n );\n return (\n <>\n {t(i.state === \"published\" ? \"publish\" : \"release_publish_new\")} <span className=\"tabular-nums text-muted-foreground\">v{i.version}</span>\n </>\n );\n };\n const problem = (i: Item) => {\n const stop = blocked.find((b) => b.collection === i.collection && b.slug === i.slug);\n const n = problems[i.documentId] ?? 0;\n if (!open) return null;\n if (stop || n || !i.canPublish || i.currentVersion === null)\n return (\n <span className=\"inline-flex items-center gap-1.5 text-amber-700\" title={stop?.message}>\n <CircleAlert aria-hidden className=\"h-3.5 w-3.5 shrink-0\" />\n <span className=\"truncate\">{stop ? stop.message : n ? t(\"problems_n\", { n }) : i.currentVersion === null ? t(\"release_gone\") : t(\"review_needed\")}</span>\n </span>\n );\n return <span className=\"text-muted-foreground\">{t(\"problems_none\")}</span>;\n };\n const collectionLabel = (slug: string) => me?.collections.find((c) => c.slug === slug)?.label ?? slug;\n\n return (\n <div className={cn(\"flex min-h-0 flex-1 flex-col\", className)}>\n <PageHeader\n title={rel.name}\n crumbs={[\n onBack ? (\n <button key=\"b\" type=\"button\" className=\"rounded outline-none hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring\" onClick={onBack}>\n {t(\"nav_releases\")}\n </button>\n ) : (\n t(\"nav_releases\")\n ),\n ]}\n after={\n <>\n <ReleaseBadge state={rel.state} />\n {at ? <span className=\"text-xs tabular-nums text-muted-foreground\">{formatZoned(at, locale, zone)}</span> : null}\n </>\n }\n >\n {open ? (\n <>\n <Button type=\"button\" variant=\"outline\" className=\"gap-1.5\" onClick={() => setDialog(\"add\")}>\n <Plus aria-hidden className=\"h-4 w-4\" />\n {t(\"release_add\")}\n </Button>\n {rel.canPublish ? (\n <>\n <Button type=\"button\" variant=\"outline\" className=\"gap-1.5\" disabled={busy || !rel.items.length} onClick={() => setDialog(\"schedule\")}>\n <CalendarClock aria-hidden className=\"h-4 w-4\" />\n {t(\"sched_go\")}\n </Button>\n <Button type=\"button\" disabled={busy || !rel.items.length} onClick={() => setDialog(\"publish\")}>\n {t(\"publish\")}\n </Button>\n </>\n ) : null}\n <DropdownMenu>\n <DropdownMenuTrigger className={buttonVariants({ variant: \"ghost\", size: \"icon\" })} aria-label={t(\"more\")}>\n <MoreHorizontal aria-hidden className=\"h-4 w-4\" />\n </DropdownMenuTrigger>\n <DropdownMenuContent align=\"end\">\n <DropdownMenuItem onClick={() => setDialog(\"rename\")}>{t(\"media_rename\")}</DropdownMenuItem>\n <DropdownMenuItem className=\"text-destructive\" onClick={() => setDialog(\"delete\")}>\n {t(\"release_delete\")}\n </DropdownMenuItem>\n </DropdownMenuContent>\n </DropdownMenu>\n </>\n ) : null}\n </PageHeader>\n <div className=\"flex-1 px-4 py-4 md:px-6\">\n {blocked.length ? (\n <div role=\"alert\" className=\"mb-3 rounded-lg border border-amber-200 bg-amber-50 px-3 py-2 text-sm text-amber-950\">\n <p className=\"font-medium\">{t(\"release_blocked\")}</p>\n <ul className=\"mt-1 list-disc pl-5\">\n {blocked.map((b) => (\n <li key={`${b.collection}/${b.slug}`}>\n {b.title}: {b.message}\n </li>\n ))}\n </ul>\n </div>\n ) : null}\n {rel.lastError && open && !blocked.length ? <StatusText tone=\"error\" className=\"mb-3\">{rel.lastError}</StatusText> : null}\n {!rel.items.length ? <p className=\"py-16 text-center text-sm text-muted-foreground\">{t(\"release_items_empty\")}</p> : null}\n {rel.items.length ? (\n <Table>\n <TableHeader>\n <TableRow>\n <TableHead>{t(\"col_title\")}</TableHead>\n <TableHead className=\"hidden w-[120px] sm:table-cell\">{t(\"release_col_collection\")}</TableHead>\n <TableHead className=\"w-[200px]\">{t(\"release_col_change\")}</TableHead>\n <TableHead className=\"hidden w-[200px] md:table-cell\">{t(\"release_col_problem\")}</TableHead>\n <TableHead className=\"w-10\">\n <span className=\"sr-only\">{t(\"col_actions\")}</span>\n </TableHead>\n </TableRow>\n </TableHeader>\n <TableBody>\n {rel.items.map((i) => (\n <TableRow key={i.documentId}>\n <TableCell className=\"max-w-0\">\n <button type=\"button\" className=\"block max-w-full truncate text-left font-medium enabled:hover:underline\" disabled={!onOpenDocument || i.currentVersion === null} onClick={() => onOpenDocument?.(i.collection, i.slug)}>\n {i.title || i.slug}\n </button>\n <div className=\"truncate text-xs text-muted-foreground md:hidden\">{problem(i)}</div>\n </TableCell>\n <TableCell className=\"hidden sm:table-cell\">{collectionLabel(i.collection)}</TableCell>\n <TableCell>{change(i)}</TableCell>\n <TableCell className=\"hidden max-w-0 md:table-cell\">{problem(i)}</TableCell>\n <TableCell>\n {open ? (\n <Button type=\"button\" variant=\"ghost\" size=\"icon\" className=\"h-7 w-7 text-muted-foreground\" aria-label={t(\"release_remove_item\", { title: i.title || i.slug })} disabled={busy} onClick={() => void act(() => client.removeFromRelease(rel.id, i.documentId))}>\n <X aria-hidden className=\"h-4 w-4\" />\n </Button>\n ) : null}\n </TableCell>\n </TableRow>\n ))}\n </TableBody>\n </Table>\n ) : null}\n </div>\n <div className=\"flex items-center gap-3 px-4 py-3 text-xs text-muted-foreground md:px-6\">\n <span className=\"tabular-nums\">{t(\"release_count\", { n: rel.items.length })}</span>\n <span className=\"flex-1\" />\n <StatusText className=\"text-xs\" tone={status?.tone === \"error\" ? \"error\" : status ? \"ok\" : \"muted\"}>\n {status?.text ?? \"\"}\n </StatusText>\n </div>\n\n {dialog === \"add\" ? <AddDocumentsDialog release={rel} onClose={() => setDialog(null)} onAdded={() => (setBlocked([]), reload())} /> : null}\n {dialog === \"schedule\" ? <ScheduleDialog release={rel} zone={zone ?? \"UTC\"} onClose={() => setDialog(null)} onDone={reload} /> : null}\n {dialog === \"rename\" ? <NameDialog title={t(\"media_rename\")} initial={rel.name} action={t(\"save\")} onClose={() => setDialog(null)} onSubmit={(n) => client.renameRelease(rel.id, n).then(reload)} /> : null}\n <ConfirmDialog\n open={dialog === \"publish\" || dialog === \"delete\"}\n onOpenChange={(o) => !o && setDialog(null)}\n title={dialog === \"delete\" ? t(\"release_delete_title\", { name: rel.name }) : t(\"release_publish_title\", { name: rel.name })}\n description={dialog === \"delete\" ? t(\"release_delete_note\") : t(\"release_publish_note\", { n: rel.items.length })}\n confirmLabel={dialog === \"delete\" ? t(\"release_delete\") : t(\"publish\")}\n destructive={dialog === \"delete\"}\n busy={busy}\n onConfirm={async () => {\n const what = dialog;\n setDialog(null);\n if (what === \"delete\") {\n await act(() => client.removeRelease(rel.id));\n return onBack?.();\n }\n setBusy(true);\n setStatus(null);\n try {\n await client.publishRelease(rel.id);\n setBlocked([]);\n setStatus({ text: t(\"release_published_done\"), tone: \"ok\" });\n } catch (e) {\n const list = isCmsRemoteError(e) ? (e.current as { blocked?: BlockedItem[] } | undefined)?.blocked : undefined;\n setBlocked(list ?? []);\n setStatus({ text: errorMessage(e, t), tone: \"error\" });\n } finally {\n setBusy(false);\n reload();\n }\n }}\n />\n </div>\n );\n}\n\nfunction ScheduleDialog({ release, zone, onClose, onDone }: { release: ReleaseView; zone: string; onClose: () => void; onDone: () => void }) {\n const { client, t } = useCms();\n const [v, setV] = React.useState(() => (release.publishAt ? zonedParts(release.publishAt, zone) : { date: zonedParts(new Date(Date.now() + 86_400_000).toISOString(), zone).date, time: \"09:00\" }));\n const [error, setError] = React.useState<string | null>(null);\n const [busy, setBusy] = React.useState(false);\n const send = (publishAt: string | null) => {\n setBusy(true);\n client.scheduleRelease(release.id, publishAt).then(\n () => (onDone(), onClose()),\n (e) => (setBusy(false), setError(errorMessage(e, t)))\n );\n };\n return (\n <Dialog open onOpenChange={(o) => !o && onClose()}>\n <DialogContent className=\"max-w-[380px]\">\n <form\n className=\"grid gap-4\"\n onSubmit={(e) => {\n e.preventDefault();\n const iso = zonedToIso(v.date, v.time || \"09:00\", zone);\n if (!iso || Date.parse(iso) <= Date.now()) return setError(t(\"sched_past\"));\n send(iso);\n }}\n >\n <DialogHeader>\n <DialogTitle>{t(\"publish_later\")}</DialogTitle>\n <DialogDescription className=\"sr-only\">{release.name}</DialogDescription>\n </DialogHeader>\n <fieldset className=\"grid gap-1.5\">\n <legend className=\"mb-1.5 flex w-full items-center text-sm font-medium\">\n <span className=\"flex-1\">{t(\"sched_publish_at\")}</span>\n <span className=\"text-xs font-normal text-muted-foreground\">{zone}</span>\n </legend>\n <div className=\"flex gap-2\">\n <input type=\"date\" aria-label={`${t(\"sched_publish_at\")}: ${t(\"sched_date\")}`} className={cn(SELECT, \"min-w-0 flex-1 tabular-nums\")} value={v.date} onChange={(e) => setV({ ...v, date: e.target.value })} />\n <input type=\"time\" aria-label={`${t(\"sched_publish_at\")}: ${t(\"sched_time\")}`} className={cn(SELECT, \"w-[112px] tabular-nums\")} value={v.time} onChange={(e) => setV({ ...v, time: e.target.value })} />\n </div>\n {error ? <StatusText tone=\"error\">{error}</StatusText> : null}\n </fieldset>\n <DialogFooter>\n {release.publishAt ? (\n <Button type=\"button\" variant=\"ghost\" className=\"mr-auto text-destructive hover:text-destructive\" disabled={busy} onClick={() => send(null)}>\n {t(\"sched_cancel\")}\n </Button>\n ) : null}\n <Button type=\"button\" variant=\"outline\" onClick={onClose}>\n {t(\"cancel\")}\n </Button>\n <Button type=\"submit\" disabled={busy || !v.date}>\n {t(\"sched_go\")}\n </Button>\n </DialogFooter>\n </form>\n </DialogContent>\n </Dialog>\n );\n}\n\n/** Find documents by title and add them, to publish or to unpublish. */\nfunction AddDocumentsDialog({ release, onClose, onAdded }: { release: ReleaseView; onClose: () => void; onAdded: () => void }) {\n const { client, t, me } = useCms();\n const cols = (me?.collections ?? []).filter((c) => c.canWrite);\n const [col, setCol] = React.useState(cols[0]?.slug ?? \"\");\n const [text, setText] = React.useState(\"\");\n const [q, setQ] = React.useState(\"\");\n const applyQ = useDebounced(setQ, 250);\n const [docs, setDocs] = React.useState<DocSummary[] | null>(null);\n const [picked, setPicked] = React.useState<ReadonlySet<string>>(new Set());\n const [action, setAction] = React.useState<\"publish\" | \"unpublish\">(\"publish\");\n const [error, setError] = React.useState<string | null>(null);\n const [busy, setBusy] = React.useState(false);\n\n React.useEffect(() => {\n if (!col) return;\n let live = true;\n setDocs(null);\n client.list(col, { q: q || undefined, limit: 30 }).then(\n (r) => live && setDocs(r.docs),\n (e) => live && setError(errorMessage(e, t))\n );\n return () => {\n live = false;\n };\n }, [client, col, q, t]);\n\n const inside = new Set(release.items.map((i) => `${i.collection}/${i.slug}`));\n // Unpublishing only makes sense for what is public now.\n const rows = (docs ?? []).filter((d) => !inside.has(`${col}/${d.slug}`) && (action === \"publish\" || d.publishedVersion !== null));\n return (\n <Dialog open onOpenChange={(o) => !o && onClose()}>\n <DialogContent className=\"max-w-[520px]\">\n <form\n className=\"grid gap-3.5\"\n onSubmit={(e) => {\n e.preventDefault();\n setBusy(true);\n client.addToRelease(release.id, [...picked].map((slug) => ({ collection: col, slug, action }))).then(\n () => (onAdded(), onClose()),\n (err) => (setBusy(false), setError(errorMessage(err, t)))\n );\n }}\n >\n <DialogHeader>\n <DialogTitle>{t(\"release_add\")}</DialogTitle>\n <DialogDescription className=\"sr-only\">{release.name}</DialogDescription>\n </DialogHeader>\n <div className=\"flex flex-wrap items-center gap-2\">\n <select aria-label={t(\"release_col_collection\")} className={cn(SELECT, \"max-w-[160px]\")} value={col} onChange={(e) => (setCol(e.target.value), setPicked(new Set()))}>\n {cols.map((c) => (\n <option key={c.slug} value={c.slug}>\n {c.label}\n </option>\n ))}\n </select>\n <div className=\"relative min-w-0 flex-1\">\n <Search aria-hidden className=\"pointer-events-none absolute left-2.5 top-2.5 h-4 w-4 text-muted-foreground\" />\n <Input\n aria-label={t(\"release_pick\")}\n placeholder={t(\"release_pick\")}\n className=\"pl-8\"\n autoFocus\n value={text}\n onChange={(e) => {\n setText(e.target.value);\n applyQ(e.target.value.trim());\n }}\n />\n </div>\n </div>\n <Segmented\n label={t(\"release_action\")}\n value={action}\n onChange={(a) => (setAction(a), setPicked(new Set()))}\n options={[\n { value: \"publish\", label: t(\"publish\") },\n { value: \"unpublish\", label: t(\"release_unpublish\") },\n ]}\n />\n <ul aria-label={t(\"release_col_docs\")} className=\"max-h-64 min-h-24 overflow-y-auto rounded-md border\">\n {rows.map((d) => (\n <li key={d.slug} className=\"border-b last:border-b-0\">\n <label className=\"flex cursor-pointer items-center gap-2.5 px-3 py-2\">\n <Checkbox\n checked={picked.has(d.slug)}\n onCheckedChange={(v) =>\n setPicked((now) => {\n const next = new Set(now);\n if (v === true) next.add(d.slug);\n else next.delete(d.slug);\n return next;\n })\n }\n />\n <span className=\"min-w-0 flex-1 truncate text-sm font-medium\">{d.title || d.slug}</span>\n <StateBadge state={d.state} />\n <span className=\"text-xs tabular-nums text-muted-foreground\">v{d.version}</span>\n </label>\n </li>\n ))}\n {docs && !rows.length ? <li className=\"px-3 py-6 text-center text-sm text-muted-foreground\">{t(\"no_results\")}</li> : null}\n </ul>\n {error ? <StatusText tone=\"error\">{error}</StatusText> : null}\n <DialogFooter>\n <Button type=\"button\" variant=\"outline\" onClick={onClose}>\n {t(\"cancel\")}\n </Button>\n <Button type=\"submit\" disabled={busy || !picked.size}>\n {t(\"release_add\")}\n </Button>\n </DialogFooter>\n </form>\n </DialogContent>\n </Dialog>\n );\n}\n"
26
+ }
27
+ ]
28
+ }
@@ -3,7 +3,7 @@
3
3
  "name": "cms-shell",
4
4
  "type": "registry:component",
5
5
  "title": "Admin layout",
6
- "description": "Sidebar with collections, API keys and audit log, plus extraNav for your app's own screens. A sheet menu under 768px.",
6
+ "description": "Sidebar with collections, API keys and audit log, plus extraNav for your app's own screens. A sheet menu under 768px. Shows \"Media\" when the app has a media library.",
7
7
  "dependencies": [
8
8
  "@mainsoft/agent-cms",
9
9
  "lucide-react"
@@ -16,7 +16,7 @@
16
16
  {
17
17
  "path": "registry/cms/cms-shell.tsx",
18
18
  "type": "registry:component",
19
- "content": "// agent-cms registry: cms-shell (0.6.0). Copied into your app by `npx agent-cms add`; edit freely.\n//\n// The admin layout: a sidebar with the collections you may read, the\n// operations screens (API keys, audit log, admins only) and `extraNav`, the\n// place for your app's own screens. Under 768px the sidebar opens in a sheet.\n\"use client\";\n\nimport * as React from \"react\";\nimport { BookOpen, KeyRound, ScrollText, Search, FileText } from \"lucide-react\";\nimport { Sheet, SheetContent, SheetDescription, SheetTitle } from \"@/components/ui/sheet\";\nimport { cn } from \"@/lib/utils\";\nimport { ShellNavContext, useCms } from \"./use-cms\";\n\nexport interface CmsNavItem {\n label: string;\n href: string;\n badge?: React.ReactNode;\n icon?: React.ReactNode;\n}\n\nexport interface CmsNavGroup {\n label: string;\n items: CmsNavItem[];\n}\n\nexport interface CmsLinkProps {\n href: string;\n className?: string;\n children: React.ReactNode;\n \"aria-current\"?: \"page\" | undefined;\n onClick?: () => void;\n}\n\nexport type CmsShellTarget = { kind: \"collection\"; slug: string } | { kind: \"keys\" } | { kind: \"audit\" };\n\nexport interface CmsShellProps {\n children?: React.ReactNode;\n /** Brand text on top of the sidebar. Default \"Admin\". */\n title?: React.ReactNode;\n /** Brand mark (logo) before the title. */\n logo?: React.ReactNode;\n /** The collection shown now (highlighted). */\n activeCollection?: string;\n /** The current path; highlights the ops or `extraNav` link with this href. */\n activeHref?: string;\n /** Where the admin pages live, for the default links. Default \"/admin\". */\n basePath?: string;\n /** Override the link of a sidebar entry. Default `${basePath}/<collection>`, `${basePath}/keys`, `${basePath}/audit`. */\n hrefFor?: (target: CmsShellTarget) => string;\n /** Your app's own screens, shown under the operations section. */\n extraNav?: CmsNavGroup[];\n /** Show the search button (pair it with <CmsCommand>). */\n onSearch?: () => void;\n /** Render links with your router, e.g. `LinkComponent={Link}` from next/link. Default `<a>`. */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n LinkComponent?: React.ComponentType<CmsLinkProps> | React.ComponentType<any>;\n /** Full control over links (wins over LinkComponent). */\n renderLink?: (props: CmsLinkProps) => React.ReactNode;\n /** Item counts beside collections; default: the \"all\" count from `counts()` for collections you can edit. */\n counts?: Record<string, number>;\n className?: string;\n}\n\nexport function CmsShell({ children, title, logo, activeCollection, activeHref, basePath = \"/admin\", hrefFor, extraNav, onSearch, LinkComponent, renderLink, counts, className }: CmsShellProps) {\n const { t, me, client } = useCms();\n const [open, setOpen] = React.useState(false);\n const [loaded, setLoaded] = React.useState<Record<string, number>>({});\n\n React.useEffect(() => {\n if (counts || !me) return;\n let live = true;\n void Promise.all(\n me.collections\n .filter((c) => c.canWrite)\n .map((c) =>\n client.counts(c.slug).then(\n (n) => [c.slug, n.all] as const,\n () => null\n )\n )\n ).then((rows) => {\n if (live) setLoaded(Object.fromEntries(rows.filter((r): r is readonly [string, number] => !!r)));\n });\n return () => {\n live = false;\n };\n }, [client, me, counts]);\n const shown = counts ?? loaded;\n\n const href = (target: CmsShellTarget) =>\n hrefFor?.(target) ?? (target.kind === \"collection\" ? `${basePath}/${encodeURIComponent(target.slug)}` : `${basePath}/${target.kind}`);\n\n const link = (p: CmsLinkProps) => {\n if (renderLink) return renderLink(p);\n const L = LinkComponent;\n if (L) return <L {...p} />;\n return (\n <a href={p.href} className={p.className} aria-current={p[\"aria-current\"]} onClick={p.onClick}>\n {p.children}\n </a>\n );\n };\n\n const navClass = (active: boolean) =>\n cn(\n \"flex h-8 items-center gap-2 rounded-md px-2 text-sm text-foreground/80 outline-none hover:bg-accent hover:text-accent-foreground focus-visible:ring-2 focus-visible:ring-ring\",\n active && \"bg-accent font-medium text-accent-foreground\"\n );\n\n const close = () => setOpen(false);\n\n const nav = (\n <nav aria-label={t(\"nav_label\")} className=\"flex flex-col gap-0.5 text-sm\">\n {onSearch ? (\n <button\n type=\"button\"\n onClick={() => {\n close();\n onSearch();\n }}\n className=\"mb-3 flex h-8 items-center gap-2 rounded-md border bg-background px-2 text-sm text-muted-foreground outline-none hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring\"\n >\n <Search aria-hidden className=\"h-4 w-4\" />\n <span className=\"flex-1 text-left\">{t(\"search\")}</span>\n <kbd className=\"rounded border border-b-2 px-1 font-mono text-[11px]\">⌘K</kbd>\n </button>\n ) : null}\n <h2 className=\"px-2 pb-1 pt-2 text-xs font-medium text-muted-foreground\">{t(\"nav_collections\")}</h2>\n <ul className=\"flex flex-col gap-0.5\">\n {(me?.collections ?? []).map((c) => {\n const active = c.slug === activeCollection;\n return (\n <li key={c.slug}>\n {link({\n href: href({ kind: \"collection\", slug: c.slug }),\n className: navClass(active),\n \"aria-current\": active ? \"page\" : undefined,\n onClick: close,\n children: (\n <>\n <BookOpen aria-hidden className=\"h-4 w-4 shrink-0\" />\n <span className=\"flex-1 truncate\">{c.label}</span>\n {shown[c.slug] !== undefined ? <span className=\"text-xs tabular-nums text-muted-foreground\">{shown[c.slug]}</span> : null}\n </>\n ),\n })}\n </li>\n );\n })}\n </ul>\n {me?.isAdmin ? (\n <>\n <h2 className=\"px-2 pb-1 pt-4 text-xs font-medium text-muted-foreground\">{t(\"nav_ops\")}</h2>\n <ul className=\"flex flex-col gap-0.5\">\n {(\n [\n { kind: \"keys\", label: t(\"nav_keys\"), Icon: KeyRound },\n { kind: \"audit\", label: t(\"nav_audit\"), Icon: ScrollText },\n ] as const\n ).map(({ kind, label, Icon }) => {\n const h = href({ kind });\n const active = activeHref === h;\n return (\n <li key={kind}>\n {link({\n href: h,\n className: navClass(active),\n \"aria-current\": active ? \"page\" : undefined,\n onClick: close,\n children: (\n <>\n <Icon aria-hidden className=\"h-4 w-4 shrink-0\" />\n <span className=\"flex-1 truncate\">{label}</span>\n </>\n ),\n })}\n </li>\n );\n })}\n </ul>\n </>\n ) : null}\n {(extraNav ?? []).map((g, gi) => (\n <div key={gi} data-cms-extra-nav=\"\">\n <h2 className=\"px-2 pb-1 pt-4 text-xs font-medium text-muted-foreground\">{g.label}</h2>\n <ul className=\"flex flex-col gap-0.5\">\n {g.items.map((it) => {\n const active = activeHref === it.href;\n return (\n <li key={it.href}>\n {link({\n href: it.href,\n className: navClass(active),\n \"aria-current\": active ? \"page\" : undefined,\n onClick: close,\n children: (\n <>\n {it.icon ?? <FileText aria-hidden className=\"h-4 w-4 shrink-0\" />}\n <span className=\"flex-1 truncate\">{it.label}</span>\n {it.badge !== undefined && it.badge !== null ? <span className=\"text-xs tabular-nums text-muted-foreground\">{it.badge}</span> : null}\n </>\n ),\n })}\n </li>\n );\n })}\n </ul>\n </div>\n ))}\n </nav>\n );\n\n const brand = (\n <div className=\"mb-4 flex items-center gap-2 px-2 font-semibold\">\n {logo}\n <span className=\"truncate\">{title ?? t(\"shell_title\")}</span>\n </div>\n );\n\n const navCtx = React.useMemo(() => ({ openNav: () => setOpen(true) }), []);\n\n return (\n <ShellNavContext.Provider value={navCtx}>\n <div className={cn(\"flex min-h-screen bg-background text-foreground\", className)}>\n <aside className=\"sticky top-0 hidden h-screen w-60 shrink-0 overflow-y-auto border-r bg-muted/30 p-3 md:block\">\n {brand}\n {nav}\n </aside>\n <Sheet open={open} onOpenChange={setOpen}>\n <SheetContent side=\"left\" className=\"w-72 overflow-y-auto p-3\">\n <SheetTitle className=\"sr-only\">{t(\"menu\")}</SheetTitle>\n <SheetDescription className=\"sr-only\">{t(\"nav_label\")}</SheetDescription>\n {brand}\n {nav}\n </SheetContent>\n </Sheet>\n <main className=\"flex min-w-0 flex-1 flex-col\">{children}</main>\n </div>\n </ShellNavContext.Provider>\n );\n}\n"
19
+ "content": "// agent-cms registry: cms-shell (0.10.0). Copied into your app by `npx agent-cms add`; edit freely.\n//\n// The admin layout: a sidebar with the collections you may read, the\n// operations screens (API keys, audit log, admins only) and `extraNav`, the\n// place for your app's own screens. Under 768px the sidebar opens in a sheet.\n\"use client\";\n\nimport * as React from \"react\";\nimport { BookOpen, HardDrive, Image as ImageIcon, KeyRound, Layers, ScrollText, Search, FileText, Trash2 } from \"lucide-react\";\nimport { Sheet, SheetContent, SheetDescription, SheetTitle } from \"@/components/ui/sheet\";\nimport { cn } from \"@/lib/utils\";\nimport { ShellNavContext, useCms } from \"./use-cms\";\n\nexport interface CmsNavItem {\n label: string;\n href: string;\n badge?: React.ReactNode;\n icon?: React.ReactNode;\n}\n\nexport interface CmsNavGroup {\n label: string;\n items: CmsNavItem[];\n}\n\nexport interface CmsLinkProps {\n href: string;\n className?: string;\n children: React.ReactNode;\n \"aria-current\"?: \"page\" | undefined;\n onClick?: () => void;\n}\n\nexport type CmsShellTarget = { kind: \"collection\"; slug: string } | { kind: \"media\" } | { kind: \"files\" } | { kind: \"releases\" } | { kind: \"trash\" } | { kind: \"keys\" } | { kind: \"audit\" };\n\nexport interface CmsShellProps {\n children?: React.ReactNode;\n /** Brand text on top of the sidebar. Default \"Admin\". */\n title?: React.ReactNode;\n /** Brand mark (logo) before the title. */\n logo?: React.ReactNode;\n /** The collection shown now (highlighted). */\n activeCollection?: string;\n /** The current path; highlights the ops or `extraNav` link with this href. */\n activeHref?: string;\n /** Where the admin pages live, for the default links. Default \"/admin\". */\n basePath?: string;\n /** Override the link of a sidebar entry. Default `${basePath}/<collection>`, `${basePath}/keys`, `${basePath}/audit`. */\n hrefFor?: (target: CmsShellTarget) => string;\n /** Your app's own screens, shown under the operations section. */\n extraNav?: CmsNavGroup[];\n /** Show the search button (pair it with <CmsCommand>). */\n onSearch?: () => void;\n /** Render links with your router, e.g. `LinkComponent={Link}` from next/link. Default `<a>`. */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n LinkComponent?: React.ComponentType<CmsLinkProps> | React.ComponentType<any>;\n /** Full control over links (wins over LinkComponent). */\n renderLink?: (props: CmsLinkProps) => React.ReactNode;\n /** Item counts beside collections; default: the \"all\" count from `counts()` for collections you can edit. */\n counts?: Record<string, number>;\n className?: string;\n}\n\nexport function CmsShell({ children, title, logo, activeCollection, activeHref, basePath = \"/admin\", hrefFor, extraNav, onSearch, LinkComponent, renderLink, counts, className }: CmsShellProps) {\n const { t, me, client } = useCms();\n const [open, setOpen] = React.useState(false);\n const [loaded, setLoaded] = React.useState<Record<string, number>>({});\n\n React.useEffect(() => {\n if (counts || !me) return;\n let live = true;\n void Promise.all(\n me.collections\n .filter((c) => c.canWrite)\n .map((c) =>\n client.counts(c.slug).then(\n (n) => [c.slug, n.all] as const,\n () => null\n )\n )\n ).then((rows) => {\n if (live) setLoaded(Object.fromEntries(rows.filter((r): r is readonly [string, number] => !!r)));\n });\n return () => {\n live = false;\n };\n }, [client, me, counts]);\n const shown = counts ?? loaded;\n\n // Releases and the trash are for people who can change something.\n const editor = !!me?.collections.some((c) => c.canWrite);\n const hasTrash = editor && (me?.trashDays ?? 0) > 0;\n const [inTrash, setInTrash] = React.useState<number | null>(null);\n React.useEffect(() => {\n if (!hasTrash) return;\n let live = true;\n client.trash().then(\n (r) => live && setInTrash(r.items.length),\n () => undefined\n );\n return () => {\n live = false;\n };\n }, [client, hasTrash, activeHref]);\n\n const href = (target: CmsShellTarget) =>\n hrefFor?.(target) ?? (target.kind === \"collection\" ? `${basePath}/${encodeURIComponent(target.slug)}` : `${basePath}/${target.kind}`);\n\n const link = (p: CmsLinkProps) => {\n if (renderLink) return renderLink(p);\n const L = LinkComponent;\n if (L) return <L {...p} />;\n return (\n <a href={p.href} className={p.className} aria-current={p[\"aria-current\"]} onClick={p.onClick}>\n {p.children}\n </a>\n );\n };\n\n const navClass = (active: boolean) =>\n cn(\n \"flex h-8 items-center gap-2 rounded-md px-2 text-sm text-foreground/80 outline-none hover:bg-accent hover:text-accent-foreground focus-visible:ring-2 focus-visible:ring-ring\",\n active && \"bg-accent font-medium text-accent-foreground\"\n );\n\n const close = () => setOpen(false);\n\n const nav = (\n <nav aria-label={t(\"nav_label\")} className=\"flex flex-col gap-0.5 text-sm\">\n {onSearch ? (\n <button\n type=\"button\"\n onClick={() => {\n close();\n onSearch();\n }}\n className=\"mb-3 flex h-8 items-center gap-2 rounded-md border bg-background px-2 text-sm text-muted-foreground outline-none hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring\"\n >\n <Search aria-hidden className=\"h-4 w-4\" />\n <span className=\"flex-1 text-left\">{t(\"search\")}</span>\n <kbd className=\"rounded border border-b-2 px-1 font-mono text-[11px]\">⌘K</kbd>\n </button>\n ) : null}\n <h2 className=\"px-2 pb-1 pt-2 text-xs font-medium text-muted-foreground\">{t(\"nav_collections\")}</h2>\n <ul className=\"flex flex-col gap-0.5\">\n {(me?.collections ?? []).map((c) => {\n const active = c.slug === activeCollection;\n return (\n <li key={c.slug}>\n {link({\n href: href({ kind: \"collection\", slug: c.slug }),\n className: navClass(active),\n \"aria-current\": active ? \"page\" : undefined,\n onClick: close,\n children: (\n <>\n <BookOpen aria-hidden className=\"h-4 w-4 shrink-0\" />\n <span className=\"flex-1 truncate\">{c.label}</span>\n {shown[c.slug] !== undefined ? <span className=\"text-xs tabular-nums text-muted-foreground\">{shown[c.slug]}</span> : null}\n </>\n ),\n })}\n </li>\n );\n })}\n </ul>\n {me?.media ? (\n <ul className=\"mt-3 flex flex-col gap-0.5\">\n <li>\n {link({\n href: href({ kind: \"media\" }),\n className: navClass(activeHref === href({ kind: \"media\" })),\n \"aria-current\": activeHref === href({ kind: \"media\" }) ? \"page\" : undefined,\n onClick: close,\n children: (\n <>\n <ImageIcon aria-hidden className=\"h-4 w-4 shrink-0\" />\n <span className=\"flex-1 truncate\">{t(\"nav_media\")}</span>\n </>\n ),\n })}\n </li>\n {me.media.stores.some((s) => s.can.browse) ? (\n <li>\n {link({\n href: href({ kind: \"files\" }),\n className: navClass(activeHref === href({ kind: \"files\" })),\n \"aria-current\": activeHref === href({ kind: \"files\" }) ? \"page\" : undefined,\n onClick: close,\n children: (\n <>\n <HardDrive aria-hidden className=\"h-4 w-4 shrink-0\" />\n <span className=\"flex-1 truncate\">{t(\"nav_files\")}</span>\n </>\n ),\n })}\n </li>\n ) : null}\n </ul>\n ) : null}\n {editor ? (\n <ul className={cn(\"flex flex-col gap-0.5\", me?.media ? \"mt-0.5\" : \"mt-3\")}>\n {(\n [\n { kind: \"releases\", label: t(\"nav_releases\"), Icon: Layers, n: null, show: true },\n { kind: \"trash\", label: t(\"nav_trash\"), Icon: Trash2, n: inTrash, show: hasTrash },\n ] as const\n )\n .filter((x) => x.show)\n .map(({ kind, label, Icon, n }) => {\n const h = href({ kind });\n const active = activeHref === h || (kind === \"releases\" && !!activeHref?.startsWith(`${h}/`));\n return (\n <li key={kind}>\n {link({\n href: h,\n className: navClass(active),\n \"aria-current\": active ? \"page\" : undefined,\n onClick: close,\n children: (\n <>\n <Icon aria-hidden className=\"h-4 w-4 shrink-0\" />\n <span className=\"flex-1 truncate\">{label}</span>\n {n ? <span className=\"text-xs tabular-nums text-muted-foreground\">{n}</span> : null}\n </>\n ),\n })}\n </li>\n );\n })}\n </ul>\n ) : null}\n {me?.isAdmin ? (\n <>\n <h2 className=\"px-2 pb-1 pt-4 text-xs font-medium text-muted-foreground\">{t(\"nav_ops\")}</h2>\n <ul className=\"flex flex-col gap-0.5\">\n {(\n [\n { kind: \"keys\", label: t(\"nav_keys\"), Icon: KeyRound },\n { kind: \"audit\", label: t(\"nav_audit\"), Icon: ScrollText },\n ] as const\n ).map(({ kind, label, Icon }) => {\n const h = href({ kind });\n const active = activeHref === h;\n return (\n <li key={kind}>\n {link({\n href: h,\n className: navClass(active),\n \"aria-current\": active ? \"page\" : undefined,\n onClick: close,\n children: (\n <>\n <Icon aria-hidden className=\"h-4 w-4 shrink-0\" />\n <span className=\"flex-1 truncate\">{label}</span>\n </>\n ),\n })}\n </li>\n );\n })}\n </ul>\n </>\n ) : null}\n {(extraNav ?? []).map((g, gi) => (\n <div key={gi} data-cms-extra-nav=\"\">\n <h2 className=\"px-2 pb-1 pt-4 text-xs font-medium text-muted-foreground\">{g.label}</h2>\n <ul className=\"flex flex-col gap-0.5\">\n {g.items.map((it) => {\n const active = activeHref === it.href;\n return (\n <li key={it.href}>\n {link({\n href: it.href,\n className: navClass(active),\n \"aria-current\": active ? \"page\" : undefined,\n onClick: close,\n children: (\n <>\n {it.icon ?? <FileText aria-hidden className=\"h-4 w-4 shrink-0\" />}\n <span className=\"flex-1 truncate\">{it.label}</span>\n {it.badge !== undefined && it.badge !== null ? <span className=\"text-xs tabular-nums text-muted-foreground\">{it.badge}</span> : null}\n </>\n ),\n })}\n </li>\n );\n })}\n </ul>\n </div>\n ))}\n </nav>\n );\n\n const brand = (\n <div className=\"mb-4 flex items-center gap-2 px-2 font-semibold\">\n {logo}\n <span className=\"truncate\">{title ?? t(\"shell_title\")}</span>\n </div>\n );\n\n const navCtx = React.useMemo(() => ({ openNav: () => setOpen(true) }), []);\n\n return (\n <ShellNavContext.Provider value={navCtx}>\n <div className={cn(\"flex min-h-screen bg-background text-foreground\", className)}>\n <aside className=\"sticky top-0 hidden h-screen w-60 shrink-0 overflow-y-auto border-r bg-muted/30 p-3 md:block\">\n {brand}\n {nav}\n </aside>\n <Sheet open={open} onOpenChange={setOpen}>\n <SheetContent side=\"left\" className=\"w-72 overflow-y-auto p-3\">\n <SheetTitle className=\"sr-only\">{t(\"menu\")}</SheetTitle>\n <SheetDescription className=\"sr-only\">{t(\"nav_label\")}</SheetDescription>\n {brand}\n {nav}\n </SheetContent>\n </Sheet>\n <main className=\"flex min-w-0 flex-1 flex-col\">{children}</main>\n </div>\n </ShellNavContext.Provider>\n );\n}\n"
20
20
  }
21
21
  ]
22
22
  }
@@ -0,0 +1,24 @@
1
+ {
2
+ "$schema": "https://ui.shadcn.com/schema/registry-item.json",
3
+ "name": "cms-trash",
4
+ "type": "registry:component",
5
+ "title": "Trash",
6
+ "description": "Deleted documents and files: restore them, or delete them forever (admins). Shown when `createCms({ trash })` keeps deleted things, which is the default (30 days).",
7
+ "dependencies": [
8
+ "@mainsoft/agent-cms",
9
+ "lucide-react"
10
+ ],
11
+ "registryDependencies": [
12
+ "button",
13
+ "checkbox",
14
+ "table",
15
+ "cms-lib"
16
+ ],
17
+ "files": [
18
+ {
19
+ "path": "registry/cms/cms-trash.tsx",
20
+ "type": "registry:component",
21
+ "content": "// agent-cms registry: cms-trash (0.10.0). Copied into your app by `npx agent-cms add`; edit freely.\n//\n// The trash: deleted documents and files wait here for `trash.days` days.\n// Restore brings them back as they were (a published document goes public\n// again); deleting forever is for admins.\n\"use client\";\n\nimport * as React from \"react\";\nimport { Trash2, Undo2 } from \"lucide-react\";\nimport type { TrashItem } from \"@mainsoft/agent-cms/client\";\nimport { Button } from \"@/components/ui/button\";\nimport { Checkbox } from \"@/components/ui/checkbox\";\nimport { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from \"@/components/ui/table\";\nimport { cn } from \"@/lib/utils\";\nimport { errorMessage } from \"./cms-messages\";\nimport { ConfirmDialog, PageHeader, Segmented, StatusText } from \"./cms-parts\";\nimport { useCms } from \"./use-cms\";\n\nexport interface CmsTrashProps {\n className?: string;\n}\n\ntype Kind = TrashItem[\"kind\"];\n\n/** Whole days until `iso` (at least 0). */\nexport function daysLeft(iso: string, now: number = Date.now()): number {\n return Math.max(0, Math.ceil((Date.parse(iso) - now) / 86_400_000));\n}\n\nexport function CmsTrash({ className }: CmsTrashProps) {\n const { client, t, locale, me } = useCms();\n const [data, setData] = React.useState<{ items: TrashItem[]; days: number; canPurge: boolean } | null>(null);\n const [error, setError] = React.useState<unknown>(null);\n const [kind, setKind] = React.useState<Kind>(\"document\");\n const [picked, setPicked] = React.useState<ReadonlySet<string>>(new Set());\n const [confirm, setConfirm] = React.useState<null | { what: \"restore\" | \"purge\"; ids: string[] } | { what: \"empty\" }>(null);\n const [busy, setBusy] = React.useState(false);\n const [problem, setProblem] = React.useState<string | null>(null);\n const [status, setStatus] = React.useState<string | null>(null);\n const [tick, setTick] = React.useState(0);\n\n React.useEffect(() => {\n let live = true;\n client.trash().then(\n (r) => live && (setData(r), setError(null), setPicked(new Set())),\n (e) => live && setError(e)\n );\n return () => {\n live = false;\n };\n }, [client, tick]);\n\n const all = data?.items ?? [];\n const docs = all.filter((i) => i.kind === \"document\");\n const files = all.filter((i) => i.kind === \"asset\");\n const hasFiles = !!me?.media || files.length > 0;\n const rows = kind === \"document\" ? docs : files;\n const allPicked = rows.length > 0 && rows.every((r) => picked.has(r.id));\n const toggle = (id: string, on: boolean) =>\n setPicked((now) => {\n const next = new Set(now);\n if (on) next.add(id);\n else next.delete(id);\n return next;\n });\n const refs = (ids: string[]) => ids.map((id) => ({ kind, id }));\n const restorable = rows.filter((r) => picked.has(r.id) && r.canRestore).map((r) => r.id);\n\n const run = async () => {\n if (!confirm) return;\n setBusy(true);\n setProblem(null);\n try {\n if (confirm.what === \"empty\") setStatus(t(\"trash_purged\", { n: (await client.purgeTrash(\"all\")).purged }));\n else if (confirm.what === \"purge\") setStatus(t(\"trash_purged\", { n: (await client.purgeTrash(refs(confirm.ids))).purged }));\n else {\n const r = await client.restoreTrash(refs(confirm.ids));\n setStatus(r.restored < confirm.ids.length ? `${t(\"trash_restored\", { n: r.restored })}. ${t(\"trash_slug_taken\")}` : t(\"trash_restored\", { n: r.restored }));\n }\n setConfirm(null);\n setTick((n) => n + 1);\n } catch (e) {\n setProblem(errorMessage(e, t));\n } finally {\n setBusy(false);\n }\n };\n\n const bulk = \"h-7 gap-1.5 px-2 text-[13px]\";\n const n = confirm && confirm.what !== \"empty\" ? confirm.ids.length : all.length;\n\n return (\n <div className={cn(\"flex min-h-0 flex-1 flex-col\", className)}>\n <PageHeader title={t(\"nav_trash\")}>\n {data?.canPurge ? (\n <Button type=\"button\" variant=\"outline\" className=\"gap-1.5 text-destructive hover:text-destructive\" disabled={!all.length} onClick={() => setConfirm({ what: \"empty\" })}>\n <Trash2 aria-hidden className=\"h-4 w-4\" />\n {t(\"trash_empty_all\")}\n </Button>\n ) : null}\n </PageHeader>\n <div className=\"flex-1 px-4 py-4 md:px-6\">\n {hasFiles ? (\n <div className=\"mb-3 flex items-center gap-2\">\n <Segmented\n label={t(\"trash_kind\")}\n value={kind}\n onChange={(k) => (setKind(k), setPicked(new Set()))}\n options={[\n { value: \"document\", label: t(\"trash_docs\", { n: docs.length }) },\n { value: \"asset\", label: t(\"trash_files\", { n: files.length }) },\n ]}\n />\n </div>\n ) : null}\n {picked.size ? (\n <div role=\"toolbar\" aria-label={t(\"bulk_bar\")} className=\"mb-2.5 flex flex-wrap items-center gap-1.5 rounded-lg border bg-muted/40 py-1.5 pl-3 pr-2\">\n <span className=\"mr-1 text-[13px] font-medium\" role=\"status\">\n {t(\"selected_n\", { n: picked.size })}\n </span>\n <Button type=\"button\" variant=\"outline\" size=\"sm\" className={bulk} disabled={!restorable.length} onClick={() => setConfirm({ what: \"restore\", ids: restorable })}>\n <Undo2 aria-hidden className=\"h-3.5 w-3.5\" />\n {t(\"trash_restore\")}\n </Button>\n {data?.canPurge ? (\n <Button type=\"button\" variant=\"outline\" size=\"sm\" className={cn(bulk, \"text-destructive hover:text-destructive\")} onClick={() => setConfirm({ what: \"purge\", ids: [...picked] })}>\n <Trash2 aria-hidden className=\"h-3.5 w-3.5\" />\n {t(\"trash_purge\")}\n </Button>\n ) : null}\n <span className=\"flex-1\" />\n <Button type=\"button\" variant=\"ghost\" size=\"sm\" className={bulk} onClick={() => setPicked(new Set())}>\n {t(\"clear_selection\")}\n </Button>\n </div>\n ) : null}\n {kind === \"asset\" && files.length ? <p className=\"mb-2.5 text-xs text-muted-foreground\">{t(\"trash_file_note\")}</p> : null}\n {error ? <StatusText tone=\"error\">{errorMessage(error, t)}</StatusText> : null}\n {data && !rows.length ? <p className=\"py-16 text-center text-sm text-muted-foreground\">{t(\"trash_none\")}</p> : null}\n {rows.length ? (\n <Table>\n <TableHeader>\n <TableRow>\n <TableHead className=\"w-9\">\n <Checkbox aria-label={t(\"select_all\")} checked={allPicked} onCheckedChange={(v) => setPicked(v === true ? new Set(rows.map((r) => r.id)) : new Set())} />\n </TableHead>\n <TableHead>{t(\"name\")}</TableHead>\n <TableHead className=\"hidden w-[160px] md:table-cell\">{t(\"trash_col_where\")}</TableHead>\n <TableHead className=\"hidden w-[150px] md:table-cell\">{t(\"trash_col_by\")}</TableHead>\n <TableHead className=\"hidden w-[130px] sm:table-cell\">{t(\"trash_col_at\")}</TableHead>\n <TableHead className=\"w-[110px] text-right\">{t(\"trash_col_left\")}</TableHead>\n </TableRow>\n </TableHeader>\n <TableBody>\n {rows.map((r) => (\n <TableRow key={r.id} data-state={picked.has(r.id) ? \"selected\" : undefined}>\n <TableCell>\n <Checkbox aria-label={t(\"select_row\", { title: r.title })} checked={picked.has(r.id)} onCheckedChange={(v) => toggle(r.id, v === true)} />\n </TableCell>\n <TableCell className=\"max-w-0\">\n <div className=\"truncate font-medium\">{r.title}</div>\n <div className=\"truncate text-xs text-muted-foreground md:hidden\">{r.where}</div>\n </TableCell>\n <TableCell className=\"hidden max-w-0 truncate text-[13.5px] md:table-cell\">{r.where}</TableCell>\n <TableCell className=\"hidden max-w-0 truncate text-[13.5px] md:table-cell\">{r.deletedBy ?? \"\"}</TableCell>\n <TableCell className=\"hidden tabular-nums sm:table-cell\">{new Date(r.deletedAt).toLocaleDateString(locale)}</TableCell>\n <TableCell className=\"text-right tabular-nums\">{r.purgeAt ? t(\"days_n\", { n: daysLeft(r.purgeAt) }) : \"\"}</TableCell>\n </TableRow>\n ))}\n </TableBody>\n </Table>\n ) : null}\n </div>\n <div className=\"flex items-center gap-3 px-4 py-3 text-xs text-muted-foreground md:px-6\">\n <StatusText className=\"text-xs\">{status ?? (data ? t(\"shown_of\", { shown: rows.length, total: rows.length }) : t(\"loading\"))}</StatusText>\n </div>\n <ConfirmDialog\n open={!!confirm}\n onOpenChange={(o) => {\n if (!o) {\n setConfirm(null);\n setProblem(null);\n }\n }}\n title={!confirm ? \"\" : confirm.what === \"empty\" ? t(\"trash_purge_all\") : confirm.what === \"purge\" ? t(\"trash_purge_title\", { n }) : t(kind === \"document\" ? \"trash_restore_docs\" : \"trash_restore_files\", { n })}\n description={!confirm ? undefined : confirm.what === \"restore\" ? (kind === \"document\" ? t(\"trash_restore_note\") : undefined) : t(\"trash_purge_note\")}\n confirmLabel={confirm?.what === \"restore\" ? t(\"trash_restore\") : confirm?.what === \"empty\" ? t(\"trash_empty_all\") : t(\"trash_purge\")}\n destructive={confirm?.what !== \"restore\"}\n busy={busy}\n error={problem}\n onConfirm={run}\n >\n {confirm && confirm.what !== \"empty\" ? (\n <ul className=\"max-h-60 overflow-y-auto rounded-md border\">\n {rows\n .filter((r) => confirm.ids.includes(r.id))\n .map((r) => (\n <li key={r.id} className=\"flex items-center gap-2 border-b px-3 py-2 last:border-b-0\">\n <span className=\"flex-1 truncate text-sm font-medium\">{r.title}</span>\n <span className=\"shrink-0 text-xs text-muted-foreground\">{r.where}</span>\n </li>\n ))}\n </ul>\n ) : null}\n </ConfirmDialog>\n </div>\n );\n}\n"
22
+ }
23
+ ]
24
+ }
@@ -12,6 +12,7 @@
12
12
  "badge",
13
13
  "button",
14
14
  "dialog",
15
+ "input",
15
16
  "label",
16
17
  "select",
17
18
  "cms-lib"
@@ -20,7 +21,7 @@
20
21
  {
21
22
  "path": "registry/cms/cms-versions.tsx",
22
23
  "type": "registry:component",
23
- "content": "// agent-cms registry: cms-versions (0.6.0). Copied into your app by `npx agent-cms add`; edit freely.\n//\n// Version history of one document: who saved what (agent or person, note,\n// published marker, changed fields), a compare of any two versions (side by\n// side or unified, word-level highlight), restore and publish a version.\n\"use client\";\n\nimport * as React from \"react\";\nimport { ArrowLeft, ArrowRight, ChevronLeft, RotateCcw } from \"lucide-react\";\nimport { diffWords, type Hunk, type HunkLine } from \"@mainsoft/agent-cms/diff\";\nimport type { CmsDoc, VersionSummary } from \"@mainsoft/agent-cms/types\";\nimport { Badge } from \"@/components/ui/badge\";\nimport { Button } from \"@/components/ui/button\";\nimport { Label } from \"@/components/ui/label\";\nimport { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from \"@/components/ui/select\";\nimport { cn } from \"@/lib/utils\";\nimport { errorMessage, type MessageKey } from \"./cms-messages\";\nimport { ConfirmDialog, PageHeader, Segmented, StateBadge, StatusText, Who } from \"./cms-parts\";\nimport { relativeTime, useAsync, useCms, useIsMobile, useLocalStorage } from \"./use-cms\";\n\ntype DocDiff = Awaited<ReturnType<import(\"@mainsoft/agent-cms/client\").RestClient[\"diff\"]>>;\n\nexport interface CmsVersionsProps {\n collection: string;\n slug: string;\n /** \"Back to editing\". */\n onBack?: () => void;\n /** After a restore or publish. */\n onChanged?: (doc: CmsDoc) => void;\n className?: string;\n}\n\nconst FIELD_LABEL: Record<string, MessageKey> = { title: \"field_title\", slug: \"field_slug\", summary: \"field_summary\", category: \"field_category\", keywords: \"field_keywords\", body: \"field_body\" };\nconst show = (v: unknown): string => (v === undefined || v === null ? \"\" : Array.isArray(v) ? v.join(\", \") : typeof v === \"object\" ? JSON.stringify(v) : String(v));\n\n/** Pair the removed and added lines of a hunk row by row (for side by side and word highlight). */\ntype Row = { t: \"ctx\"; a: HunkLine; b: HunkLine } | { t: \"chg\"; a: HunkLine | null; b: HunkLine | null };\nfunction rowsOf(h: Hunk): Row[] {\n const out: Row[] = [];\n let dels: HunkLine[] = [];\n let adds: HunkLine[] = [];\n const flush = () => {\n for (let i = 0; i < Math.max(dels.length, adds.length); i++) out.push({ t: \"chg\", a: dels[i] ?? null, b: adds[i] ?? null });\n dels = [];\n adds = [];\n };\n for (const l of h.lines) {\n if (l.t === \"-\") dels.push(l);\n else if (l.t === \"+\") adds.push(l);\n else {\n flush();\n out.push({ t: \"ctx\", a: l, b: l });\n }\n }\n flush();\n return out;\n}\n\nfunction Words({ a, b, side }: { a: string; b: string; side: \"a\" | \"b\" }) {\n return (\n <>\n {diffWords(a, b).map((p, i) =>\n p.t === \"eq\" ? (\n <React.Fragment key={i}>{p.v}</React.Fragment>\n ) : p.t === \"del\" && side === \"a\" ? (\n <del key={i} className=\"bg-red-200 no-underline\">\n {p.v}\n </del>\n ) : p.t === \"ins\" && side === \"b\" ? (\n <ins key={i} className=\"bg-green-200 no-underline\">\n {p.v}\n </ins>\n ) : null\n )}\n </>\n );\n}\n\nfunction headingBefore(body: string | undefined, line: number): string | null {\n if (!body) return null;\n const lines = body.split(\"\\n\").slice(0, Math.max(0, line - 1));\n for (let i = lines.length - 1; i >= 0; i--) if (/^#{1,6}\\s/.test(lines[i])) return lines[i];\n return null;\n}\n\nexport function CmsVersions({ collection, slug, onBack, onChanged, className }: CmsVersionsProps) {\n const { client, t, locale } = useCms();\n const mobile = useIsMobile();\n const schema = useAsync(() => client.schema(collection), [client, collection]);\n const list = useAsync(() => client.versions(collection, slug), [client, collection, slug]);\n const versions = list.data ?? [];\n const latest = versions[0]?.version ?? 0;\n const publishedV = versions.find((v) => v.published)?.version ?? null;\n\n const [to, setTo] = React.useState<number | null>(null);\n const [from, setFrom] = React.useState<number | null>(null);\n const [savedView, setView] = useLocalStorage<\"split\" | \"unified\">(\"agent-cms:diff-view\", \"split\");\n const view = mobile ? \"unified\" : savedView;\n const [confirm, setConfirm] = React.useState<\"restore\" | null>(null);\n const [busy, setBusy] = React.useState(false);\n const [status, setStatus] = React.useState<{ text: string; tone: \"ok\" | \"error\" } | null>(null);\n\n // Default: latest against the published version (or the one before).\n React.useEffect(() => {\n if (!versions.length || to !== null) return;\n const b = versions[0].version;\n const a = publishedV !== null && publishedV !== b ? publishedV : (versions[1]?.version ?? b);\n setTo(b);\n setFrom(a);\n }, [versions, to, publishedV]);\n\n const diff = useAsync<{ d: DocDiff; body?: string } | null>(\n async () => {\n if (from === null || to === null) return null;\n const [d, v] = await Promise.all([client.diff(collection, slug, from, to), client.version(collection, slug, to).catch(() => null)]);\n return { d, body: v?.snapshot.body };\n },\n [client, collection, slug, from, to]\n );\n\n const pick = (v: VersionSummary) => {\n setTo(v.version);\n const idx = versions.findIndex((x) => x.version === v.version);\n const prev = versions[idx + 1]?.version;\n setFrom(publishedV !== null && publishedV < v.version ? publishedV : (prev ?? v.version));\n };\n\n const run = async (what: \"restore\" | \"publish\") => {\n if (from === null || to === null) return;\n setBusy(true);\n setStatus(null);\n try {\n const d = what === \"restore\" ? await client.restore(collection, slug, from, { expectedVersion: latest }) : await client.publish(collection, slug, { version: to, expectedVersion: latest });\n setStatus({ text: what === \"restore\" ? t(\"restored\", { version: d.version }) : t(\"published_v\", { version: to }), tone: \"ok\" });\n setConfirm(null);\n setTo(null);\n list.reload();\n onChanged?.(d);\n } catch (e) {\n setStatus({ text: errorMessage(e, t), tone: \"error\" });\n } finally {\n setBusy(false);\n }\n };\n\n const canWrite = schema.data?.canWrite ?? false;\n const canPublish = schema.data?.canPublish ?? false;\n const label = (n: number) => (n === publishedV ? t(\"version_published_tag\", { version: n }) : `v${n}`);\n const toInfo = versions.find((v) => v.version === to);\n\n const picker = (id: string, text: string, value: number | null, set: (n: number) => void) => (\n <div className={cn(\"flex flex-col gap-1\", mobile && \"flex-1\")}>\n <Label htmlFor={id} className=\"sr-only\">\n {text}\n </Label>\n <Select value={value === null ? undefined : String(value)} onValueChange={(v: string | null) => v && set(Number(v))}>\n <SelectTrigger id={id} className={cn(\"h-8 text-[13px]\", mobile ? \"w-full\" : \"w-40\")}>\n <SelectValue>{value === null ? null : label(value)}</SelectValue>\n </SelectTrigger>\n <SelectContent>\n {versions.map((v) => (\n <SelectItem key={v.version} value={String(v.version)}>\n {label(v.version)}\n </SelectItem>\n ))}\n </SelectContent>\n </Select>\n </div>\n );\n\n const compare = (\n <div className=\"flex flex-wrap items-center gap-2\" role=\"group\" aria-label={`${t(\"compare_from\")}, ${t(\"compare_to\")}`}>\n {picker(\"cms-v-from\", t(\"compare_from\"), from, setFrom)}\n <ArrowRight aria-hidden className=\"h-4 w-4 text-muted-foreground\" />\n {picker(\"cms-v-to\", t(\"compare_to\"), to, setTo)}\n {!mobile ? (\n <Segmented\n label={t(\"view_mode\")}\n value={savedView}\n onChange={setView}\n options={[\n { value: \"split\", label: t(\"side_by_side\") },\n { value: \"unified\", label: t(\"unified\") },\n ]}\n />\n ) : null}\n </div>\n );\n\n const actions = (cls?: string) =>\n from !== null && to !== null ? (\n <>\n {canWrite && from !== latest ? (\n <Button type=\"button\" variant=\"outline\" className={cn(\"gap-1.5\", cls)} disabled={busy} onClick={() => setConfirm(\"restore\")}>\n <RotateCcw aria-hidden className=\"h-4 w-4\" />\n {t(\"restore_version\", { version: from })}\n </Button>\n ) : null}\n {canPublish && to !== publishedV ? (\n <Button type=\"button\" className={cls} disabled={busy} onClick={() => void run(\"publish\")}>\n {t(\"publish_version\", { version: to })}\n </Button>\n ) : null}\n </>\n ) : null;\n\n const d = diff.data?.d;\n const body = diff.data?.body;\n\n const fieldTable = d && d.fields.length ? (\n <div className=\"overflow-hidden rounded-lg border\">\n <table className=\"w-full text-sm\">\n <thead>\n <tr className=\"border-b text-left text-xs text-muted-foreground\">\n <th className=\"px-3 py-2 font-medium\">{t(\"field\")}</th>\n {!mobile ? <th className=\"px-3 py-2 font-medium\">{label(d.a)}</th> : null}\n <th className=\"px-3 py-2 font-medium\">{mobile ? `${label(d.a)} → v${d.b}` : `v${d.b}`}</th>\n </tr>\n </thead>\n <tbody>\n {d.fields.map((f) => {\n const name = FIELD_LABEL[f.path] ? t(FIELD_LABEL[f.path]) : f.path.replace(/^fields\\./, \"\");\n const a = show(f.from);\n const b = show(f.to);\n return (\n <tr key={f.path} className=\"border-b last:border-b-0 align-top\">\n <td className=\"px-3 py-2 text-xs\">{name}</td>\n {!mobile ? (\n <td className=\"px-3 py-2 font-mono text-xs\">\n <Words a={a} b={b} side=\"a\" />\n </td>\n ) : null}\n <td className=\"px-3 py-2 font-mono text-xs\">\n <Words a={a} b={b} side=\"b\" />\n </td>\n </tr>\n );\n })}\n </tbody>\n </table>\n </div>\n ) : null;\n\n const hunkHead = (h: Hunk) => {\n const head = headingBefore(body, h.bStart + 1);\n return `@@ ${head ?? `-${h.aStart},${h.aLines} +${h.bStart},${h.bLines}`}`;\n };\n\n const lineCls = (k: \"del\" | \"add\" | \"ctx\" | \"pad\") => cn(\"flex min-w-0 gap-2 px-2 font-mono text-xs leading-6\", k === \"del\" && \"bg-red-50\", k === \"add\" && \"bg-green-50\", k === \"pad\" && \"bg-muted/40\");\n const num = (n?: number) => (\n <i aria-hidden className=\"w-8 shrink-0 select-none text-right not-italic text-muted-foreground\">\n {n ?? \"\"}\n </i>\n );\n\n const split = d ? (\n <div className=\"overflow-hidden rounded-lg border\">\n <div className=\"grid grid-cols-2 border-b text-xs font-medium text-muted-foreground\">\n <span className=\"px-3 py-1.5\">{label(d.a)}</span>\n <span className=\"border-l px-3 py-1.5\">v{d.b}</span>\n </div>\n {d.hunks.map((h, hi) => (\n <div key={hi}>\n <div className=\"border-y bg-muted/40 px-3 py-1 font-mono text-xs text-muted-foreground first:border-t-0\">{hunkHead(h)}</div>\n <div className=\"grid grid-cols-2\">\n {rowsOf(h).map((r, i) => (\n <React.Fragment key={i}>\n <div className={lineCls(r.t === \"ctx\" ? \"ctx\" : r.a ? \"del\" : \"pad\")}>\n {num(r.a?.a)}\n <span className=\"min-w-0 whitespace-pre-wrap break-words\">\n {r.t === \"chg\" && r.a ? <span className=\"sr-only\">- </span> : null}\n {r.a ? r.t === \"chg\" && r.b ? <Words a={r.a.v} b={r.b.v} side=\"a\" /> : r.a.v : \"\"}\n </span>\n </div>\n <div className={cn(lineCls(r.t === \"ctx\" ? \"ctx\" : r.b ? \"add\" : \"pad\"), \"border-l\")}>\n {num(r.b?.b)}\n <span className=\"min-w-0 whitespace-pre-wrap break-words\">\n {r.t === \"chg\" && r.b ? <span className=\"sr-only\">+ </span> : null}\n {r.b ? r.t === \"chg\" && r.a ? <Words a={r.a.v} b={r.b.v} side=\"b\" /> : r.b.v : \"\"}\n </span>\n </div>\n </React.Fragment>\n ))}\n </div>\n </div>\n ))}\n </div>\n ) : null;\n\n const unified = d ? (\n <div className={cn(\"overflow-hidden\", mobile ? \"border-t\" : \"rounded-lg border\")}>\n {d.hunks.map((h, hi) => {\n const rows = rowsOf(h);\n const pairs = new Map<HunkLine, string>();\n for (const r of rows) if (r.t === \"chg\" && r.a && r.b) (pairs.set(r.a, r.b.v), pairs.set(r.b, r.a.v));\n return (\n <div key={hi}>\n <div className=\"border-b bg-muted/40 px-3 py-1 font-mono text-xs text-muted-foreground\">{hunkHead(h)}</div>\n {h.lines.map((l, i) => {\n const other = pairs.get(l);\n return (\n <div key={i} className={lineCls(l.t === \"-\" ? \"del\" : l.t === \"+\" ? \"add\" : \"ctx\")}>\n <span aria-hidden className=\"w-3 shrink-0 select-none text-muted-foreground\">\n {l.t === \"-\" ? \"−\" : l.t === \"+\" ? \"+\" : \" \"}\n </span>\n <span className=\"min-w-0 whitespace-pre-wrap break-words\">\n {l.t !== \" \" ? <span className=\"sr-only\">{l.t} </span> : null}\n {other !== undefined ? l.t === \"-\" ? <Words a={l.v} b={other} side=\"a\" /> : <Words a={other} b={l.v} side=\"b\" /> : l.v}\n </span>\n </div>\n );\n })}\n </div>\n );\n })}\n </div>\n ) : null;\n\n const diffArea = (\n <div className=\"flex min-w-0 flex-1 flex-col gap-3\">\n {diff.error ? <StatusText tone=\"error\">{errorMessage(diff.error, t)}</StatusText> : null}\n {d && !d.fields.length && !d.hunks.length ? <p className=\"text-sm text-muted-foreground\">{t(\"no_diff\")}</p> : null}\n {fieldTable}\n {d && d.hunks.length ? (view === \"unified\" ? unified : split) : null}\n </div>\n );\n\n const confirmDialog = (\n <ConfirmDialog\n open={confirm === \"restore\"}\n onOpenChange={(o) => !o && setConfirm(null)}\n title={t(\"restore_confirm\", { version: from ?? 0 })}\n description={t(\"restore_confirm_note\", { version: from ?? 0 })}\n confirmLabel={t(\"restore_version\", { version: from ?? 0 })}\n busy={busy}\n onConfirm={() => run(\"restore\")}\n />\n );\n\n const statusLine = (\n <StatusText tone={status?.tone === \"error\" ? \"error\" : \"ok\"} className=\"text-xs\">\n {status?.text ?? (list.loading && !versions.length ? t(\"loading\") : \"\")}\n </StatusText>\n );\n\n if (mobile)\n return (\n <div className={cn(\"flex min-h-0 flex-1 flex-col\", className)}>\n <PageHeader\n title={t(\"versions\")}\n back={\n onBack ? (\n <Button type=\"button\" variant=\"ghost\" size=\"icon\" className=\"-ml-2 h-8 w-8\" aria-label={t(\"versions_back\")} onClick={onBack}>\n <ChevronLeft aria-hidden className=\"h-4 w-4\" />\n </Button>\n ) : undefined\n }\n />\n <div className=\"border-b px-4 py-2.5\">{compare}</div>\n <div className=\"flex-1\">\n {toInfo ? (\n <div className=\"flex flex-col gap-0.5 px-4 py-2.5 text-xs\">\n <div className=\"flex items-center gap-2\">\n <Who kind={toInfo.authorKind} label={toInfo.authorLabel} className=\"font-medium\" />\n <span className=\"text-muted-foreground\">{relativeTime(toInfo.createdAt, t, locale)}</span>\n </div>\n {toInfo.note ? <div className=\"text-muted-foreground\">{toInfo.note}</div> : null}\n </div>\n ) : null}\n <div className=\"px-4 pb-2\">{statusLine}</div>\n {diffArea}\n </div>\n <div className=\"sticky bottom-0 flex gap-2 border-t bg-background p-2\">{actions(\"flex-1\")}</div>\n {confirmDialog}\n </div>\n );\n\n return (\n <div className={cn(\"flex min-h-0 flex-1 flex-col\", className)}>\n <PageHeader title={t(\"versions\")} crumbs={[schema.data?.label ?? collection, slug]}>\n {onBack ? (\n <Button type=\"button\" variant=\"ghost\" className=\"gap-1.5\" onClick={onBack}>\n <ArrowLeft aria-hidden className=\"h-4 w-4\" />\n {t(\"versions_back\")}\n </Button>\n ) : null}\n </PageHeader>\n <div className=\"flex min-h-0 flex-1\">\n <nav aria-label={t(\"versions_list\")} className=\"w-64 shrink-0 overflow-y-auto border-r\">\n <ul>\n {versions.map((v) => {\n const on = v.version === to;\n const cmp = v.version === from && !on;\n return (\n <li key={v.version}>\n <button\n type=\"button\"\n aria-current={on ? \"true\" : undefined}\n onClick={() => pick(v)}\n className={cn(\"flex w-full flex-col gap-1 border-b px-3.5 py-2.5 text-left outline-none hover:bg-muted/50 focus-visible:bg-muted\", on && \"bg-muted\", cmp && \"bg-muted/40\")}\n >\n <span className=\"flex w-full items-center gap-2 text-sm\">\n <b>v{v.version}</b>\n {v.published ? <StateBadge state=\"published\" /> : null}\n <span className=\"flex-1\" />\n <span className=\"text-xs text-muted-foreground\">{relativeTime(v.createdAt, t, locale)}</span>\n </span>\n <span className=\"flex items-center gap-1.5 text-xs\">\n <Who kind={v.authorKind} label={v.authorLabel} />\n <Badge variant=\"outline\" className={cn(\"h-4 rounded-full px-1.5 text-[10.5px] font-normal\", v.authorKind !== \"user\" && \"border-blue-200 bg-blue-50 text-blue-700\")}>\n {v.authorKind === \"user\" ? t(\"kind_user\") : t(\"kind_agent\")}\n </Badge>\n </span>\n {v.note ? <span className=\"text-xs text-muted-foreground\">{v.note}</span> : null}\n {v.changed?.fields.length ? (\n <span className=\"text-[11px] text-muted-foreground\">\n {t(\"changed_fields\", { fields: v.changed.fields.map((f) => (FIELD_LABEL[f] ? t(FIELD_LABEL[f]) : f.replace(/^fields\\./, \"\"))).join(\", \") })}\n </span>\n ) : null}\n </button>\n </li>\n );\n })}\n </ul>\n </nav>\n <div className=\"flex min-w-0 flex-1 flex-col gap-3 overflow-y-auto px-6 py-4\">\n <div className=\"flex flex-wrap items-center gap-2\">\n {compare}\n <span className=\"flex-1\" />\n {actions()}\n </div>\n {statusLine}\n {diffArea}\n </div>\n </div>\n {confirmDialog}\n </div>\n );\n}\n"
24
+ "content": "// agent-cms registry: cms-versions (0.10.0). Copied into your app by `npx agent-cms add`; edit freely.\n//\n// Version history of one document: who saved what (agent or person, note,\n// published marker, changed fields), a compare of any two versions (side by\n// side or unified, word-level highlight), restore and publish a version,\n// and give a version a name or pin it so it is never cleaned up.\n\"use client\";\n\nimport * as React from \"react\";\nimport { ArrowLeft, ArrowRight, ChevronLeft, Pin, RotateCcw, Tag } from \"lucide-react\";\nimport { diffWords, type Hunk, type HunkLine } from \"@mainsoft/agent-cms/diff\";\nimport type { CmsDoc, VersionSummary } from \"@mainsoft/agent-cms/types\";\nimport { Badge } from \"@/components/ui/badge\";\nimport { Button } from \"@/components/ui/button\";\nimport { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from \"@/components/ui/dialog\";\nimport { Input } from \"@/components/ui/input\";\nimport { Label } from \"@/components/ui/label\";\nimport { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from \"@/components/ui/select\";\nimport { cn } from \"@/lib/utils\";\nimport { errorMessage, type MessageKey } from \"./cms-messages\";\nimport { ConfirmDialog, PageHeader, Segmented, StateBadge, StatusText, Who } from \"./cms-parts\";\nimport { relativeTime, useAsync, useCms, useIsMobile, useLocalStorage } from \"./use-cms\";\n\ntype DocDiff = Awaited<ReturnType<import(\"@mainsoft/agent-cms/client\").RestClient[\"diff\"]>>;\n\nexport interface CmsVersionsProps {\n collection: string;\n slug: string;\n /** \"Back to editing\". */\n onBack?: () => void;\n /** After a restore or publish. */\n onChanged?: (doc: CmsDoc) => void;\n className?: string;\n}\n\nconst FIELD_LABEL: Record<string, MessageKey> = { title: \"field_title\", slug: \"field_slug\", summary: \"field_summary\", category: \"field_category\", keywords: \"field_keywords\", body: \"field_body\" };\nconst show = (v: unknown): string => (v === undefined || v === null ? \"\" : Array.isArray(v) ? v.join(\", \") : typeof v === \"object\" ? JSON.stringify(v) : String(v));\n\n/** Pair the removed and added lines of a hunk row by row (for side by side and word highlight). */\ntype Row = { t: \"ctx\"; a: HunkLine; b: HunkLine } | { t: \"chg\"; a: HunkLine | null; b: HunkLine | null };\nfunction rowsOf(h: Hunk): Row[] {\n const out: Row[] = [];\n let dels: HunkLine[] = [];\n let adds: HunkLine[] = [];\n const flush = () => {\n for (let i = 0; i < Math.max(dels.length, adds.length); i++) out.push({ t: \"chg\", a: dels[i] ?? null, b: adds[i] ?? null });\n dels = [];\n adds = [];\n };\n for (const l of h.lines) {\n if (l.t === \"-\") dels.push(l);\n else if (l.t === \"+\") adds.push(l);\n else {\n flush();\n out.push({ t: \"ctx\", a: l, b: l });\n }\n }\n flush();\n return out;\n}\n\nfunction Words({ a, b, side }: { a: string; b: string; side: \"a\" | \"b\" }) {\n return (\n <>\n {diffWords(a, b).map((p, i) =>\n p.t === \"eq\" ? (\n <React.Fragment key={i}>{p.v}</React.Fragment>\n ) : p.t === \"del\" && side === \"a\" ? (\n <del key={i} className=\"bg-red-200 no-underline\">\n {p.v}\n </del>\n ) : p.t === \"ins\" && side === \"b\" ? (\n <ins key={i} className=\"bg-green-200 no-underline\">\n {p.v}\n </ins>\n ) : null\n )}\n </>\n );\n}\n\nfunction headingBefore(body: string | undefined, line: number): string | null {\n if (!body) return null;\n const lines = body.split(\"\\n\").slice(0, Math.max(0, line - 1));\n for (let i = lines.length - 1; i >= 0; i--) if (/^#{1,6}\\s/.test(lines[i])) return lines[i];\n return null;\n}\n\nexport function CmsVersions({ collection, slug, onBack, onChanged, className }: CmsVersionsProps) {\n const { client, t, locale } = useCms();\n const mobile = useIsMobile();\n const schema = useAsync(() => client.schema(collection), [client, collection]);\n const list = useAsync(() => client.versions(collection, slug), [client, collection, slug]);\n const versions = list.data ?? [];\n const latest = versions[0]?.version ?? 0;\n const publishedV = versions.find((v) => v.published)?.version ?? null;\n\n const [to, setTo] = React.useState<number | null>(null);\n const [from, setFrom] = React.useState<number | null>(null);\n const [savedView, setView] = useLocalStorage<\"split\" | \"unified\">(\"agent-cms:diff-view\", \"split\");\n const view = mobile ? \"unified\" : savedView;\n const [confirm, setConfirm] = React.useState<\"restore\" | null>(null);\n const [naming, setNaming] = React.useState<string | null>(null);\n const [busy, setBusy] = React.useState(false);\n const [status, setStatus] = React.useState<{ text: string; tone: \"ok\" | \"error\" } | null>(null);\n\n // Default: latest against the published version (or the one before).\n React.useEffect(() => {\n if (!versions.length || to !== null) return;\n const b = versions[0].version;\n const a = publishedV !== null && publishedV !== b ? publishedV : (versions[1]?.version ?? b);\n setTo(b);\n setFrom(a);\n }, [versions, to, publishedV]);\n\n const diff = useAsync<{ d: DocDiff; body?: string } | null>(\n async () => {\n if (from === null || to === null) return null;\n const [d, v] = await Promise.all([client.diff(collection, slug, from, to), client.version(collection, slug, to).catch(() => null)]);\n return { d, body: v?.snapshot.body };\n },\n [client, collection, slug, from, to]\n );\n\n const pick = (v: VersionSummary) => {\n setTo(v.version);\n const idx = versions.findIndex((x) => x.version === v.version);\n const prev = versions[idx + 1]?.version;\n setFrom(publishedV !== null && publishedV < v.version ? publishedV : (prev ?? v.version));\n };\n\n const run = async (what: \"restore\" | \"publish\") => {\n if (from === null || to === null) return;\n setBusy(true);\n setStatus(null);\n try {\n const d = what === \"restore\" ? await client.restore(collection, slug, from, { expectedVersion: latest }) : await client.publish(collection, slug, { version: to, expectedVersion: latest });\n setStatus({ text: what === \"restore\" ? t(\"restored\", { version: d.version }) : t(\"published_v\", { version: to }), tone: \"ok\" });\n setConfirm(null);\n setTo(null);\n list.reload();\n onChanged?.(d);\n } catch (e) {\n setStatus({ text: errorMessage(e, t), tone: \"error\" });\n } finally {\n setBusy(false);\n }\n };\n\n const canWrite = schema.data?.canWrite ?? false;\n const canPublish = schema.data?.canPublish ?? false;\n const label = (n: number) => (n === publishedV ? t(\"version_published_tag\", { version: n }) : `v${n}`);\n const toInfo = versions.find((v) => v.version === to);\n\n const picker = (id: string, text: string, value: number | null, set: (n: number) => void) => (\n <div className={cn(\"flex flex-col gap-1\", mobile && \"flex-1\")}>\n <Label htmlFor={id} className=\"sr-only\">\n {text}\n </Label>\n <Select value={value === null ? undefined : String(value)} onValueChange={(v: string | null) => v && set(Number(v))}>\n <SelectTrigger id={id} className={cn(\"h-8 text-[13px]\", mobile ? \"w-full\" : \"w-40\")}>\n <SelectValue>{value === null ? null : label(value)}</SelectValue>\n </SelectTrigger>\n <SelectContent>\n {versions.map((v) => (\n <SelectItem key={v.version} value={String(v.version)}>\n {label(v.version)}\n </SelectItem>\n ))}\n </SelectContent>\n </Select>\n </div>\n );\n\n const compare = (\n <div className=\"flex flex-wrap items-center gap-2\" role=\"group\" aria-label={`${t(\"compare_from\")}, ${t(\"compare_to\")}`}>\n {picker(\"cms-v-from\", t(\"compare_from\"), from, setFrom)}\n <ArrowRight aria-hidden className=\"h-4 w-4 text-muted-foreground\" />\n {picker(\"cms-v-to\", t(\"compare_to\"), to, setTo)}\n {!mobile ? (\n <Segmented\n label={t(\"view_mode\")}\n value={savedView}\n onChange={setView}\n options={[\n { value: \"split\", label: t(\"side_by_side\") },\n { value: \"unified\", label: t(\"unified\") },\n ]}\n />\n ) : null}\n </div>\n );\n\n const mark = async (b: { label?: string | null; pinned?: boolean }) => {\n if (to === null) return;\n setBusy(true);\n setStatus(null);\n try {\n await client.labelVersion(collection, slug, to, b);\n setNaming(null);\n list.reload();\n } catch (e) {\n setStatus({ text: errorMessage(e, t), tone: \"error\" });\n } finally {\n setBusy(false);\n }\n };\n /** Name and pin for the version on the right side of the compare. */\n const markActions = (size: \"sm\" | \"default\") =>\n canWrite && toInfo ? (\n <>\n <Button type=\"button\" variant=\"ghost\" size={size} className={cn(\"gap-1.5\", size === \"sm\" && \"h-7 px-2 text-xs\")} disabled={busy} onClick={() => setNaming(toInfo.label ?? \"\")}>\n <Tag aria-hidden className=\"h-4 w-4\" />\n {t(\"version_label\")}\n </Button>\n <Button type=\"button\" variant=\"ghost\" size={size} className={cn(\"gap-1.5\", size === \"sm\" && \"h-7 px-2 text-xs\")} disabled={busy} aria-pressed={toInfo.pinned} onClick={() => void mark({ pinned: !toInfo.pinned })}>\n <Pin aria-hidden className=\"h-4 w-4\" />\n {t(toInfo.pinned ? \"version_unpin\" : \"version_pin\")}\n </Button>\n </>\n ) : null;\n const marks = (v: VersionSummary) =>\n v.label || v.pinned || v.approvedBy ? (\n <span className=\"flex flex-wrap items-center gap-x-2 gap-y-0.5 text-xs\">\n {v.label ? (\n <span className=\"inline-flex min-w-0 items-center gap-1 font-medium\">\n <Tag aria-hidden className=\"h-3 w-3 shrink-0\" />\n <span className=\"truncate\">{v.label}</span>\n </span>\n ) : null}\n {v.pinned ? (\n <span className=\"inline-flex items-center gap-1 text-muted-foreground\">\n <Pin aria-hidden className=\"h-3 w-3\" />\n {t(\"version_pinned\")}\n </span>\n ) : null}\n {v.approvedBy ? <span className=\"text-muted-foreground\">{t(\"version_approved\", { who: v.approvedBy })}</span> : null}\n </span>\n ) : null;\n\n const actions = (cls?: string) =>\n from !== null && to !== null ? (\n <>\n {cls ? null : markActions(\"default\")}\n {canWrite && from !== latest ? (\n <Button type=\"button\" variant=\"outline\" className={cn(\"gap-1.5\", cls)} disabled={busy} onClick={() => setConfirm(\"restore\")}>\n <RotateCcw aria-hidden className=\"h-4 w-4\" />\n {t(\"restore_version\", { version: from })}\n </Button>\n ) : null}\n {canPublish && to !== publishedV ? (\n <Button type=\"button\" className={cls} disabled={busy} onClick={() => void run(\"publish\")}>\n {t(\"publish_version\", { version: to })}\n </Button>\n ) : null}\n </>\n ) : null;\n\n const d = diff.data?.d;\n const body = diff.data?.body;\n\n const fieldTable = d && d.fields.length ? (\n <div className=\"overflow-hidden rounded-lg border\">\n <table className=\"w-full text-sm\">\n <thead>\n <tr className=\"border-b text-left text-xs text-muted-foreground\">\n <th className=\"px-3 py-2 font-medium\">{t(\"field\")}</th>\n {!mobile ? <th className=\"px-3 py-2 font-medium\">{label(d.a)}</th> : null}\n <th className=\"px-3 py-2 font-medium\">{mobile ? `${label(d.a)} → v${d.b}` : `v${d.b}`}</th>\n </tr>\n </thead>\n <tbody>\n {d.fields.map((f) => {\n const name = FIELD_LABEL[f.path] ? t(FIELD_LABEL[f.path]) : f.path.replace(/^fields\\./, \"\");\n const a = show(f.from);\n const b = show(f.to);\n return (\n <tr key={f.path} className=\"border-b last:border-b-0 align-top\">\n <td className=\"px-3 py-2 text-xs\">{name}</td>\n {!mobile ? (\n <td className=\"px-3 py-2 font-mono text-xs\">\n <Words a={a} b={b} side=\"a\" />\n </td>\n ) : null}\n <td className=\"px-3 py-2 font-mono text-xs\">\n <Words a={a} b={b} side=\"b\" />\n </td>\n </tr>\n );\n })}\n </tbody>\n </table>\n </div>\n ) : null;\n\n const hunkHead = (h: Hunk) => {\n const head = headingBefore(body, h.bStart + 1);\n return `@@ ${head ?? `-${h.aStart},${h.aLines} +${h.bStart},${h.bLines}`}`;\n };\n\n const lineCls = (k: \"del\" | \"add\" | \"ctx\" | \"pad\") => cn(\"flex min-w-0 gap-2 px-2 font-mono text-xs leading-6\", k === \"del\" && \"bg-red-50\", k === \"add\" && \"bg-green-50\", k === \"pad\" && \"bg-muted/40\");\n const num = (n?: number) => (\n <i aria-hidden className=\"w-8 shrink-0 select-none text-right not-italic text-muted-foreground\">\n {n ?? \"\"}\n </i>\n );\n\n const split = d ? (\n <div className=\"overflow-hidden rounded-lg border\">\n <div className=\"grid grid-cols-2 border-b text-xs font-medium text-muted-foreground\">\n <span className=\"px-3 py-1.5\">{label(d.a)}</span>\n <span className=\"border-l px-3 py-1.5\">v{d.b}</span>\n </div>\n {d.hunks.map((h, hi) => (\n <div key={hi}>\n <div className=\"border-y bg-muted/40 px-3 py-1 font-mono text-xs text-muted-foreground first:border-t-0\">{hunkHead(h)}</div>\n <div className=\"grid grid-cols-2\">\n {rowsOf(h).map((r, i) => (\n <React.Fragment key={i}>\n <div className={lineCls(r.t === \"ctx\" ? \"ctx\" : r.a ? \"del\" : \"pad\")}>\n {num(r.a?.a)}\n <span className=\"min-w-0 whitespace-pre-wrap break-words\">\n {r.t === \"chg\" && r.a ? <span className=\"sr-only\">- </span> : null}\n {r.a ? r.t === \"chg\" && r.b ? <Words a={r.a.v} b={r.b.v} side=\"a\" /> : r.a.v : \"\"}\n </span>\n </div>\n <div className={cn(lineCls(r.t === \"ctx\" ? \"ctx\" : r.b ? \"add\" : \"pad\"), \"border-l\")}>\n {num(r.b?.b)}\n <span className=\"min-w-0 whitespace-pre-wrap break-words\">\n {r.t === \"chg\" && r.b ? <span className=\"sr-only\">+ </span> : null}\n {r.b ? r.t === \"chg\" && r.a ? <Words a={r.a.v} b={r.b.v} side=\"b\" /> : r.b.v : \"\"}\n </span>\n </div>\n </React.Fragment>\n ))}\n </div>\n </div>\n ))}\n </div>\n ) : null;\n\n const unified = d ? (\n <div className={cn(\"overflow-hidden\", mobile ? \"border-t\" : \"rounded-lg border\")}>\n {d.hunks.map((h, hi) => {\n const rows = rowsOf(h);\n const pairs = new Map<HunkLine, string>();\n for (const r of rows) if (r.t === \"chg\" && r.a && r.b) (pairs.set(r.a, r.b.v), pairs.set(r.b, r.a.v));\n return (\n <div key={hi}>\n <div className=\"border-b bg-muted/40 px-3 py-1 font-mono text-xs text-muted-foreground\">{hunkHead(h)}</div>\n {h.lines.map((l, i) => {\n const other = pairs.get(l);\n return (\n <div key={i} className={lineCls(l.t === \"-\" ? \"del\" : l.t === \"+\" ? \"add\" : \"ctx\")}>\n <span aria-hidden className=\"w-3 shrink-0 select-none text-muted-foreground\">\n {l.t === \"-\" ? \"−\" : l.t === \"+\" ? \"+\" : \" \"}\n </span>\n <span className=\"min-w-0 whitespace-pre-wrap break-words\">\n {l.t !== \" \" ? <span className=\"sr-only\">{l.t} </span> : null}\n {other !== undefined ? l.t === \"-\" ? <Words a={l.v} b={other} side=\"a\" /> : <Words a={other} b={l.v} side=\"b\" /> : l.v}\n </span>\n </div>\n );\n })}\n </div>\n );\n })}\n </div>\n ) : null;\n\n const diffArea = (\n <div className=\"flex min-w-0 flex-1 flex-col gap-3\">\n {diff.error ? <StatusText tone=\"error\">{errorMessage(diff.error, t)}</StatusText> : null}\n {d && !d.fields.length && !d.hunks.length ? <p className=\"text-sm text-muted-foreground\">{t(\"no_diff\")}</p> : null}\n {fieldTable}\n {d && d.hunks.length ? (view === \"unified\" ? unified : split) : null}\n </div>\n );\n\n const confirmDialog = (\n <>\n <Dialog open={naming !== null} onOpenChange={(o) => !o && setNaming(null)}>\n <DialogContent className=\"max-w-[400px]\">\n <form\n className=\"grid gap-4\"\n onSubmit={(e) => {\n e.preventDefault();\n void mark({ label: (naming ?? \"\").trim() || null });\n }}\n >\n <DialogHeader>\n <DialogTitle>{t(\"version_label\")}</DialogTitle>\n <DialogDescription>v{to}</DialogDescription>\n </DialogHeader>\n <Input aria-label={t(\"version_label_field\")} placeholder={t(\"version_label_field\")} autoFocus maxLength={80} value={naming ?? \"\"} onChange={(e) => setNaming(e.target.value)} />\n <DialogFooter>\n <Button type=\"button\" variant=\"outline\" onClick={() => setNaming(null)}>\n {t(\"cancel\")}\n </Button>\n <Button type=\"submit\" disabled={busy}>\n {t(\"save\")}\n </Button>\n </DialogFooter>\n </form>\n </DialogContent>\n </Dialog>\n <ConfirmDialog\n open={confirm === \"restore\"}\n onOpenChange={(o) => !o && setConfirm(null)}\n title={t(\"restore_confirm\", { version: from ?? 0 })}\n description={t(\"restore_confirm_note\", { version: from ?? 0 })}\n confirmLabel={t(\"restore_version\", { version: from ?? 0 })}\n busy={busy}\n onConfirm={() => run(\"restore\")}\n />\n </>\n );\n\n const statusLine = (\n <StatusText tone={status?.tone === \"error\" ? \"error\" : \"ok\"} className=\"text-xs\">\n {status?.text ?? (list.loading && !versions.length ? t(\"loading\") : \"\")}\n </StatusText>\n );\n\n if (mobile)\n return (\n <div className={cn(\"flex min-h-0 flex-1 flex-col\", className)}>\n <PageHeader\n title={t(\"versions\")}\n back={\n onBack ? (\n <Button type=\"button\" variant=\"ghost\" size=\"icon\" className=\"-ml-2 h-8 w-8\" aria-label={t(\"versions_back\")} onClick={onBack}>\n <ChevronLeft aria-hidden className=\"h-4 w-4\" />\n </Button>\n ) : undefined\n }\n />\n <div className=\"border-b px-4 py-2.5\">{compare}</div>\n <div className=\"flex-1\">\n {toInfo ? (\n <div className=\"flex flex-col gap-0.5 px-4 py-2.5 text-xs\">\n <div className=\"flex items-center gap-2\">\n <Who kind={toInfo.authorKind} label={toInfo.authorLabel} agent={toInfo.authorAgent} className=\"font-medium\" />\n <span className=\"text-muted-foreground\">{relativeTime(toInfo.createdAt, t, locale)}</span>\n </div>\n {marks(toInfo)}\n {toInfo.note ? <div className=\"text-muted-foreground\">{toInfo.note}</div> : null}\n <div className=\"-ml-2 flex gap-1\">{markActions(\"sm\")}</div>\n </div>\n ) : null}\n <div className=\"px-4 pb-2\">{statusLine}</div>\n {diffArea}\n </div>\n <div className=\"sticky bottom-0 flex gap-2 border-t bg-background p-2\">{actions(\"flex-1\")}</div>\n {confirmDialog}\n </div>\n );\n\n return (\n <div className={cn(\"flex min-h-0 flex-1 flex-col\", className)}>\n <PageHeader title={t(\"versions\")} crumbs={[schema.data?.label ?? collection, slug]}>\n {onBack ? (\n <Button type=\"button\" variant=\"ghost\" className=\"gap-1.5\" onClick={onBack}>\n <ArrowLeft aria-hidden className=\"h-4 w-4\" />\n {t(\"versions_back\")}\n </Button>\n ) : null}\n </PageHeader>\n <div className=\"flex min-h-0 flex-1\">\n <nav aria-label={t(\"versions_list\")} className=\"w-64 shrink-0 overflow-y-auto border-r\">\n <ul>\n {versions.map((v) => {\n const on = v.version === to;\n const cmp = v.version === from && !on;\n return (\n <li key={v.version}>\n <button\n type=\"button\"\n aria-current={on ? \"true\" : undefined}\n onClick={() => pick(v)}\n className={cn(\"flex w-full flex-col gap-1 border-b px-3.5 py-2.5 text-left outline-none hover:bg-muted/50 focus-visible:bg-muted\", on && \"bg-muted\", cmp && \"bg-muted/40\")}\n >\n <span className=\"flex w-full items-center gap-2 text-sm\">\n <b>v{v.version}</b>\n {v.published ? <StateBadge state=\"published\" /> : null}\n <span className=\"flex-1\" />\n <span className=\"text-xs text-muted-foreground\">{relativeTime(v.createdAt, t, locale)}</span>\n </span>\n <span className=\"flex items-center gap-1.5 text-xs\">\n <Who kind={v.authorKind} label={v.authorLabel} agent={v.authorAgent} />\n <Badge variant=\"outline\" className={cn(\"h-4 rounded-full px-1.5 text-[10.5px] font-normal\", (v.authorKind !== \"user\" || v.authorAgent) && \"border-blue-200 bg-blue-50 text-blue-700\")}>\n {v.authorKind === \"user\" && !v.authorAgent ? t(\"kind_user\") : t(\"kind_agent\")}\n </Badge>\n </span>\n {marks(v)}\n {v.note ? <span className=\"text-xs text-muted-foreground\">{v.note}</span> : null}\n {v.changed?.fields.length ? (\n <span className=\"text-[11px] text-muted-foreground\">\n {t(\"changed_fields\", { fields: v.changed.fields.map((f) => (FIELD_LABEL[f] ? t(FIELD_LABEL[f]) : f.replace(/^fields\\./, \"\"))).join(\", \") })}\n </span>\n ) : null}\n </button>\n </li>\n );\n })}\n </ul>\n </nav>\n <div className=\"flex min-w-0 flex-1 flex-col gap-3 overflow-y-auto px-6 py-4\">\n <div className=\"flex flex-wrap items-center gap-2\">\n {compare}\n <span className=\"flex-1\" />\n {actions()}\n </div>\n {statusLine}\n {diffArea}\n </div>\n </div>\n {confirmDialog}\n </div>\n );\n}\n"
24
25
  }
25
26
  ]
26
27
  }
@@ -36,7 +36,7 @@
36
36
  "name": "cms-shell",
37
37
  "type": "registry:component",
38
38
  "title": "Admin layout",
39
- "description": "Sidebar with collections, API keys and audit log, plus extraNav for your app's own screens. A sheet menu under 768px.",
39
+ "description": "Sidebar with collections, API keys and audit log, plus extraNav for your app's own screens. A sheet menu under 768px. Shows \"Media\" when the app has a media library.",
40
40
  "dependencies": [
41
41
  "@mainsoft/agent-cms",
42
42
  "lucide-react"
@@ -87,6 +87,7 @@
87
87
  "dialog",
88
88
  "dropdown-menu",
89
89
  "input",
90
+ "label",
90
91
  "select",
91
92
  "table",
92
93
  "cms-lib",
@@ -123,11 +124,37 @@
123
124
  }
124
125
  ]
125
126
  },
127
+ {
128
+ "name": "cms-media-picker",
129
+ "type": "registry:component",
130
+ "title": "Media picker",
131
+ "description": "The dialog that chooses a file from the media library (search, type tabs, folders, upload), the upload logic (straight to the storage, parts for large files, retry of what is missing, browser-made thumbnails) and the tiles and upload panel shared with the media library.",
132
+ "dependencies": [
133
+ "@mainsoft/agent-cms",
134
+ "lucide-react"
135
+ ],
136
+ "registryDependencies": [
137
+ "button",
138
+ "dialog",
139
+ "input",
140
+ "cms-lib"
141
+ ],
142
+ "files": [
143
+ {
144
+ "path": "registry/cms/cms-upload.ts",
145
+ "type": "registry:lib"
146
+ },
147
+ {
148
+ "path": "registry/cms/cms-media-picker.tsx",
149
+ "type": "registry:component"
150
+ }
151
+ ]
152
+ },
126
153
  {
127
154
  "name": "cms-doc-editor",
128
155
  "type": "registry:component",
129
156
  "title": "Document editor",
130
- "description": "Info form generated from the collection schema, markdown with live preview, autosave and restore, problems on the fields, agent change review (accept, revert), save, publish, preview links.",
157
+ "description": "Info form generated from the collection schema, markdown with live preview, autosave and restore, problems on the fields, agent change review (accept, revert), save, publish, preview links. Image and file fields and \"Insert media\" open the media picker when the app has a media library.",
131
158
  "dependencies": [
132
159
  "@mainsoft/agent-cms",
133
160
  "lucide-react"
@@ -143,7 +170,8 @@
143
170
  "tabs",
144
171
  "textarea",
145
172
  "cms-lib",
146
- "cms-merge"
173
+ "cms-merge",
174
+ "cms-media-picker"
147
175
  ],
148
176
  "files": [
149
177
  {
@@ -153,6 +181,137 @@
153
181
  {
154
182
  "path": "registry/cms/cms-field-form.tsx",
155
183
  "type": "registry:component"
184
+ },
185
+ {
186
+ "path": "registry/cms/cms-flow.tsx",
187
+ "type": "registry:component"
188
+ },
189
+ {
190
+ "path": "registry/cms/cms-paste.ts",
191
+ "type": "registry:lib"
192
+ }
193
+ ]
194
+ },
195
+ {
196
+ "name": "cms-media",
197
+ "type": "registry:component",
198
+ "title": "Media library",
199
+ "description": "Stores and folders, files as a grid or a list, search and type tabs, a panel with one file's alt text, tags and the documents that use it, uploads with progress, and delete with a look at where the file is used. Needs `createCms({ media })`.",
200
+ "dependencies": [
201
+ "@mainsoft/agent-cms",
202
+ "lucide-react"
203
+ ],
204
+ "registryDependencies": [
205
+ "button",
206
+ "dialog",
207
+ "input",
208
+ "label",
209
+ "table",
210
+ "textarea",
211
+ "cms-lib",
212
+ "cms-media-picker"
213
+ ],
214
+ "files": [
215
+ {
216
+ "path": "registry/cms/cms-media.tsx",
217
+ "type": "registry:component"
218
+ }
219
+ ]
220
+ },
221
+ {
222
+ "name": "cms-files",
223
+ "type": "registry:component",
224
+ "title": "File manager",
225
+ "description": "A storage bucket as it is, folder by folder, also files nobody uploaded through the CMS: move, download, share links and delete for several files at once. Needs `createCms({ media })`.",
226
+ "dependencies": [
227
+ "@mainsoft/agent-cms",
228
+ "lucide-react"
229
+ ],
230
+ "registryDependencies": [
231
+ "button",
232
+ "checkbox",
233
+ "dialog",
234
+ "input",
235
+ "label",
236
+ "table",
237
+ "cms-lib",
238
+ "cms-media-picker",
239
+ "cms-media"
240
+ ],
241
+ "files": [
242
+ {
243
+ "path": "registry/cms/cms-files.tsx",
244
+ "type": "registry:component"
245
+ }
246
+ ]
247
+ },
248
+ {
249
+ "name": "cms-trash",
250
+ "type": "registry:component",
251
+ "title": "Trash",
252
+ "description": "Deleted documents and files: restore them, or delete them forever (admins). Shown when `createCms({ trash })` keeps deleted things, which is the default (30 days).",
253
+ "dependencies": [
254
+ "@mainsoft/agent-cms",
255
+ "lucide-react"
256
+ ],
257
+ "registryDependencies": [
258
+ "button",
259
+ "checkbox",
260
+ "table",
261
+ "cms-lib"
262
+ ],
263
+ "files": [
264
+ {
265
+ "path": "registry/cms/cms-trash.tsx",
266
+ "type": "registry:component"
267
+ }
268
+ ]
269
+ },
270
+ {
271
+ "name": "cms-releases",
272
+ "type": "registry:component",
273
+ "title": "Releases",
274
+ "description": "Documents that are published (or unpublished) together: the list of releases and one release with its documents, the version of each, what blocks it, publish now or at a set time.",
275
+ "dependencies": [
276
+ "@mainsoft/agent-cms",
277
+ "lucide-react"
278
+ ],
279
+ "registryDependencies": [
280
+ "button",
281
+ "checkbox",
282
+ "dialog",
283
+ "dropdown-menu",
284
+ "input",
285
+ "label",
286
+ "table",
287
+ "cms-lib"
288
+ ],
289
+ "files": [
290
+ {
291
+ "path": "registry/cms/cms-releases.tsx",
292
+ "type": "registry:component"
293
+ }
294
+ ]
295
+ },
296
+ {
297
+ "name": "cms-preview-comments",
298
+ "type": "registry:component",
299
+ "title": "Preview comments",
300
+ "description": "For your public page when it shows a draft through a preview link made with \"Allow comments\": the comments on the draft and a box for someone without an account to add one. Needs no provider.",
301
+ "dependencies": [
302
+ "@mainsoft/agent-cms"
303
+ ],
304
+ "registryDependencies": [
305
+ "button",
306
+ "input",
307
+ "label",
308
+ "textarea",
309
+ "cms-lib"
310
+ ],
311
+ "files": [
312
+ {
313
+ "path": "registry/cms/cms-preview-comments.tsx",
314
+ "type": "registry:component"
156
315
  }
157
316
  ]
158
317
  },
@@ -169,6 +328,7 @@
169
328
  "badge",
170
329
  "button",
171
330
  "dialog",
331
+ "input",
172
332
  "label",
173
333
  "select",
174
334
  "cms-lib"