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
  }
@@ -1303,8 +1322,11 @@ function getPaintables(vault, paintingAnnotations, enabledChoices) {
1303
1322
  let choice = null;
1304
1323
  const items = [];
1305
1324
  for (const annotation of paintingAnnotations) {
1306
- const bodies = vault.get(annotation.body);
1325
+ const bodies = vault.get(annotation.body, { skipSelfReturn: false });
1307
1326
  for (const unknownBody of bodies) {
1327
+ if (!unknownBody) {
1328
+ continue;
1329
+ }
1308
1330
  const [body, { selector }] = parseSpecificResource(unknownBody);
1309
1331
  const type = (body.type || "unknown").toLowerCase();
1310
1332
  if (type === "choice") {
@@ -1560,11 +1582,15 @@ function useLoadImageService() {
1560
1582
  return [loadImageService, imageServiceStatus];
1561
1583
  }
1562
1584
  function usePaintingAnnotations(options = {}) {
1585
+ const annotation = useAnnotation();
1563
1586
  const canvas = useCanvas(options.canvasId ? { id: options.canvasId } : void 0);
1564
1587
  return useVaultSelector((state, vault) => {
1565
1588
  if (!canvas) {
1566
1589
  return [];
1567
1590
  }
1591
+ if (annotation && options.enableSingleAnnotation) {
1592
+ return [annotation];
1593
+ }
1568
1594
  const annotationPages = vault.get(canvas.items);
1569
1595
  const flatAnnotations = [];
1570
1596
  for (const page of annotationPages) {
@@ -1575,7 +1601,7 @@ function usePaintingAnnotations(options = {}) {
1575
1601
  }
1576
1602
  function usePaintables(options, deps = []) {
1577
1603
  const vault = useVault();
1578
- const paintingAnnotations = usePaintingAnnotations();
1604
+ const paintingAnnotations = usePaintingAnnotations({ enableSingleAnnotation: options == null ? void 0 : options.enableSingleAnnotation });
1579
1605
  const [enabledChoices, setEnabledChoices] = useState((options == null ? void 0 : options.defaultChoices) || []);
1580
1606
  const paintables = useMemo(() => getPaintables(vault, paintingAnnotations, enabledChoices), [vault, paintingAnnotations, enabledChoices, ...deps]);
1581
1607
  const makeChoice = useCallback((id, { deselectOthers = true, deselect = false } = {}) => {