Small refactor
This commit is contained in:
+11
-13
@@ -82,17 +82,10 @@ function buildDataSource () {
|
|||||||
export function initLightbox () {
|
export function initLightbox () {
|
||||||
const { options = {} } = state.lightboxConfig
|
const { options = {} } = state.lightboxConfig
|
||||||
|
|
||||||
// Pull `padding` out as an override. Drop any `paddingFn` coming from config
|
|
||||||
// without overwriting ours: PhotoSwipe expects a function there, so an object
|
|
||||||
// from JSON would crash it.
|
|
||||||
const configPadding = options.padding as Partial<Record<'top' | 'bottom' | 'left' | 'right', number>> | undefined
|
|
||||||
const restOptions = { ...options }
|
|
||||||
delete restOptions.padding
|
|
||||||
delete restOptions.paddingFn
|
|
||||||
|
|
||||||
// Full-bleed by default, the same as Immich. Reserve a bottom strip only when captions
|
// Full-bleed by default, the same as Immich. Reserve a bottom strip only when captions
|
||||||
// are enabled, so the caption has somewhere to sit without overlapping the image.
|
// are enabled, so the caption has somewhere to sit without overlapping the image.
|
||||||
// Operators can override these via ipp.lightbox.options.padding
|
// Operators can override any side via ipp.lightbox.options.padding.
|
||||||
|
const configPadding = options.padding as Partial<Record<'top' | 'bottom' | 'left' | 'right', number>> | undefined
|
||||||
const showCaption = !!state.metadataConfig.descriptionInCaption
|
const showCaption = !!state.metadataConfig.descriptionInCaption
|
||||||
const basePadding = {
|
const basePadding = {
|
||||||
top: 0,
|
top: 0,
|
||||||
@@ -108,19 +101,24 @@ export function initLightbox () {
|
|||||||
closeOnVerticalDrag: true,
|
closeOnVerticalDrag: true,
|
||||||
arrowKeys: true,
|
arrowKeys: true,
|
||||||
loop: false,
|
loop: false,
|
||||||
|
// Hidden by default to match Immich; operators can re-enable via
|
||||||
|
// ipp.lightbox.options, which is why these sit before the `...options` spread.
|
||||||
counter: false,
|
counter: false,
|
||||||
zoom: false,
|
zoom: false,
|
||||||
close: false,
|
close: false,
|
||||||
// paddingFn lets the sidebar shrink the slide viewport when open. On a
|
...options,
|
||||||
// narrow viewport the sidebar overlays instead, so we leave padding
|
// paddingFn comes after `...options` so it always wins: PhotoSwipe gives it
|
||||||
// alone in that case.
|
// precedence over `padding`, and spreading it last neutralises any `padding`
|
||||||
|
// or (mistyped) `paddingFn` an operator put in config. Their static `padding`
|
||||||
|
// is still honoured above via basePadding. It lets the sidebar shrink the
|
||||||
|
// slide viewport when docked; on a narrow viewport the sidebar overlays
|
||||||
|
// instead, so we leave padding alone there.
|
||||||
paddingFn: () => ({
|
paddingFn: () => ({
|
||||||
...basePadding,
|
...basePadding,
|
||||||
right: state.sidebarOpen && window.innerWidth >= MOBILE_BREAKPOINT
|
right: state.sidebarOpen && window.innerWidth >= MOBILE_BREAKPOINT
|
||||||
? SIDEBAR_WIDTH + basePadding.right
|
? SIDEBAR_WIDTH + basePadding.right
|
||||||
: basePadding.right
|
: basePadding.right
|
||||||
}),
|
}),
|
||||||
...restOptions,
|
|
||||||
dataSource: buildDataSource(),
|
dataSource: buildDataSource(),
|
||||||
// @ts-expect-error - runtime URL resolved by Express static
|
// @ts-expect-error - runtime URL resolved by Express static
|
||||||
pswpModule: () => import('/share/static/photoswipe/photoswipe.esm.js') // eslint-disable-line import/no-absolute-path
|
pswpModule: () => import('/share/static/photoswipe/photoswipe.esm.js') // eslint-disable-line import/no-absolute-path
|
||||||
|
|||||||
Reference in New Issue
Block a user