Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vault helper for Choice #159

Closed
tomcrane opened this issue Apr 1, 2022 · 3 comments
Closed

Vault helper for Choice #159

tomcrane opened this issue Apr 1, 2022 · 3 comments
Assignees
Milestone

Comments

@tomcrane
Copy link
Contributor

tomcrane commented Apr 1, 2022

Broken out of #156, extending #106

Current proposal is https://iiif-canvas-panel.netlify.app/docs/examples/handling-choice#additional-choice-helper-api

but it doesn't have to look like that.

@tomcrane tomcrane added the future label Apr 5, 2022
@stephenwf stephenwf moved this to Todo in Canvas panel v1.0 Jun 22, 2022
@stephenwf stephenwf self-assigned this Jun 22, 2022
@stephenwf stephenwf added this to the v1.0 milestone Jun 22, 2022
@stephenwf stephenwf moved this from Todo to In Progress in Canvas panel v1.0 Jul 13, 2022
@stephenwf
Copy link
Member

This will require a pre-requisite vault helper for painting annotations (as they are tied together). That API currently has the following surface:

getPaintingAnnotations(vault, canvas): AnnotationNormalized[];
getPaintables(vault, paintingAnnotations, enabledChoices): { types, items, choice }

The concept is that you can get a flat list of painting annotations from getPaintingAnnotations() and then pass it to getPaintables() to take into account the choices made to get a list of things to actually display.

If you call getPaintables() without any enabled choices, you will see a choice is returned. It can be either be a simple choice or a complex one. Complex choices are not supported. You can then use that to create a UI and if you need a new set of "things to render" you call getPaintables() again with the updated choices.

With these lower level tools, helpers could further add:

function containsChoice(vault, canvas) {
  const { choice } = getPaintables(vault, getPaintingAnnotations(vault, canvas));
  return choice !== null;
}

function extractChoices(vault, canvas) {
  const { choice } = getPaintables(vault, getPaintingAnnotations(vault, canvas));
  return choice;
}

Although that might feel a bit redundant, and we could simplify to just extract choices and update the example:

const choiceSets = vault.extractChoiceSets(canvas);
if (choiceSets) {
  // Render UI for choices.
  // When I'm ready, I can insert a web component onto the page:
  // <canvas-panel canvas-id=" ... " choice-id=" ... " />
} else {
  // Render normal component
  // <canvas-panel canvas-id=" ... " ... />
}

@stephenwf stephenwf moved this from In Progress to To discuss in Canvas panel v1.0 Jul 13, 2022
@stephenwf
Copy link
Member

Docs will be updated, implementation here: IIIF-Commons/vault-helpers#11

const helper = createPaintingAnnotationsHelper(vault);

helper.getAllPaintingAnnotations(canvas); // returns flattened list of annotations
helper.getPaintables(canvas); // returns list of types, choices and items
helper.extractChoices(canvas); // returns just choices

@stephenwf stephenwf moved this from To discuss to In PR in Canvas panel v1.0 Jul 13, 2022
@stephenwf
Copy link
Member

This has been expanded in #246 so that you can listen for choice events on multiple canvases in a sequence and make choices on both images. The current implementation is documented though.

@github-project-automation github-project-automation bot moved this from In PR to Done in Canvas panel v1.0 Apr 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

No branches or pull requests

2 participants