@prenta/admin 2.11.0 → 2.11.2

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.
@@ -0,0 +1,22 @@
1
+ import { describe, expect, it } from 'vitest'
2
+ import { MEDIA_GRID_ROW_HEIGHT, mediaGridColumns } from '../../views/MediaBrowser.js'
3
+
4
+ describe('media grid layout', () => {
5
+ it('fits auto-fill minmax(220px, 1fr) columns with a 14px gap', () => {
6
+ expect(mediaGridColumns(219)).toBe(1)
7
+ expect(mediaGridColumns(220)).toBe(1)
8
+ expect(mediaGridColumns(454)).toBe(2)
9
+ expect(mediaGridColumns(453)).toBe(1)
10
+ expect(mediaGridColumns(1170)).toBe(5)
11
+ })
12
+
13
+ it('falls back to four columns before the grid is measured', () => {
14
+ expect(mediaGridColumns(0)).toBe(4)
15
+ })
16
+
17
+ // Rows are virtualised at this stride; cards taller than it overlap the next
18
+ // row (the cropped-tile bug), so the stride is the fixed card height + gap.
19
+ it('uses the fixed card height plus the gap as the row stride', () => {
20
+ expect(MEDIA_GRID_ROW_HEIGHT).toBe(172 + 14)
21
+ })
22
+ })
@@ -722,6 +722,8 @@ export interface FormCaptchaSettings {
722
722
  provider: 'recaptcha' | 'turnstile' | 'none'
723
723
  siteKey: string
724
724
  hasSecret: boolean
725
+ /** False when the saved secret can't be decrypted on this deployment. Older cores omit it. */
726
+ secretReadable?: boolean
725
727
  secretLast4: string | null
726
728
  scoreThreshold: number
727
729
  envOverride: boolean
@@ -1487,7 +1487,17 @@ function RecaptchaKeys({
1487
1487
  onChange={(event) => setSecretKey(event.target.value)}
1488
1488
  className={keyInputClass}
1489
1489
  />
1490
- {fieldError('secretKey')}
1490
+ {fieldError('secretKey') ??
1491
+ (settings.hasSecret && settings.secretReadable === false ? (
1492
+ <span
1493
+ role="alert"
1494
+ className="text-err flex basis-full items-center justify-end gap-1 text-right text-[12px] font-medium"
1495
+ >
1496
+ <AlertCircle size={13} aria-hidden />
1497
+ This site can’t read the saved secret, so CAPTCHA checks fail here. It was saved with
1498
+ a different CMS_ENCRYPTION_KEY. Enter the secret key again and save.
1499
+ </span>
1500
+ ) : null)}
1491
1501
  </Row>
1492
1502
  <Row
1493
1503
  label="Score threshold"
@@ -122,30 +122,21 @@ export interface MediaBrowserProps {
122
122
  currentPath?: string
123
123
  }
124
124
 
125
- function gridColumnCount(width: number, panelOpen: boolean): number {
126
- if (panelOpen) {
127
- if (width >= 1024) return 4
128
- if (width >= 768) return 3
129
- return 2
130
- }
131
- if (width >= 1536) return 8
132
- if (width >= 1280) return 6
133
- if (width >= 1024) return 5
134
- if (width >= 768) return 4
135
- if (width >= 640) return 3
136
- return 2
137
- }
138
-
139
- function useGridColumns(panelOpen: boolean): number {
140
- const [width, setWidth] = useState(() =>
141
- typeof window === 'undefined' ? 1280 : window.innerWidth,
125
+ // Media.html `.media-grid` / `.media-thumb`. Grid rows are virtualised at a
126
+ // fixed stride, so card height must not depend on card width.
127
+ const MEDIA_CARD_MIN_WIDTH = 220
128
+ const MEDIA_GRID_GAP = 14
129
+ const MEDIA_GRID_PADDING_X = 28
130
+ const MEDIA_CARD_HEIGHT = 172
131
+ export const MEDIA_GRID_ROW_HEIGHT = MEDIA_CARD_HEIGHT + MEDIA_GRID_GAP
132
+
133
+ /** Columns that fit `auto-fill, minmax(220px, 1fr)` in the grid's content box. */
134
+ export function mediaGridColumns(contentWidth: number): number {
135
+ if (contentWidth <= 0) return 4
136
+ return Math.max(
137
+ 1,
138
+ Math.floor((contentWidth + MEDIA_GRID_GAP) / (MEDIA_CARD_MIN_WIDTH + MEDIA_GRID_GAP)),
142
139
  )
143
- useEffect(() => {
144
- const onResize = () => setWidth(window.innerWidth)
145
- window.addEventListener('resize', onResize)
146
- return () => window.removeEventListener('resize', onResize)
147
- }, [])
148
- return gridColumnCount(width, panelOpen)
149
140
  }
150
141
 
151
142
  function buildMediaApiUrl(folderSel: FolderSelection): string {
@@ -225,8 +216,20 @@ export function MediaBrowser({ onNavigate, currentPath, role, config }: MediaBro
225
216
  return results
226
217
  }, [mediaItems, searchQuery, filterType, sortConfig])
227
218
 
228
- const gridColumns = useGridColumns(activeItem !== null)
229
219
  const gridScrollRef = useRef<HTMLDivElement>(null)
220
+ const [gridWidth, setGridWidth] = useState(0)
221
+ const gridMounted = viewMode === 'grid' && activeTab === 'library' && filteredAndSorted.length > 0
222
+ useEffect(() => {
223
+ const el = gridScrollRef.current
224
+ if (!gridMounted || !el) return
225
+ const measure = () => setGridWidth(el.clientWidth - MEDIA_GRID_PADDING_X * 2)
226
+ measure()
227
+ if (typeof ResizeObserver === 'undefined') return
228
+ const observer = new ResizeObserver(measure)
229
+ observer.observe(el)
230
+ return () => observer.disconnect()
231
+ }, [gridMounted, loading])
232
+ const gridColumns = mediaGridColumns(gridWidth)
230
233
  const listScrollRef = useRef<HTMLDivElement>(null)
231
234
  /** The grid's or list's scroll position when a card opened the detail panel. */
232
235
  const savedListScroll = useRef(0)
@@ -234,7 +237,7 @@ export function MediaBrowser({ onNavigate, currentPath, role, config }: MediaBro
234
237
  const gridWindow = useVirtualWindow({
235
238
  count: gridRowCount,
236
239
  scrollRef: gridScrollRef,
237
- estimateSize: 220,
240
+ estimateSize: MEDIA_GRID_ROW_HEIGHT,
238
241
  overscan: 3,
239
242
  })
240
243
  const listWindow = useVirtualWindow({
@@ -855,13 +858,16 @@ export function MediaBrowser({ onNavigate, currentPath, role, config }: MediaBro
855
858
  tabIndex={0}
856
859
  role="region"
857
860
  aria-label="Media library"
858
- className="h-full overflow-y-auto p-2 sm:p-3"
861
+ className="h-full overflow-y-auto px-[28px] py-[20px]"
859
862
  >
860
- <div className="relative" style={{ height: gridRowCount * 220 }}>
863
+ <div
864
+ className="relative"
865
+ style={{ height: gridRowCount * MEDIA_GRID_ROW_HEIGHT }}
866
+ >
861
867
  {gridWindow.rows.map((virtualRow) => (
862
868
  <div
863
869
  key={virtualRow.key}
864
- className="grid gap-3 sm:gap-4"
870
+ className="grid gap-[14px]"
865
871
  style={{
866
872
  position: 'absolute',
867
873
  top: 0,
@@ -892,7 +898,8 @@ export function MediaBrowser({ onNavigate, currentPath, role, config }: MediaBro
892
898
  return (
893
899
  <div
894
900
  key={item.id}
895
- className={`group relative flex cursor-pointer flex-col overflow-hidden rounded-lg border-2 transition-all ${
901
+ data-media-card=""
902
+ className={`group relative flex h-[172px] cursor-pointer flex-col overflow-hidden rounded-lg border-2 transition-all ${
896
903
  isActive
897
904
  ? 'border-primary ring-primary/30 ring-2'
898
905
  : selectedMedia.includes(item.id)
@@ -903,7 +910,7 @@ export function MediaBrowser({ onNavigate, currentPath, role, config }: MediaBro
903
910
  draggable
904
911
  onDragStart={(e) => handleDragStart(e, item.id)}
905
912
  >
906
- <div className="relative aspect-square w-full overflow-hidden">
913
+ <div className="relative h-[118px] w-full shrink-0 overflow-hidden">
907
914
  <div className="bg-muted flex h-full w-full items-center justify-center">
908
915
  <MediaPreview item={item} />
909
916
  </div>
@@ -944,7 +951,7 @@ export function MediaBrowser({ onNavigate, currentPath, role, config }: MediaBro
944
951
  </div>
945
952
  </div>
946
953
  </div>
947
- <div className="border-border bg-card flex items-center gap-2 border-t px-2 py-1.5">
954
+ <div className="border-border bg-card flex min-h-0 flex-1 items-center gap-2 border-t px-2 py-1.5">
948
955
  <span
949
956
  className={`mt-0.5 h-2 w-2 shrink-0 self-start rounded-full ${
950
957
  hasIssues ? 'bg-warning' : 'bg-success'