Skip to content
4 changes: 3 additions & 1 deletion src/lib/AreaObservations.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ The zone where dragging can be performed is defined by the _parent element_ of t
import { deleteObservation } from './observations.js';
import { cancelTask } from './queue.svelte.js';
import { isDebugMode } from './settings.svelte.js';
import { toasts } from './toasts.svelte';
import { toasts } from './toasts.svelte.js';
import { tooltip } from './tooltips.js';
import { compareBy, entries } from './utils.js';

/**
Expand Down Expand Up @@ -273,6 +274,7 @@ The zone where dragging can be performed is defined by the _parent element_ of t
>
{#if label}
<header
use:tooltip={isDebugMode() ? `sort key = ${sortKey}` : undefined}
aria-expanded={!collapsedGroups.has(sortKey)}
aria-controls="{componentId}-group-{sortKey}"
>
Expand Down
4 changes: 2 additions & 2 deletions src/lib/BoundingBoxes.svelte.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ const _anyBoundingBox = type.or(centeredBoundingBox, topLeftBoundingBox);
*/

/**
* @type {CenteredBoundingBox}
* @satisfies {CenteredBoundingBox}
*/
export const FULL_IMAGE_CROPBOX = { w: 1, h: 1, x: 0.5, y: 0.5 };
export const FULL_IMAGE_CROPBOX = /** @type {const} */ ({ w: 1, h: 1, x: 0.5, y: 0.5 });

/**
*
Expand Down
3 changes: 3 additions & 0 deletions src/lib/ButtonIcon.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* @property {boolean} [disabled]
* @property {boolean} [crossout] draw a diagonal line through the button's content
* @property {boolean} [dangerous] style the button to indicate a dangerous action
* @property {() => void} [preload] function to call on mouseover, useful for preloading the next page in a navigation button for instance
* @property {Partial<import('$lib/tooltips.js').TooltipParameters>} [tooltipParams] additional params for the tooltip
*/

Expand All @@ -23,6 +24,7 @@
keyboard,
disabled,
crossout,
preload,
dangerous,
submits,
tooltipParams = {},
Expand All @@ -33,6 +35,7 @@
<button
{disabled}
{onclick}
onmouseenter={() => preload?.()}
class:crossout
class:dangerous
use:tooltip={{ text: help, keyboard, ...tooltipParams }}
Expand Down
1 change: 1 addition & 0 deletions src/lib/ButtonInk.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
letter-spacing: 0.05em;
cursor: pointer;
text-decoration: none;
font-size: 0.8em;
}

