@kidecms/core 0.18.0 → 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,14 +38,14 @@ export default function InternalLinkPicker({
34
38
  }, [editHref, linkOptions]);
35
39
 
36
40
  return (
37
- <div className="min-w-0 flex-1">
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
- className="h-9 w-full min-w-0 justify-between rounded-lg px-3 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)}
45
49
  >
46
50
  <span className={cn("truncate", !selectedLabel && "text-muted-foreground")}>
47
51
  {selectedLabel || "Search documents..."}
@@ -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
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kidecms/core",
3
- "version": "0.18.0",
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",