@kidecms/core 0.17.1 → 0.18.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,10 +1,10 @@
1
1
  "use client";
2
2
 
3
3
  import { useState, useCallback, useRef, useMemo, useEffect } from "react";
4
- import type { CSSProperties } from "react";
5
4
  import {
6
5
  ChevronLeft,
7
6
  ChevronRight,
7
+ CircleCheck,
8
8
  Folder,
9
9
  FolderPlus,
10
10
  GripVertical,
@@ -30,7 +30,7 @@ import {
30
30
  type DragStartEvent,
31
31
  type DragEndEvent,
32
32
  } from "@dnd-kit/core";
33
- import { cn, thumbnail } from "../lib/utils";
33
+ import { cn, focalPointStyle, thumbnail } from "../lib/utils";
34
34
  import { Badge } from "./ui/badge";
35
35
  import { Button, buttonVariants } from "./ui/button";
36
36
  import { Card, CardContent } from "./ui/card";
@@ -82,13 +82,6 @@ type Props = {
82
82
  pageSize: number;
83
83
  };
84
84
 
85
- // object-cover crops around the CSS center by default — steer it to the asset's
86
- // focal point instead, when one is set.
87
- function focalPointStyle(asset: Pick<AssetItem, "focalX" | "focalY">): CSSProperties | undefined {
88
- if (asset.focalX == null || asset.focalY == null) return undefined;
89
- return { objectPosition: `${asset.focalX}% ${asset.focalY}%` };
90
- }
91
-
92
85
  // Build a "/admin/assets" URL for a sidebar scope ("all" | "unfiled" | folderId).
93
86
  // "all" is the bare route; "unfiled" and folder ids ride on the `folder` param.
94
87
  function assetsUrl(opts: { scope?: string; q?: string; page?: number }) {
@@ -802,7 +795,20 @@ export default function AssetsGrid({
802
795
  </div>
803
796
  )}
804
797
  {uploadError && <p className="text-destructive text-sm">{uploadError}</p>}
805
- {uploadNotice && <p className="text-muted-foreground text-sm">{uploadNotice}</p>}
798
+
799
+ {/* Same look and timing as the server-rendered Toast.astro */}
800
+ {uploadNotice && (
801
+ <div className="fixed top-4 left-1/2 z-[60] w-full max-w-sm -translate-x-1/2">
802
+ <div
803
+ role="status"
804
+ className="bg-card flex items-center gap-2 rounded-lg border border-green-500/30 px-5 py-3 text-sm shadow-lg"
805
+ style={{ animation: "toast-in 0.25s ease-out, toast-out 0.3s ease-in 2.7s forwards" }}
806
+ >
807
+ <CircleCheck className="size-4 shrink-0 text-green-600 dark:text-green-400" />
808
+ <span className="text-green-700 dark:text-green-400">{uploadNotice}</span>
809
+ </div>
810
+ </div>
811
+ )}
806
812
 
807
813
  {/* Selection toolbar */}
808
814
  {selectedIds.size > 0 && (
@@ -1,13 +1,15 @@
1
1
  import { useState, useCallback, useEffect } from "react";
2
2
  import { ChevronRight, Folder, Loader2, X } from "lucide-react";
3
3
  import { Dialog, DialogClose, DialogContent, DialogHeader, DialogTitle } from "./ui/dialog";
4
- import { thumbnail } from "../lib/utils";
4
+ import { focalPointStyle, thumbnail } from "../lib/utils";
5
5
 
6
6
  type AssetRecord = {
7
7
  _id: string;
8
8
  filename: string;
9
9
  mimeType: string;
10
10
  url: string;
11
+ focalX?: number | null;
12
+ focalY?: number | null;
11
13
  _createdAt: string;
12
14
  };
13
15
 
@@ -156,7 +158,12 @@ export default function ImageBrowseDialog({ open, onOpenChange, onSelect }: Prop
156
158
  }}
157
159
  className="hover:border-foreground relative aspect-square overflow-hidden rounded-lg border transition-colors"
158
160
  >
159
- <img src={thumbnail(asset.url)} alt={asset.filename} className="size-full object-cover" />
161
+ <img
162
+ src={thumbnail(asset.url)}
163
+ alt={asset.filename}
164
+ className="size-full object-cover"
165
+ style={focalPointStyle(asset)}
166
+ />
160
167
  </button>
161
168
  ))}
162
169
  </div>
@@ -1,6 +1,6 @@
1
1
  import { useState, useRef, useCallback, useEffect } from "react";
2
2
  import { ImagePlus, Loader2, Upload, X } from "lucide-react";
