IIIF-Commons / iiif-helpers

MIT License
3 stars 2 forks source link

Added new range helpers for generating more usable trees for displaying #14

Closed stephenwf closed 3 months ago

stephenwf commented 4 months ago

Currently this will produce a tree with two types of node.

Full interface:

interface RangeTableOfContentsNode {
  id: string;
  type: 'Canvas' | 'Range';
  label: InternationalString | null;
  resource?: SpecificResource;
  untitled?: boolean;
  isCanvasLeaf: boolean;
  isRangeLeaf: boolean;
  isVirtual?: boolean;
  firstCanvas?: SpecificResource<Reference<'Canvas'>> | null;
  items?: Array<RangeTableOfContentsNode>;
}

Example Range node:

{
  "id": "https://iiif.io/api/cookbook/recipe/0024-book-4-toc/range/r1",
  "type": "Range",
  "isCanvasLeaf": false,
  "isRangeLeaf": true,
  "label": {
    "gez": [
      "Tabiba Tabiban [ጠቢበ ጠቢባን]",
    ],
  },
  "untitled": false,
  "firstCanvas": {
    "source": {
      "id": "https://iiif.io/api/cookbook/recipe/0024-book-4-toc/canvas/p1",
      "type": "Canvas",
    },
    "type": "SpecificResource",
  },
  "items": [ ... ],
}

The "Range" node contains the following:

Example Canvas node:

 {
  "id": "https://iiif.io/api/cookbook/recipe/0024-book-4-toc/canvas/p2",
  "isCanvasLeaf": true,
  "isRangeLeaf": false,
  "label": {
    "en": [
      "f. 1v",
    ],
  },
  "resource": {
    "source": {
      "id": "https://iiif.io/api/cookbook/recipe/0024-book-4-toc/canvas/p2",
      "type": "Canvas",
    },
    "type": "SpecificResource",
  },
  "type": "Canvas",
  "untitled": false,
}

Similar properties to the range, if you wanted to display each canvas. The label is grabbed from the canvas (if you use the helper with Vault).

It will also work with AV or regions, and use the normalized "SpecificResource" format, to make it easier to use.

{
  "id": "https://iiif.io/api/cookbook/recipe/0026-toc-opera/canvas/1#t=0,302.05",
  "isCanvasLeaf": true,
  "isRangeLeaf": false,
  "label": {
    "none": [
      "Untitled",
    ],
  },
  "resource": {
    "selector": {
      "type": "FragmentSelector",
      "value": "t=0,302.05",
    },
    "source": {
      "id": "https://iiif.io/api/cookbook/recipe/0026-toc-opera/canvas/1",
      "type": "Canvas",
    },
    "type": "SpecificResource",
  },
  "type": "Canvas",
  "untitled": true,
}

In this example, the canvas ID is pulled out, but the range is Untitled and marked as untitled. The time selector is also pulled out. (Other helpers in the repo can be used to parse it further).

codesandbox-ci[bot] commented 4 months ago

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.