Skip to content

Commit

Permalink
Merge pull request #11 from abrin/allow-choices-to-support-multiple
Browse files Browse the repository at this point in the history
allow choices helpers to support multiple
  • Loading branch information
stephenwf authored Apr 9, 2024
2 parents 0f582fb + fa4abf8 commit c15013f
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/painting-annotations/helper.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ContentResource, IIIFExternalWebResource } from '@iiif/presentation-3';
import { AnnotationNormalized, CanvasNormalized } from '@iiif/presentation-3-normalized';
import { Paintables } from './types';
import { ComplexChoice, Paintables } from './types';
import { parseSpecificResource } from './parse-specific-resource';
import { compatVault, CompatVault } from '../compat';

Expand Down Expand Up @@ -32,7 +32,10 @@ export function createPaintingAnnotationsHelper(vault: CompatVault = compatVault
: getAllPaintingAnnotations(paintingAnnotationsOrCanvas);

const types: string[] = [];
let choice: Paintables['choice'] = null;
let choices: ComplexChoice = {
items: [],
type: 'complex-choice'
};
const items: Paintables['items'] = [];

for (const annotation of paintingAnnotations) {
Expand All @@ -59,15 +62,15 @@ export function createPaintingAnnotationsHelper(vault: CompatVault = compatVault
}

// Store choice.
choice = {
choices.items.push({
type: 'single-choice',
items: nestedBodies.map((b) => ({
id: b.id,
label: (b as any).label as any,
selected: selected.indexOf(b) !== -1,
})) as any[],
label: (ref as any).label,
};
});

// @todo insert in the right order.
references.push(...(selected as any[]));
Expand All @@ -92,7 +95,7 @@ export function createPaintingAnnotationsHelper(vault: CompatVault = compatVault
return {
types,
items,
choice,
choice: choices.items.length < 2 ? (choices.items[0] || null) : choices,
};
}

Expand Down

0 comments on commit c15013f

Please sign in to comment.