Skip to content

Commit

Permalink
Merge pull request #13 from nulib/is-annotations
Browse files Browse the repository at this point in the history
Add isAnnotationsProperty to createAnnotationPage
  • Loading branch information
stephenwf authored Nov 4, 2022
2 parents a675cf2 + 33ecc7f commit 7fe1a47
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/canvas-builder.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { emptyAnnotationPage } from '@iiif/parser';
import { Annotation, CanvasNormalized } from '@iiif/presentation-3';

import { AnnotationPageInstanceBuilder } from './annotation-page-builder';
import { IIIFBuilder } from './iiif-builder';
import { BaseEntityBuilder } from './base-entity-builder';
import { IIIFBuilder } from './iiif-builder';
import { emptyAnnotationPage } from '@iiif/parser';

export class CanvasInstanceBuilder extends BaseEntityBuilder<CanvasNormalized> {
firstAnnotationPage?: AnnotationPageInstanceBuilder;
Expand All @@ -11,21 +12,27 @@ export class CanvasInstanceBuilder extends BaseEntityBuilder<CanvasNormalized> {
super(builder, entity);
}

createAnnotationPage(id: string, callback: (annotationPage: AnnotationPageInstanceBuilder) => void) {
createAnnotationPage(
id: string,
callback: (annotationPage: AnnotationPageInstanceBuilder) => void,
isAnnotationsProperty = false
) {
const annotationPageBuilder = new AnnotationPageInstanceBuilder(
this.builder,
{ ...emptyAnnotationPage, id },
this.entity.id
);
callback(annotationPageBuilder);
this.newInstances.push(annotationPageBuilder);
if (!this.firstAnnotationPage) {
if (!this.firstAnnotationPage && !isAnnotationsProperty) {
this.firstAnnotationPage = annotationPageBuilder;
}

this.modified.add('items');
this.entity.items = [
...this.entity.items,
const canvasPageProperty = isAnnotationsProperty ? 'annotations' : 'items';

this.modified.add(canvasPageProperty);
this.entity[canvasPageProperty] = [
...this.entity[canvasPageProperty],
{
id,
type: 'AnnotationPage',
Expand Down

0 comments on commit 7fe1a47

Please sign in to comment.