@kidecms/core 0.1.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 (93) hide show
  1. package/README.md +28 -0
  2. package/admin/components/AdminCard.astro +25 -0
  3. package/admin/components/AiGenerateButton.tsx +102 -0
  4. package/admin/components/AssetsGrid.tsx +711 -0
  5. package/admin/components/BlockEditor.tsx +996 -0
  6. package/admin/components/CheckboxField.tsx +31 -0
  7. package/admin/components/DocumentActions.tsx +317 -0
  8. package/admin/components/DocumentLock.tsx +54 -0
  9. package/admin/components/DocumentsDataTable.tsx +804 -0
  10. package/admin/components/FieldControl.astro +397 -0
  11. package/admin/components/FocalPointSelector.tsx +100 -0
  12. package/admin/components/ImageBrowseDialog.tsx +176 -0
  13. package/admin/components/ImagePicker.tsx +149 -0
  14. package/admin/components/InternalLinkPicker.tsx +80 -0
  15. package/admin/components/LiveHeading.tsx +17 -0
  16. package/admin/components/MobileSidebar.tsx +29 -0
  17. package/admin/components/RelationField.tsx +204 -0
  18. package/admin/components/RichTextEditor.tsx +685 -0
  19. package/admin/components/SelectField.tsx +65 -0
  20. package/admin/components/SidebarUserMenu.tsx +99 -0
  21. package/admin/components/SlugField.tsx +77 -0
  22. package/admin/components/TaxonomySelect.tsx +52 -0
  23. package/admin/components/Toast.astro +40 -0
  24. package/admin/components/TreeItemsEditor.tsx +790 -0
  25. package/admin/components/TreeSelect.tsx +166 -0
  26. package/admin/components/UnsavedGuard.tsx +181 -0
  27. package/admin/components/tree-utils.ts +86 -0
  28. package/admin/components/ui/alert-dialog.tsx +92 -0
  29. package/admin/components/ui/badge.tsx +83 -0
  30. package/admin/components/ui/button.tsx +53 -0
  31. package/admin/components/ui/card.tsx +70 -0
  32. package/admin/components/ui/checkbox.tsx +28 -0
  33. package/admin/components/ui/collapsible.tsx +26 -0
  34. package/admin/components/ui/command.tsx +88 -0
  35. package/admin/components/ui/dialog.tsx +92 -0
  36. package/admin/components/ui/dropdown-menu.tsx +259 -0
  37. package/admin/components/ui/input.tsx +20 -0
  38. package/admin/components/ui/label.tsx +20 -0
  39. package/admin/components/ui/popover.tsx +42 -0
  40. package/admin/components/ui/select.tsx +165 -0
  41. package/admin/components/ui/separator.tsx +21 -0
  42. package/admin/components/ui/sheet.tsx +104 -0
  43. package/admin/components/ui/skeleton.tsx +7 -0
  44. package/admin/components/ui/table.tsx +74 -0
  45. package/admin/components/ui/textarea.tsx +18 -0
  46. package/admin/components/ui/tooltip.tsx +52 -0
  47. package/admin/layouts/AdminLayout.astro +340 -0
  48. package/admin/lib/utils.ts +19 -0
  49. package/dist/admin.js +92 -0
  50. package/dist/ai.js +67 -0
  51. package/dist/api.js +827 -0
  52. package/dist/assets.js +163 -0
  53. package/dist/auth.js +132 -0
  54. package/dist/blocks.js +110 -0
  55. package/dist/content.js +29 -0
  56. package/dist/create-admin.js +23 -0
  57. package/dist/define.js +36 -0
  58. package/dist/generator.js +370 -0
  59. package/dist/image.js +69 -0
  60. package/dist/index.js +16 -0
  61. package/dist/integration.js +256 -0
  62. package/dist/locks.js +37 -0
  63. package/dist/richtext.js +1 -0
  64. package/dist/runtime.js +26 -0
  65. package/dist/schema.js +13 -0
  66. package/dist/seed.js +84 -0
  67. package/dist/values.js +102 -0
  68. package/middleware/auth.ts +100 -0
  69. package/package.json +102 -0
  70. package/routes/api/cms/[collection]/[...path].ts +366 -0
  71. package/routes/api/cms/ai/alt-text.ts +25 -0
  72. package/routes/api/cms/ai/seo.ts +25 -0
  73. package/routes/api/cms/ai/translate.ts +31 -0
  74. package/routes/api/cms/assets/[id].ts +82 -0
  75. package/routes/api/cms/assets/folders.ts +81 -0
  76. package/routes/api/cms/assets/index.ts +23 -0
  77. package/routes/api/cms/assets/upload.ts +112 -0
  78. package/routes/api/cms/auth/invite.ts +166 -0
  79. package/routes/api/cms/auth/login.ts +124 -0
  80. package/routes/api/cms/auth/logout.ts +33 -0
  81. package/routes/api/cms/auth/setup.ts +77 -0
  82. package/routes/api/cms/cron/publish.ts +33 -0
  83. package/routes/api/cms/img/[...path].ts +24 -0
  84. package/routes/api/cms/locks/[...path].ts +37 -0
  85. package/routes/api/cms/preview/render.ts +36 -0
  86. package/routes/api/cms/references/[collection]/[id].ts +60 -0
  87. package/routes/pages/admin/[...path].astro +1104 -0
  88. package/routes/pages/admin/assets/[id].astro +183 -0
  89. package/routes/pages/admin/assets/index.astro +58 -0
  90. package/routes/pages/admin/invite.astro +116 -0
  91. package/routes/pages/admin/login.astro +57 -0
  92. package/routes/pages/admin/setup.astro +91 -0
  93. package/virtual.d.ts +61 -0
