From d9c18aaca604db6c7470cbff71c2d37bc9ca4d12 Mon Sep 17 00:00:00 2001 From: Adam Brin Date: Mon, 8 Apr 2024 07:30:52 -0700 Subject: [PATCH 1/2] allow choices helpers to support multiple --- src/painting-annotations/helper.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/painting-annotations/helper.ts b/src/painting-annotations/helper.ts index 433000c..5535dfc 100644 --- a/src/painting-annotations/helper.ts +++ b/src/painting-annotations/helper.ts @@ -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'; @@ -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) { @@ -59,7 +62,7 @@ export function createPaintingAnnotationsHelper(vault: CompatVault = compatVault } // Store choice. - choice = { + choices.items.push({ type: 'single-choice', items: nestedBodies.map((b) => ({ id: b.id, @@ -67,7 +70,7 @@ export function createPaintingAnnotationsHelper(vault: CompatVault = compatVault selected: selected.indexOf(b) !== -1, })) as any[], label: (ref as any).label, - }; + }); // @todo insert in the right order. references.push(...(selected as any[])); @@ -92,7 +95,7 @@ export function createPaintingAnnotationsHelper(vault: CompatVault = compatVault return { types, items, - choice, + choice: choices.items.length < 2 ? choices.items[0] : choices, }; } From fa4abf828c083b9795dd7a892eb92016b9ed0478 Mon Sep 17 00:00:00 2001 From: Adam Brin Date: Tue, 9 Apr 2024 05:23:00 -0700 Subject: [PATCH 2/2] Update src/painting-annotations/helper.ts Co-authored-by: Stephen Fraser --- src/painting-annotations/helper.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/painting-annotations/helper.ts b/src/painting-annotations/helper.ts index 5535dfc..b8f12b8 100644 --- a/src/painting-annotations/helper.ts +++ b/src/painting-annotations/helper.ts @@ -95,7 +95,7 @@ export function createPaintingAnnotationsHelper(vault: CompatVault = compatVault return { types, items, - choice: choices.items.length < 2 ? choices.items[0] : choices, + choice: choices.items.length < 2 ? (choices.items[0] || null) : choices, }; }