[role='button'].inline {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/CardMedia.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@

.errored-actions {
margin-top: 0.75em;
font-size: 0.4em;
font-size: 0.37em;
display: flex;
flex-wrap: wrap;
justify-content: center;
Expand Down
59 changes: 47 additions & 12 deletions src/lib/Carousel.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,17 @@
export interface Props<T = unknown> {
items: T[];
item: Snippet<[T]>;
// eslint-disable-next-line no-unused-vars
slideName: (item: T, index: number) => string;
currentItem?: T;
scrollers?: {
next: () => void;
prev: () => void;
};
/** Show keyboard shortcuts on the next button's tooltip */
'keyboard-next'?: string;
/** Show keyboard shortcuts on the previous button's tooltip */
'keyboard-prev'?: string;
}
</script>

Expand All @@ -19,13 +26,25 @@

import ButtonIcon from './ButtonIcon.svelte';

let { item: itemSnippet, items, scrollers = $bindable() }: Props<T> = $props();
let {
item: itemSnippet,
slideName,
items,
scrollers = $bindable(),
currentItem = $bindable(),
'keyboard-next': keyboardNext,
'keyboard-prev': keyboardPrev
}: Props<T> = $props();

let canScrollNext = $state(true);
let canScrollPrev = $state(false);
let currentIndex = $state(0);
let carousel: EmblaCarouselType | undefined = $state();

$effect(() => {
currentItem = items[currentIndex];
});

$effect(() => {
if (!carousel) return;
scrollers = {
Expand All @@ -35,23 +54,28 @@
});

$effect(() => {
function onSettle() {
function onSelect() {
canScrollPrev = carousel?.canScrollPrev() ?? false;
canScrollNext = carousel?.canScrollNext() ?? false;
currentIndex = carousel?.selectedScrollSnap() ?? 0;
}

carousel?.on('settle', onSettle);
return () => carousel?.off('settle', onSettle);
carousel?.on('settle', onSelect);
carousel?.on('select', onSelect);
return () => {
carousel?.off('settle', onSelect);
carousel?.off('select', onSelect);
};
});
</script>

<div class="embla">
<div class="embla" aria-roledescription="carousel">
{#key items}
{#if items.length > 1}
<nav>
<section role="group" class="controls">
<ButtonIcon
help="Image précédente"
keyboard={keyboardPrev ?? ''}
class="embla__prev"
disabled={!canScrollPrev}
onclick={() => {
Expand All @@ -62,9 +86,12 @@
</ButtonIcon>
<div class="dots">
{#each items as _, i (i)}
<!-- We use aria-disabled instead of disabled to avoid removing the button from the tab order -->
<!-- See https://www.w3.org/WAI/ARIA/apg/patterns/carousel/ -->
<button
class="dot"
aria-label="Aller à l'image {i + 1}"
aria-disabled={currentIndex === i}
class:active={currentIndex === i}
onclick={() => {
carousel?.scrollTo(i);
Expand All @@ -74,28 +101,35 @@
</div>
<ButtonIcon
help="Image suivante"
class="embla_next"
keyboard={keyboardNext ?? ''}
class="embla__next"
disabled={!canScrollNext}
onclick={() => {
carousel?.scrollNext();
}}
>
<IconNext />
</ButtonIcon>
</nav>
</section>
{/if}
<div
class="embla__viewport"
use:embla={{
options: { duration: 15 }
options: { duration: 12 }
}}
onemblaInit={(event: CustomEvent) => {
carousel = event.detail;
}}
>
<div class="embla__container">
<div class="embla__container" aria-atomic="false" aria-live="polite">
{#each items as item, i (i)}
<div class="embla__slide">
<div
class="embla__slide"
data-current-slide={currentIndex === i}
role="group"
aria-roledescription="slide"
aria-label={slideName(item, i)}
>
{@render itemSnippet(item)}
</div>
{/each}
Expand Down Expand Up @@ -128,7 +162,7 @@
height: 100%;
}

nav {
.controls {
display: flex;
align-items: center;
justify-content: center;
Expand All @@ -139,6 +173,7 @@
padding-top: 2em;
z-index: 10;
width: 100%;
--fg: white;
background: linear-gradient(to bottom, rgba(0, 0, 0, 0) 0%, rgba(0, 0, 0, 0.7) 100%);
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib/gallery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export async function galleryItemsGrouper(
if (value === undefined) return [options.length, `Sans ${label}`];
const group = grouper(value);
return [
options.find((opt) => opt.key === value)?.index ?? group,
options.find((opt) => opt.key === value.toString())?.index ?? group,
`${label} = ${group}`
];
};
Expand Down
8 changes: 7 additions & 1 deletion src/lib/idb.svelte.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
isSessionDependentReactiveTable,
Tables
} from './database.js';
import { nonnull, safeJSONStringify } from './utils.js';

/** @type {number | null} */
export const previewingPrNumber =
Expand Down Expand Up @@ -86,6 +87,11 @@ function wrangler(table) {
_tablesState[table] = await this.list();
}
},
/** @param {string[]} keys */
getMany: async (keys) =>
Promise.all(keys.map((key) => get(table, key))).then((results) =>
results.filter(nonnull)
),
/** @param {string} key */
get: async (key) => get(table, key),
/** @param {string} key */
Expand Down Expand Up @@ -120,7 +126,7 @@ function wrangler(table) {
* @returns {Promise<boolean>} true if the item was found and updated, false otherwise
*/
async update(key, property, value) {
const logLabel = `upd ${table} ${key} ${typeof property === 'string' ? property : '<Symbol>'} = ${value}`;
const logLabel = `upd ${table} ${key} ${typeof property === 'string' ? property : '<Symbol>'} = ${typeof value === 'object' ? safeJSONStringify(value) : value}`;

// Get item from DB
const item = await this.raw.get(key);
Expand Down
2 changes: 1 addition & 1 deletion src/lib/images.js
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ if (import.meta.vitest) {

/**
*
* @param {Image[]} images
* @param {Array<Pick<Image, "fileId">>} images
* @returns {string[]}
*/
export function imageFileIds(images) {
Expand Down
18 changes: 10 additions & 8 deletions src/lib/metadata/_testdata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,25 @@ import { METADATA_TYPES } from '$lib/schemas/metadata';
import { mapEntries } from '$lib/utils';

export const metadatas = {
integer: { id: 'metadata_integer', type: 'integer', options: [] },
float: { id: 'metadata_float', type: 'float', options: [] },
date: { id: 'metadata_date', type: 'date', options: [] },
string: { id: 'metadata_string', type: 'string', options: [] },
boolean: { id: 'metadata_boolean ', type: 'boolean', options: [] },
location: { id: 'metadata_location ', type: 'location', options: [] },
boundingbox: { id: 'metadata_boundingbox ', type: 'boundingbox', options: [] },
integer: { id: 'metadata_integer', type: 'integer', mergeMethod: 'average', options: [] },
float: { id: 'metadata_float', type: 'float', mergeMethod: 'average', options: [] },
date: { id: 'metadata_date', type: 'date', mergeMethod: 'average', options: [] },
string: { id: 'metadata_string', type: 'string', mergeMethod: 'none', options: [] },
boolean: { id: 'metadata_boolean ', type: 'boolean', mergeMethod: 'average', options: [] },
location: { id: 'metadata_location ', type: 'location', mergeMethod: 'average', options: [] },
boundingbox: { id: 'metadata_boundingbox ', type: 'boundingbox', mergeMethod: 'union', options: [] },
enum: {
id: 'metadata_enum ',
type: 'enum',
mergeMethod: 'max',
options: [
{ key: 'A', label: 'Option A', index: 1, synonyms: ['Option α'] },
{ key: 'B', label: 'Option B', index: 0, synonyms: ['Option β'] },
{ key: 'C', label: 'Option C', index: 2, synonyms: ['Option γ'] }
]
}
} as const satisfies {
[K in DB.MetadataType]: Pick<DB.Metadata, 'id' | 'type'> & {
[K in DB.MetadataType]: Pick<DB.Metadata, 'id' | 'type'| 'mergeMethod'> & {
options: DB.MetadataEnumVariant[];
};
};
Expand Down Expand Up @@ -112,6 +113,7 @@ export const items: Array<{ id: string; metadata: DB.MetadataValues }> = [
{
value: v,
manuallyModified: false,
confirmed: false,
confidence: 1,
alternatives: {}
} satisfies DB.MetadataValue
Expand Down
6 changes: 3 additions & 3 deletions src/lib/metadata/display.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import { round } from '$lib/utils';
* @param metadataOptions
* @returns
*/
export async function addValueLabels(
export function addValueLabels(
values: DB.MetadataValues,
metadataOptions: Record<string, Record<string, DB.MetadataEnumVariant>>
): Promise<Record<string, DB.MetadataValue & { valueLabel?: string }>> {
metadataOptions: Record<string, Record<string, Pick<DB.MetadataEnumVariant, 'key' | 'label'>>>
): Record<string, DB.MetadataValue & { valueLabel?: string }> {
return Object.fromEntries(
Object.entries(values).map(([key, value]) => {
const opts = metadataOptions[key];
Expand Down
2 changes: 1 addition & 1 deletion src/lib/metadata/grouping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export function metadataValueGrouper<Type extends DB.MetadataType>({
metadataPrettyValue(value, {
type,
language,
valueLabel: options.find((o) => o.key === value)?.label,
valueLabel: options.find((o) => o.key === value?.toString())?.label,
boundingBoxPrecision: decimalTolerance
});

Expand Down
1 change: 1 addition & 0 deletions src/lib/metadata/merging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ function mergeMetadata(
value,
manuallyModified: values.some((v) => v.manuallyModified),
confidence: confidences(values.map((v) => v.confidence)),
confirmed: values.every((v) => v.confirmed),
alternatives: mergeAlternatives(confidences, values)
});

Expand Down
10 changes: 7 additions & 3 deletions src/lib/metadata/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,18 @@ export function assertIs<Type extends DB.MetadataType>(type: Type, value: any):
}

/**
* Get a strongly-typed metadata value from an image (Image ONLY, not Observation).
* Get a strongly-typed metadata value from an image or an observation
*/
export function getMetadataValue<Type extends DB.MetadataType>(
image: DB.Image,
subject: Pick<DB.Image, 'metadata'> | Pick<DB.Observation, 'metadataOverrides'>,
type: Type,
metadataId: string
): TypedMetadataValue<Type> | undefined {
const value = image.metadata[metadataId];
const value =
'metadataOverrides' in subject
? subject.metadataOverrides[metadataId]
: subject.metadata[metadataId];

if (value === undefined) return undefined;

return {
Expand Down
Loading
Loading