@react-navigation/core 7.0.0-alpha.1 → 7.0.0-alpha.3
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/commonjs/StaticNavigation.js +1 -2
- package/lib/commonjs/StaticNavigation.js.map +1 -1
- package/lib/commonjs/getPathFromState.js +7 -3
- package/lib/commonjs/getPathFromState.js.map +1 -1
- package/lib/commonjs/getStateFromPath.js +15 -0
- package/lib/commonjs/getStateFromPath.js.map +1 -1
- package/lib/commonjs/useRouteCache.js +16 -12
- package/lib/commonjs/useRouteCache.js.map +1 -1
- package/lib/commonjs/validatePathConfig.js +37 -10
- package/lib/commonjs/validatePathConfig.js.map +1 -1
- package/lib/module/StaticNavigation.js +1 -2
- package/lib/module/StaticNavigation.js.map +1 -1
- package/lib/module/getPathFromState.js +7 -3
- package/lib/module/getPathFromState.js.map +1 -1
- package/lib/module/getStateFromPath.js +15 -0
- package/lib/module/getStateFromPath.js.map +1 -1
- package/lib/module/useRouteCache.js +16 -12
- package/lib/module/useRouteCache.js.map +1 -1
- package/lib/module/validatePathConfig.js +37 -10
- package/lib/module/validatePathConfig.js.map +1 -1
- package/lib/typescript/src/SceneView.d.ts +0 -1
- package/lib/typescript/src/SceneView.d.ts.map +1 -1
- package/lib/typescript/src/StaticNavigation.d.ts +12 -5
- package/lib/typescript/src/StaticNavigation.d.ts.map +1 -1
- package/lib/typescript/src/getPathFromState.d.ts +1 -0
- package/lib/typescript/src/getPathFromState.d.ts.map +1 -1
- package/lib/typescript/src/getStateFromPath.d.ts +1 -0
- package/lib/typescript/src/getStateFromPath.d.ts.map +1 -1
- package/lib/typescript/src/types.d.ts +1 -1
- package/lib/typescript/src/types.d.ts.map +1 -1
- package/lib/typescript/src/useRouteCache.d.ts.map +1 -1
- package/lib/typescript/src/validatePathConfig.d.ts +1 -1
- package/lib/typescript/src/validatePathConfig.d.ts.map +1 -1
- package/package.json +6 -6
- package/src/StaticNavigation.tsx +15 -20
- package/src/getPathFromState.tsx +8 -3
- package/src/getStateFromPath.tsx +16 -0
- package/src/types.tsx +1 -1
- package/src/useRouteCache.tsx +17 -16
- package/src/validatePathConfig.tsx +58 -14
- package/lib/commonjs/fromEntries.js +0 -18
- package/lib/commonjs/fromEntries.js.map +0 -1
- package/lib/module/fromEntries.js +0 -12
- package/lib/module/fromEntries.js.map +0 -1
- package/lib/typescript/src/fromEntries.d.ts +0 -2
- package/lib/typescript/src/fromEntries.d.ts.map +0 -1
- package/src/fromEntries.tsx +0 -11
|
@@ -1,28 +1,72 @@
|
|
|
1
|
-
const formatToList = (items: string
|
|
2
|
-
|
|
1
|
+
const formatToList = (items: Record<string, string>) =>
|
|
2
|
+
Object.entries(items)
|
|
3
|
+
.map(([key, value]) => `- ${key} (${value})`)
|
|
4
|
+
.join('\n');
|
|
3
5
|
|
|
4
|
-
export function validatePathConfig(config:
|
|
5
|
-
const
|
|
6
|
+
export function validatePathConfig(config: unknown, root = true) {
|
|
7
|
+
const validation = {
|
|
8
|
+
path: 'string',
|
|
9
|
+
initialRouteName: 'string',
|
|
10
|
+
screens: 'object',
|
|
11
|
+
...(root
|
|
12
|
+
? null
|
|
13
|
+
: {
|
|
14
|
+
exact: 'boolean',
|
|
15
|
+
stringify: 'object',
|
|
16
|
+
parse: 'object',
|
|
17
|
+
}),
|
|
18
|
+
};
|
|
6
19
|
|
|
7
|
-
if (
|
|
8
|
-
|
|
20
|
+
if (typeof config !== 'object' || config === null) {
|
|
21
|
+
throw new Error(
|
|
22
|
+
`Expected the configuration to be an object, but got ${JSON.stringify(
|
|
23
|
+
config
|
|
24
|
+
)}.`
|
|
25
|
+
);
|
|
9
26
|
}
|
|
10
27
|
|
|
11
|
-
const
|
|
12
|
-
|
|
28
|
+
const validationErrors = Object.fromEntries(
|
|
29
|
+
Object.keys(config)
|
|
30
|
+
.map((key) => {
|
|
31
|
+
if (key in validation) {
|
|
32
|
+
const type = validation[key as keyof typeof validation];
|
|
33
|
+
// @ts-expect-error: we know the key exists
|
|
34
|
+
const value = config[key];
|
|
35
|
+
|
|
36
|
+
if (typeof value !== type) {
|
|
37
|
+
return [key, `expected '${type}', got '${typeof value}'`];
|
|
38
|
+
}
|
|
39
|
+
} else {
|
|
40
|
+
return [key, 'extraneous'];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return null;
|
|
44
|
+
})
|
|
45
|
+
.filter(Boolean) as [string, string][]
|
|
13
46
|
);
|
|
14
47
|
|
|
15
|
-
if (
|
|
48
|
+
if (Object.keys(validationErrors).length) {
|
|
16
49
|
throw new Error(
|
|
17
50
|
`Found invalid properties in the configuration:\n${formatToList(
|
|
18
|
-
|
|
19
|
-
)}\n\
|
|
20
|
-
|
|
21
|
-
)}\n\nSee https://reactnavigation.org/docs/configuring-links for more details on how to specify a linking configuration.`
|
|
51
|
+
validationErrors
|
|
52
|
+
)}\n\nYou can only specify the following properties:\n${formatToList(
|
|
53
|
+
validation
|
|
54
|
+
)}\n\nIf you want to specify configuration for screens, you need to specify them under a 'screens' property.\n\nSee https://reactnavigation.org/docs/configuring-links for more details on how to specify a linking configuration.`
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (
|
|
59
|
+
root &&
|
|
60
|
+
'path' in config &&
|
|
61
|
+
typeof config.path === 'string' &&
|
|
62
|
+
config.path.includes(':')
|
|
63
|
+
) {
|
|
64
|
+
throw new Error(
|
|
65
|
+
`Found invalid path '${config.path}'. The 'path' in the top-level configuration cannot contain patterns for params.`
|
|
22
66
|
);
|
|
23
67
|
}
|
|
24
68
|
|
|
25
|
-
if (config.screens) {
|
|
69
|
+
if ('screens' in config && config.screens) {
|
|
26
70
|
Object.entries(config.screens).forEach(([_, value]) => {
|
|
27
71
|
if (typeof value !== 'string') {
|
|
28
72
|
validatePathConfig(value, false);
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.fromEntries = fromEntries;
|
|
7
|
-
// Object.fromEntries is not available in older iOS versions
|
|
8
|
-
function fromEntries(entries) {
|
|
9
|
-
return entries.reduce((acc, _ref) => {
|
|
10
|
-
let [k, v] = _ref;
|
|
11
|
-
if (acc.hasOwnProperty(k)) {
|
|
12
|
-
throw new Error(`A value for key '${k}' already exists in the object.`);
|
|
13
|
-
}
|
|
14
|
-
acc[k] = v;
|
|
15
|
-
return acc;
|
|
16
|
-
}, {});
|
|
17
|
-
}
|
|
18
|
-
//# sourceMappingURL=fromEntries.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["fromEntries","entries","reduce","acc","k","v","hasOwnProperty","Error"],"sourceRoot":"../../src","sources":["fromEntries.tsx"],"mappings":";;;;;;AAAA;AACO,SAASA,WAAW,CAAsBC,OAA4B,EAAE;EAC7E,OAAOA,OAAO,CAACC,MAAM,CAAC,CAACC,GAAG,WAAa;IAAA,IAAX,CAACC,CAAC,EAAEC,CAAC,CAAC;IAChC,IAAIF,GAAG,CAACG,cAAc,CAACF,CAAC,CAAC,EAAE;MACzB,MAAM,IAAIG,KAAK,CAAE,oBAAmBH,CAAE,iCAAgC,CAAC;IACzE;IAEAD,GAAG,CAACC,CAAC,CAAC,GAAGC,CAAC;IACV,OAAOF,GAAG;EACZ,CAAC,EAAE,CAAC,CAAC,CAAiB;AACxB"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
// Object.fromEntries is not available in older iOS versions
|
|
2
|
-
export function fromEntries(entries) {
|
|
3
|
-
return entries.reduce((acc, _ref) => {
|
|
4
|
-
let [k, v] = _ref;
|
|
5
|
-
if (acc.hasOwnProperty(k)) {
|
|
6
|
-
throw new Error(`A value for key '${k}' already exists in the object.`);
|
|
7
|
-
}
|
|
8
|
-
acc[k] = v;
|
|
9
|
-
return acc;
|
|
10
|
-
}, {});
|
|
11
|
-
}
|
|
12
|
-
//# sourceMappingURL=fromEntries.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["fromEntries","entries","reduce","acc","k","v","hasOwnProperty","Error"],"sourceRoot":"../../src","sources":["fromEntries.tsx"],"mappings":"AAAA;AACA,OAAO,SAASA,WAAW,CAAsBC,OAA4B,EAAE;EAC7E,OAAOA,OAAO,CAACC,MAAM,CAAC,CAACC,GAAG,WAAa;IAAA,IAAX,CAACC,CAAC,EAAEC,CAAC,CAAC;IAChC,IAAIF,GAAG,CAACG,cAAc,CAACF,CAAC,CAAC,EAAE;MACzB,MAAM,IAAIG,KAAK,CAAE,oBAAmBH,CAAE,iCAAgC,CAAC;IACzE;IAEAD,GAAG,CAACC,CAAC,CAAC,GAAGC,CAAC;IACV,OAAOF,GAAG;EACZ,CAAC,EAAE,CAAC,CAAC,CAAiB;AACxB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fromEntries.d.ts","sourceRoot":"","sources":["../../../src/fromEntries.tsx"],"names":[],"mappings":"AACA,wBAAgB,WAAW,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,gBAS5E"}
|
package/src/fromEntries.tsx
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
// Object.fromEntries is not available in older iOS versions
|
|
2
|
-
export function fromEntries<K extends string, V>(entries: (readonly [K, V])[]) {
|
|
3
|
-
return entries.reduce((acc, [k, v]) => {
|
|
4
|
-
if (acc.hasOwnProperty(k)) {
|
|
5
|
-
throw new Error(`A value for key '${k}' already exists in the object.`);
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
acc[k] = v;
|
|
9
|
-
return acc;
|
|
10
|
-
}, {} as Record<K, V>);
|
|
11
|
-
}
|