@@ -0,0 +1,37 @@
1
+ import type { APIRoute } from "astro";
2
+
3
+ import { acquireLock, releaseLock } from "virtual:kide/runtime";
4
+
5
+ export const prerender = false;
6
+
7
+ const getSegments = (path: string | undefined) => (path ?? "").split("/").filter(Boolean);
8
+
9
+ // POST /api/cms/locks/:collection/:documentId — acquire/heartbeat or release (via ?_method=DELETE for sendBeacon)
10
+ export const POST: APIRoute = async ({ params, locals, url }) => {
11
+ const [collection, documentId] = getSegments(params.path);
12
+ const user = locals.user;
13
+
14
+ if (!collection || !documentId || !user) {
15
+ return Response.json({ error: "Missing parameters" }, { status: 400 });
16
+ }
17
+
18
+ if (url.searchParams.get("_method") === "DELETE") {
19
+ await releaseLock(collection, documentId, user.id);
20
+ return new Response(null, { status: 204 });
21
+ }
22
+
23
+ return Response.json(await acquireLock(collection, documentId, user.id, user.email));
24
+ };
25
+
26
+ // DELETE /api/cms/locks/:collection/:documentId — release lock
27
+ export const DELETE: APIRoute = async ({ params, locals }) => {
28
+ const [collection, documentId] = getSegments(params.path);
29
+ const user = locals.user;
30
+
31
+ if (!collection || !documentId || !user) {
32
+ return new Response(null, { status: 400 });
33
+ }
34
+
35
+ await releaseLock(collection, documentId, user.id);
36
+ return new Response(null, { status: 204 });
37
+ };
@@ -0,0 +1,36 @@
1
+ import type { APIRoute } from "astro";
2
+ import { experimental_AstroContainer as AstroContainer } from "astro/container";
3
+ import { loadRenderers } from "astro:container";
4
+ import { getContainerRenderer } from "@astrojs/react";
5
+
6
+ import BlockRenderer from "virtual:kide/block-renderer";
7
+ import { renderRichText, parseBlocks } from "@kidecms/core";
8
+
9
+ export const prerender = false;
10
+
11
+ let containerPromise: Promise<AstroContainer> | null = null;
12
+ const getContainer = () => {
13
+ if (!containerPromise) {
14
+ containerPromise = (async () => {
15
+ const renderers = await loadRenderers([getContainerRenderer()]);
16
+ return AstroContainer.create({ renderers });
17
+ })();
18
+ }
19
+ return containerPromise;
20
+ };
21
+
22
+ export const POST: APIRoute = async ({ request }) => {
23
+ const { type, data } = await request.json();
24
+
25
+ let html = "";
26
+ if (type === "blocks") {
27
+ const blocks = parseBlocks(data);
28
+ const container = await getContainer();
29
+ html = await container.renderToString(BlockRenderer, { props: { blocks } });
30
+ } else if (type === "richText") {
31
+ const parsed = typeof data === "string" ? JSON.parse(data) : data;
32
+ html = renderRichText(parsed) ?? "";
33
+ }
34
+
35
+ return new Response(html, { headers: { "Content-Type": "text/html" } });
36
+ };
@@ -0,0 +1,60 @@
1
+ import type { APIRoute } from "astro";
2
+ import config from "virtual:kide/config";
3
+ import { cms } from "virtual:kide/api";
4
+ import { getLabelField } from "@kidecms/core";
5
+
6
+ export const prerender = false;
7
+
8
+ const cmsRuntime = cms as Record<string, any>;
9
+
10
+ export const GET: APIRoute = async ({ params }) => {
11
+ const { collection: collectionSlug, id: documentId } = params;
12
+ if (!collectionSlug || !documentId) {
13
+ return Response.json({ refs: [] });
14
+ }
15
+
16
+ const collection = config.collections.find((c) => c.slug === collectionSlug);
17
+ if (!collection) return Response.json({ refs: [] });
18
+
19
+ const refs: Array<{ collection: string; label: string; count: number }> = [];
20
+
21
+ for (const otherCollection of config.collections) {
22
+ if (otherCollection.slug === collectionSlug) continue;
23
+ const relationFields = Object.entries(otherCollection.fields).filter(
24
+ ([, f]) => f.type === "relation" && (f as any).collection === collectionSlug,
25
+ );
26
+ if (relationFields.length === 0) continue;
27
+
28
+ const otherApi = cmsRuntime[otherCollection.slug];
29
+ if (!otherApi) continue;
30
+
31
+ for (const [fieldName, field] of relationFields) {
32
+ try {
33
+ const isMany = (field as any).hasMany;
34
+ let count = 0;
35
+
36
+ if (isMany) {
37
+ const allDocs = await otherApi.find({ status: "any", limit: 200 });
38
+ count = allDocs.filter((r: Record<string, unknown>) => {
39
+ const val = r[fieldName];
40
+ if (Array.isArray(val)) return val.includes(documentId);
41
+ if (typeof val === "string") return val.includes(documentId);
42
+ return false;
43
+ }).length;
44
+ } else {
45
+ count = await otherApi.count({ status: "any", where: { [fieldName]: documentId } });
46
+ }
47
+
48
+ if (count > 0) {
49
+ refs.push({
50
+ collection: otherCollection.labels.plural,
51
+ label: getLabelField(otherCollection),
52
+ count,
53
+ });
54
+ }
55
+ } catch {}
56
+ }
57
+ }
58
+
59
+ return Response.json({ refs, total: refs.reduce((sum, r) => sum + r.count, 0) });
60
+ };