react-iiif-vault 0.9.18 → 0.9.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -388,7 +388,7 @@ function getVisibleCanvasesFromCanvasId(vault, manifestOrRange, canvasId, preven
388
388
  }
389
389
  return [{ id: fullCanvas.id, type: "Canvas" }];
390
390
  }
391
- function getManifestSequence(vault, manifestOrRange, { disablePaging } = {}) {
391
+ function getManifestSequence(vault, manifestOrRange, { disablePaging, skipNonPaged } = {}) {
392
392
  const behavior = manifestOrRange.behavior;
393
393
  const isPaged = behavior.includes("paged");
394
394
  const isContinuous = isPaged ? false : behavior.includes("continuous");
@@ -408,17 +408,36 @@ function getManifestSequence(vault, manifestOrRange, { disablePaging } = {}) {
408
408
  currentOrdering = [];
409
409
  }
410
410
  };
411
+ let offset = 0;
412
+ let flushNextPaged = false;
411
413
  for (let i = 0; i < manifestItems.length; i++) {
412
414
  const canvas = vault.get(manifestItems[i]);
413
- if (i === 0 || canvas.behavior.includes("facing-pages")) {
415
+ if (canvas.behavior.includes("non-paged")) {
416
+ if (i === offset) {
417
+ offset++;
418
+ }
419
+ if (!skipNonPaged) {
420
+ flush();
421
+ ordering.push([i]);
422
+ flush();
423
+ }
424
+ continue;
425
+ }
426
+ if (i === offset || canvas.behavior.includes("facing-pages")) {
427
+ if (currentOrdering.length) {
428
+ flushNextPaged = true;
429
+ }
414
430
  flush();
415
431
  ordering.push([i]);
432
+ flush();
416
433
  continue;
417
434
  }
418
- if (canvas.behavior.includes("non-paged")) {
435
+ currentOrdering.push(i);
436
+ if (flushNextPaged) {
437
+ flush();
438
+ flushNextPaged = false;
419
439
  continue;
420
440
  }
421
- currentOrdering.push(i);
422
441
  if (currentOrdering.length > 1) {
423
442
  flush();
424
443
  }
@@ -1308,8 +1327,11 @@ function getPaintables(vault, paintingAnnotations, enabledChoices) {
1308
1327
  let choice = null;
1309
1328
  const items = [];
1310
1329
  for (const annotation of paintingAnnotations) {
1311
- const bodies = vault.get(annotation.body);
1330
+ const bodies = vault.get(annotation.body, { skipSelfReturn: false });
1312
1331
  for (const unknownBody of bodies) {
1332
+ if (!unknownBody) {
1333
+ continue;
1334
+ }
1313
1335
  const [body, { selector }] = parseSpecificResource(unknownBody);
1314
1336
  const type = (body.type || "unknown").toLowerCase();
1315
1337
  if (type === "choice") {
@@ -1565,11 +1587,15 @@ function useLoadImageService() {
1565
1587
  return [loadImageService, imageServiceStatus];
1566
1588
  }
1567
1589
  function usePaintingAnnotations(options = {}) {
1590
+ const annotation = useAnnotation();
1568
1591
  const canvas = useCanvas(options.canvasId ? { id: options.canvasId } : void 0);
1569
1592
  return useVaultSelector((state, vault) => {
1570
1593
  if (!canvas) {
1571
1594
  return [];
1572
1595
  }
1596
+ if (annotation && options.enableSingleAnnotation) {
1597
+ return [annotation];
1598
+ }
1573
1599
  const annotationPages = vault.get(canvas.items);
1574
1600
  const flatAnnotations = [];
1575
1601
  for (const page of annotationPages) {
@@ -1580,7 +1606,7 @@ function usePaintingAnnotations(options = {}) {
1580
1606
  }
1581
1607
  function usePaintables(options, deps = []) {
1582
1608
  const vault = useVault();
1583
- const paintingAnnotations = usePaintingAnnotations();
1609
+ const paintingAnnotations = usePaintingAnnotations({ enableSingleAnnotation: options == null ? void 0 : options.enableSingleAnnotation });
1584
1610
  const [enabledChoices, setEnabledChoices] = useState((options == null ? void 0 : options.defaultChoices) || []);
1585
1611
  const paintables = useMemo(() => getPaintables(vault, paintingAnnotations, enabledChoices), [vault, paintingAnnotations, enabledChoices, ...deps]);
1586
1612
  const makeChoice = useCallback((id, { deselectOthers = true, deselect = false } = {}) => {