3
- import { cn, thumbnail } from "../lib/utils";
3
+ import { cn, focalPointStyle, thumbnail } from "../lib/utils";
4
4
  import { Button } from "./ui/button";
5
5
  import ImageBrowseDialog from "./ImageBrowseDialog";
6
6
 
@@ -14,6 +14,7 @@ type Props = {
14
14
  export default function ImagePicker({ name, value: initialValue, onChange: onChangeProp }: Props) {
15
15
  const [value, setValue] = useState(initialValue ?? "");
16
16
  const [assetId, setAssetId] = useState<string | null>(null);
17
+ const [focal, setFocal] = useState<{ focalX: number | null; focalY: number | null } | null>(null);
17
18
  const [localPreview, setLocalPreview] = useState<string | null>(null);
18
19
  const [uploading, setUploading] = useState(false);
19
20
  const [open, setOpen] = useState(false);
@@ -26,7 +27,10 @@ export default function ImagePicker({ name, value: initialValue, onChange: onCha
26
27
  fetch(`/api/cms/assets?url=${encodeURIComponent(value)}`)
27
28
  .then((res) => (res.ok ? res.json() : null))
28
29
  .then((asset) => {
29
- if (asset?._id) setAssetId(asset._id);
30
+ if (asset?._id) {
31
+ setAssetId(asset._id);
32
+ setFocal({ focalX: asset.focalX ?? null, focalY: asset.focalY ?? null });
33
+ }
30
34
  })
31
35
  .catch(() => {});
32
36
  }, []); // eslint-disable-line react-hooks/exhaustive-deps
@@ -53,6 +57,7 @@ export default function ImagePicker({ name, value: initialValue, onChange: onCha
53
57
  const asset = await res.json();
54
58
  setValue(asset.url);
55
59
  setAssetId(asset._id);
60
+ setFocal({ focalX: asset.focalX ?? null, focalY: asset.focalY ?? null });
56
61
  onChangeProp?.(asset.url);
57
62
  } catch (e) {
58
63
  console.error("Upload failed:", e);
@@ -91,7 +96,12 @@ export default function ImagePicker({ name, value: initialValue, onChange: onCha
91
96
  assetId && "hover:border-foreground/50 cursor-pointer",
92
97
  )}
93
98
  >
94
- <img src={imgSrc} alt="" className="size-full object-cover" />
99
+ <img
100
+ src={imgSrc}
101
+ alt=""
102
+ className="size-full object-cover"
103
+ style={localPreview ? undefined : focal ? focalPointStyle(focal) : undefined}
104
+ />
95
105
  </a>
96
106
  ) : (
97
107
  <div className="bg-field flex size-40 items-center justify-center rounded-lg border">
@@ -141,6 +151,7 @@ export default function ImagePicker({ name, value: initialValue, onChange: onCha
141
151
  setLocalPreview(null);
142
152
  setValue(asset.url);
143
153
  setAssetId(asset._id);
154
+ setFocal({ focalX: asset.focalX ?? null, focalY: asset.focalY ?? null });
144
155
  onChangeProp?.(asset.url);
145
156
  }}
146
157
  />
@@ -17,10 +17,14 @@ export default function InternalLinkPicker({
17
17
  editHref,
18
18
  linkOptions,
19
19
  onSelect,
20
+ className,
21
+ triggerClassName,
20
22
  }: {
21
23
  editHref: string;
22
24
  linkOptions: LinkOptionGroup[];
23
25
  onSelect: (item: { id: string; label: string; href: string }) => void;
26
+ className?: string;
27
+ triggerClassName?: string;
24
28
  }) {
25
29
  const [open, setOpen] = React.useState(false);
26
30
 
@@ -34,15 +38,14 @@ export default function InternalLinkPicker({
34
38
  }, [editHref, linkOptions]);
35
39
 
36
40
  return (
37
- <div className="min-w-0 flex-3">
41
+ <div className={cn("min-w-0 flex-1", className)}>
38
42
  <Popover open={open} onOpenChange={setOpen}>
39
43
  <PopoverTrigger asChild>
40
44
  <Button
41
45
  variant="input"
42
46
  role="combobox"
43
47
  aria-expanded={open}
44
- size="sm"
45
- className="bg-background w-full justify-between text-sm font-normal"
48
+ className={cn("h-9 w-full min-w-0 justify-between rounded-lg px-3 text-sm font-normal", triggerClassName)}
46
49
  >
47
50
  <span className={cn("truncate", !selectedLabel && "text-muted-foreground")}>
48
51
  {selectedLabel || "Search documents..."}
@@ -8,10 +8,12 @@ import { Select, SelectContent, SelectGroup, SelectItem, SelectTrigger, SelectVa
8
8
  import InternalLinkPicker, { type LinkOptionGroup } from "./InternalLinkPicker";
9
9
 
10
10
  // A structured link control: URL + label + open-in-new-tab, stored as
11
- // { type, url, label, newTab }. A leading "/" is treated as an internal link.
12
- // When linkOptions are provided, internal links are chosen with a document
11
+ // { type, url, label, title, newTab }. A leading "/" is treated as an internal
12
+ // link. When linkOptions are provided, internal links are chosen with a document
13
13
  // picker instead of a hand-typed path (which silently breaks on slug edits).
14
- type LinkValue = { type?: string; url?: string; label?: string; newTab?: boolean };
14
+ // `title` is the picked document's title — renderers use it as the link text
15
+ // when `label` is left empty.
16
+ type LinkValue = { type?: string; url?: string; label?: string; title?: string; newTab?: boolean };
15
17
 
16
18
  type Props = {
17
19
  name?: string;
@@ -64,53 +66,59 @@ export default function LinkField({ name, value: initial, onChange, linkOptions
64
66
  return (
65
67
  <div className="space-y-2 rounded-md border p-3">
66
68
  {name && <input type="hidden" name={name} value={value.url ? JSON.stringify(value) : ""} ref={hiddenRef} />}
67
- <div className="grid gap-1">
68
- <Label className="text-xs">{hasPicker ? "Link" : "URL"}</Label>
69
- {hasPicker ? (
70
- <div className="flex items-center gap-2">
71
- <Select
72
- items={[
73
- { value: "internal", label: "Internal" },
74
- { value: "external", label: "External" },
75
- ]}
76
- value={linkType}
77
- onValueChange={(v) => setLinkType((v as "internal" | "external") ?? "internal")}
78
- >
79
- <SelectTrigger className="w-28 shrink-0 text-sm">
80
- <SelectValue />
81
- </SelectTrigger>
82
- <SelectContent>
83
- <SelectGroup>
84
- <SelectItem value="internal">Internal</SelectItem>
85
- <SelectItem value="external">External</SelectItem>
86
- </SelectGroup>
87
- </SelectContent>
88
- </Select>
89
- {linkType === "internal" ? (
90
- <InternalLinkPicker
91
- editHref={value.url ?? ""}
92
- linkOptions={linkOptions}
93
- onSelect={(item) => set({ url: item.href, ...(value.label ? {} : { label: item.label }) })}
94
- />
95
- ) : (
96
- <Input
97
- value={value.url ?? ""}
98
- placeholder="https://example.com"
99
- onChange={(e) => set({ url: e.target.value })}
100
- />
101
- )}
102
- </div>
103
- ) : (
69
+ <div className="grid gap-2 sm:grid-cols-[minmax(0,3fr)_minmax(0,2fr)]">
70
+ <div className="grid gap-1">
71
+ <Label className="text-xs">{hasPicker ? "Link" : "URL"}</Label>
72
+ {hasPicker ? (
73
+ <div className="flex min-w-0 items-center gap-2">
74
+ <Select
75
+ items={[
76
+ { value: "internal", label: "Internal" },
77
+ { value: "external", label: "External" },
78
+ ]}
79
+ value={linkType}
80
+ onValueChange={(v) => setLinkType((v as "internal" | "external") ?? "internal")}
81
+ >
82
+ <SelectTrigger className="w-28 shrink-0 text-sm">
83
+ <SelectValue />
84
+ </SelectTrigger>
85
+ <SelectContent>
86
+ <SelectGroup>
87
+ <SelectItem value="internal">Internal</SelectItem>
88
+ <SelectItem value="external">External</SelectItem>
89
+ </SelectGroup>
90
+ </SelectContent>
91
+ </Select>
92
+ {linkType === "internal" ? (
93
+ <InternalLinkPicker
94
+ editHref={value.url ?? ""}
95
+ linkOptions={linkOptions}
96
+ onSelect={(item) => set({ url: item.href, title: item.label })}
97
+ />
98
+ ) : (
99
+ <Input
100
+ value={value.url ?? ""}
101
+ placeholder="https://example.com"
102
+ onChange={(e) => set({ url: e.target.value, title: undefined })}
103
+ />
104
+ )}
105
+ </div>
106
+ ) : (
107
+ <Input
108
+ value={value.url ?? ""}
109
+ placeholder="https://example.com or /about"
110
+ onChange={(e) => set({ url: e.target.value, title: undefined })}
111
+ />
112
+ )}
113
+ </div>
114
+ <div className="grid gap-1">
115
+ <Label className="text-xs">Label</Label>
104
116
  <Input
105
- value={value.url ?? ""}
106
- placeholder="https://example.com or /about"
107
- onChange={(e) => set({ url: e.target.value })}
117
+ value={value.label ?? ""}
118
+ placeholder={value.title || "Link text"}
119
+ onChange={(e) => set({ label: e.target.value })}
108
120
  />
109
- )}
110
- </div>
111
- <div className="grid gap-1">
112
- <Label className="text-xs">Label</Label>
113
- <Input value={value.label ?? ""} placeholder="Link text" onChange={(e) => set({ label: e.target.value })} />
121
+ </div>
114
122
  </div>
115
123
  <label className="text-muted-foreground group inline-flex cursor-pointer items-center gap-2 text-sm">
116
124
  <Checkbox
@@ -119,7 +127,6 @@ export default function LinkField({ name, value: initial, onChange, linkOptions
119
127
  onCheckedChange={(checked) => set({ newTab: Boolean(checked) })}
120
128
  />
121
129
  Open in new tab
122
- {value.url && <span className="ml-auto text-xs">({value.type})</span>}
123
130
  </label>
124
131
  </div>
125
132
  );
@@ -471,6 +471,8 @@ export default function TreeItemsEditor({ name, value, variant, label, linkOptio
471
471
  <InternalLinkPicker
472
472
  editHref={editing.href}
473
473
  linkOptions={linkOptions}
474
+ className="flex-3"
475
+ triggerClassName="bg-background h-7 rounded-md"
474
476
  onSelect={(item) => {
475
477
  updateEditing({ href: item.href, ...(!editing.label ? { label: item.label } : {}) });
476
478
  }}
@@ -17,3 +17,15 @@ export function thumbnail(src: string, width: number = 480): string {
17
17
  const w = clampWidth(width);
18
18
  return `/api/cms/img${src}?w=${w}`;
19
19
  }
20
+
21
+ /**
22
+ * `object-position` style for an `object-cover` thumbnail, so the visible crop
23
+ * follows the asset's focal point instead of centering, when one is set.
24
+ */
25
+ export function focalPointStyle(asset: {
26
+ focalX?: number | null;
27
+ focalY?: number | null;
28
+ }): { objectPosition: string } | undefined {
29
+ if (asset.focalX == null || asset.focalY == null) return undefined;
30
+ return { objectPosition: `${asset.focalX}% ${asset.focalY}%` };
31
+ }
@@ -1,5 +1,5 @@
1
1
  ---
2
- import { ArrowLeft, ArrowUpRight, Dot, Lock } from "lucide-react";
2
+ import { Archive, ArrowLeft, ArrowUpRight, Dot, Lock } from "lucide-react";
3
3
 
4
4
  import AdminCard from "../components/AdminCard.astro";
5
5
  import AiGenerateButton from "../components/AiGenerateButton";
@@ -122,6 +122,12 @@ const formTab = "edit" as "edit" | "submissions";
122
122
 
123
123
  // --- Form-submissions-specific: custom read-only view ---
124
124
  const isSubmissionView = collection.slug === "form-submissions" && mode === "edit";
125
+ // Opening a new submission marks it read, like email. System write: the
126
+ // read-only `data` field's access rule must not block the status flip.
127
+ if (isSubmissionView && doc && documentId && doc.status === "new") {
128
+ await collectionApi.update(documentId, { status: "read" }, { _system: true });
129
+ doc.status = "read";
130
+ }
125
131
  const parentFormTitle =
126
132
  isSubmissionView && doc?.form ? await loadParentFormTitle(String(doc.form), cmsRuntime, runtimeContext) : null;
127
133
  const submissionData = (isSubmissionView && doc?.data ? doc.data : {}) as Record<string, unknown>;
@@ -284,6 +290,16 @@ const publishBlocked =
284
290
  >
285
291
  Save translation
286
292
  </button>
293
+ ) : isSubmissionView && documentId ? (
294
+ <form method="post" action={getFormAction(collection.slug, documentId)}>
295
+ <input type="hidden" name="_action" value="update" />
296
+ <input type="hidden" name="status" value={doc?.status === "archived" ? "read" : "archived"} />
297
+ <input type="hidden" name="redirectTo" value={`/admin/${collection.slug}`} />
298
+ <button class={buttonVariants({ variant: "outline" })} type="submit">
299
+ <Archive className="size-3.5" />
300
+ {doc?.status === "archived" ? "Unarchive" : "Archive"}
301
+ </button>
302
+ </form>
287
303
  ) : (
288
304
  <>
289
305
  <button
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kidecms/core",
3
- "version": "0.17.1",
3
+ "version": "0.18.1",
4
4
  "description": "Kide CMS runtime — core library, admin UI, routes, and middleware for Astro. Shipped as TypeScript source.",
5
5
  "keywords": [
6
6
  "cms",