react-native-readium 5.0.0-rc.15 → 5.0.0-rc.16
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.
- package/lib/web/hooks/useNavigator.js +4 -9
- package/lib/web/utils/index.d.ts +7 -0
- package/lib/web/utils/index.js +7 -0
- package/lib/web/utils/sanitizeInitialLocation.d.ts +3 -0
- package/lib/web/utils/sanitizeInitialLocation.js +28 -0
- package/package.json +1 -1
- package/web/hooks/useNavigator.ts +12 -10
- package/web/utils/index.ts +7 -0
- package/web/utils/sanitizeInitialLocation.ts +47 -0
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
2
2
|
import { EpubNavigator } from '@readium/navigator';
|
|
3
3
|
import { Publication } from '@readium/shared';
|
|
4
|
-
import { normalizeMetadata } from '../utils
|
|
5
|
-
import { fetchManifest } from '../utils/manifestFetcher';
|
|
6
|
-
import { createNavigatorListeners } from '../utils/navigatorListeners';
|
|
7
|
-
import { normalizePublicationURL, createPositions, extractTableOfContents, } from '../utils/publicationUtils';
|
|
8
|
-
import { convertToNavigatorLocator } from '../utils/locationNormalizer';
|
|
4
|
+
import { createNavigatorListeners, createPositions, extractTableOfContents, fetchManifest, normalizeMetadata, normalizePublicationURL, sanitizeInitialLocation, } from '../utils';
|
|
9
5
|
export const useNavigator = ({ file, onLocationChange, onPublicationReady, container, onPositionChange, }) => {
|
|
10
6
|
const [navigator, setNavigator] = useState(null);
|
|
11
7
|
const navigatorRef = useRef(null);
|
|
@@ -75,10 +71,9 @@ export const useNavigator = ({ file, onLocationChange, onPublicationReady, conta
|
|
|
75
71
|
setPositions(positionsArray);
|
|
76
72
|
// 5. Create navigator listeners
|
|
77
73
|
const listeners = createNavigatorListeners(onLocationChangeWithTotalProgression, onPositionChange);
|
|
78
|
-
// 6. Process initial location
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
: undefined;
|
|
74
|
+
// 6. Process initial location, sanitizing the position number to match
|
|
75
|
+
// the resolved positions array (handles scheme mismatch between sessions)
|
|
76
|
+
const initialPosition = sanitizeInitialLocation(file.initialLocation, positionsArray);
|
|
82
77
|
// 7. Initialize and load the navigator
|
|
83
78
|
const configuration = {
|
|
84
79
|
preferences: { scroll: false },
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * from './locationNormalizer';
|
|
2
|
+
export * from './manifestFetcher';
|
|
3
|
+
export * from './manifestNormalizer';
|
|
4
|
+
export * from './metadataNormalizer';
|
|
5
|
+
export * from './navigatorListeners';
|
|
6
|
+
export * from './publicationUtils';
|
|
7
|
+
export * from './sanitizeInitialLocation';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * from './locationNormalizer';
|
|
2
|
+
export * from './manifestFetcher';
|
|
3
|
+
export * from './manifestNormalizer';
|
|
4
|
+
export * from './metadataNormalizer';
|
|
5
|
+
export * from './navigatorListeners';
|
|
6
|
+
export * from './publicationUtils';
|
|
7
|
+
export * from './sanitizeInitialLocation';
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { convertToNavigatorLocator } from './locationNormalizer';
|
|
2
|
+
export const sanitizeInitialLocation = (initialLocation, positionsArray) => {
|
|
3
|
+
if (!initialLocation) {
|
|
4
|
+
return undefined;
|
|
5
|
+
}
|
|
6
|
+
const normalizedPosition = convertToNavigatorLocator(initialLocation);
|
|
7
|
+
if (!positionsArray.length) {
|
|
8
|
+
return normalizedPosition;
|
|
9
|
+
}
|
|
10
|
+
if (!normalizedPosition) {
|
|
11
|
+
return undefined;
|
|
12
|
+
}
|
|
13
|
+
const positionExists = positionsArray.some((p) => p.locations.position === normalizedPosition.locations.position);
|
|
14
|
+
if (positionExists) {
|
|
15
|
+
return normalizedPosition;
|
|
16
|
+
}
|
|
17
|
+
const matchByHref = positionsArray.find((p) => p.href === normalizedPosition.href);
|
|
18
|
+
if (matchByHref) {
|
|
19
|
+
return {
|
|
20
|
+
...matchByHref,
|
|
21
|
+
locations: {
|
|
22
|
+
...matchByHref.locations,
|
|
23
|
+
progression: normalizedPosition.locations.progression,
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
return undefined;
|
|
28
|
+
};
|
package/package.json
CHANGED
|
@@ -4,15 +4,15 @@ import { EpubNavigator } from '@readium/navigator';
|
|
|
4
4
|
import { Locator, Publication } from '@readium/shared';
|
|
5
5
|
|
|
6
6
|
import type { ReadiumProps } from '../../src/components/ReadiumView';
|
|
7
|
-
import { normalizeMetadata } from '../utils/metadataNormalizer';
|
|
8
|
-
import { fetchManifest } from '../utils/manifestFetcher';
|
|
9
|
-
import { createNavigatorListeners } from '../utils/navigatorListeners';
|
|
10
7
|
import {
|
|
11
|
-
|
|
8
|
+
createNavigatorListeners,
|
|
12
9
|
createPositions,
|
|
13
10
|
extractTableOfContents,
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
fetchManifest,
|
|
12
|
+
normalizeMetadata,
|
|
13
|
+
normalizePublicationURL,
|
|
14
|
+
sanitizeInitialLocation,
|
|
15
|
+
} from '../utils';
|
|
16
16
|
|
|
17
17
|
interface RefProps
|
|
18
18
|
extends Pick<
|
|
@@ -121,10 +121,12 @@ export const useNavigator = ({
|
|
|
121
121
|
onPositionChange
|
|
122
122
|
);
|
|
123
123
|
|
|
124
|
-
// 6. Process initial location
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
124
|
+
// 6. Process initial location, sanitizing the position number to match
|
|
125
|
+
// the resolved positions array (handles scheme mismatch between sessions)
|
|
126
|
+
const initialPosition = sanitizeInitialLocation(
|
|
127
|
+
file.initialLocation,
|
|
128
|
+
positionsArray
|
|
129
|
+
);
|
|
128
130
|
|
|
129
131
|
// 7. Initialize and load the navigator
|
|
130
132
|
const configuration = {
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * from './locationNormalizer';
|
|
2
|
+
export * from './manifestFetcher';
|
|
3
|
+
export * from './manifestNormalizer';
|
|
4
|
+
export * from './metadataNormalizer';
|
|
5
|
+
export * from './navigatorListeners';
|
|
6
|
+
export * from './publicationUtils';
|
|
7
|
+
export * from './sanitizeInitialLocation';
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { Locator } from '@readium/shared';
|
|
2
|
+
|
|
3
|
+
import type { Link, Locator as LocalLocator } from '../../src/interfaces';
|
|
4
|
+
import { convertToNavigatorLocator } from './locationNormalizer';
|
|
5
|
+
|
|
6
|
+
export const sanitizeInitialLocation = (
|
|
7
|
+
initialLocation: Link | LocalLocator | undefined,
|
|
8
|
+
positionsArray: Locator[]
|
|
9
|
+
): Locator | undefined => {
|
|
10
|
+
if (!initialLocation) {
|
|
11
|
+
return undefined;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const normalizedPosition = convertToNavigatorLocator(initialLocation);
|
|
15
|
+
|
|
16
|
+
if (!positionsArray.length) {
|
|
17
|
+
return normalizedPosition;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (!normalizedPosition) {
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const positionExists = positionsArray.some(
|
|
25
|
+
(p) => p.locations.position === normalizedPosition.locations.position
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
if (positionExists) {
|
|
29
|
+
return normalizedPosition;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const matchByHref = positionsArray.find(
|
|
33
|
+
(p) => p.href === normalizedPosition.href
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
if (matchByHref) {
|
|
37
|
+
return {
|
|
38
|
+
...matchByHref,
|
|
39
|
+
locations: {
|
|
40
|
+
...matchByHref.locations,
|
|
41
|
+
progression: normalizedPosition.locations.progression,
|
|
42
|
+
},
|
|
43
|
+
} as Locator;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return undefined;
|
|
47
|
+
};
|