goblin-laboratory 4.11.2 → 4.11.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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "goblin-laboratory",
|
|
3
|
-
"version": "4.11.
|
|
3
|
+
"version": "4.11.3",
|
|
4
4
|
"description": "Laboratory",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
@@ -43,12 +43,12 @@
|
|
|
43
43
|
"immutable": "4.0.0-rc.14",
|
|
44
44
|
"linked-list": "^1.0.4",
|
|
45
45
|
"obj-to-css": "^1.0.1",
|
|
46
|
+
"path-to-regexp": "^1.9.0",
|
|
46
47
|
"prettier": "2.0.4",
|
|
47
48
|
"prop-types": "^15.5.10",
|
|
48
49
|
"react": "^17.0.1",
|
|
49
50
|
"react-dom": "^17.0.1",
|
|
50
51
|
"react-redux": "^8.1.3",
|
|
51
|
-
"react-router": "^5.0.0",
|
|
52
52
|
"redux-thunk": "^2.3.0",
|
|
53
53
|
"safe-stable-stringify": "^2.5.0",
|
|
54
54
|
"xcraft-core-shredder": "^5.3.0",
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import pathToRegexp from 'path-to-regexp';
|
|
2
|
+
|
|
3
|
+
const cache = {};
|
|
4
|
+
const cacheLimit = 10000;
|
|
5
|
+
let cacheCount = 0;
|
|
6
|
+
|
|
7
|
+
function compilePath(path, options) {
|
|
8
|
+
const cacheKey = `${options.end}${options.strict}${options.sensitive}`;
|
|
9
|
+
const pathCache = cache[cacheKey] || (cache[cacheKey] = {});
|
|
10
|
+
|
|
11
|
+
if (pathCache[path]) return pathCache[path];
|
|
12
|
+
|
|
13
|
+
const keys = [];
|
|
14
|
+
const regexp = pathToRegexp(path, keys, options);
|
|
15
|
+
const result = {regexp, keys};
|
|
16
|
+
|
|
17
|
+
if (cacheCount < cacheLimit) {
|
|
18
|
+
pathCache[path] = result;
|
|
19
|
+
cacheCount++;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return result;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Public API for matching a URL pathname to a path.
|
|
27
|
+
*/
|
|
28
|
+
function matchPath(pathname, options = {}) {
|
|
29
|
+
if (typeof options === 'string' || Array.isArray(options)) {
|
|
30
|
+
options = {path: options};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const {path, exact = false, strict = false, sensitive = false} = options;
|
|
34
|
+
|
|
35
|
+
const paths = [].concat(path);
|
|
36
|
+
|
|
37
|
+
return paths.reduce((matched, path) => {
|
|
38
|
+
if (!path && path !== '') return null;
|
|
39
|
+
if (matched) return matched;
|
|
40
|
+
|
|
41
|
+
const {regexp, keys} = compilePath(path, {
|
|
42
|
+
end: exact,
|
|
43
|
+
strict,
|
|
44
|
+
sensitive,
|
|
45
|
+
});
|
|
46
|
+
const match = regexp.exec(pathname);
|
|
47
|
+
|
|
48
|
+
if (!match) return null;
|
|
49
|
+
|
|
50
|
+
const [url, ...values] = match;
|
|
51
|
+
const isExact = pathname === url;
|
|
52
|
+
|
|
53
|
+
if (exact && !isExact) return null;
|
|
54
|
+
|
|
55
|
+
return {
|
|
56
|
+
path, // the path used to match
|
|
57
|
+
url: path === '/' && url === '' ? '/' : url, // the matched portion of the URL
|
|
58
|
+
isExact, // whether or not we matched exactly
|
|
59
|
+
params: keys.reduce((memo, key, index) => {
|
|
60
|
+
memo[key.name] = values[index];
|
|
61
|
+
return memo;
|
|
62
|
+
}, {}),
|
|
63
|
+
};
|
|
64
|
+
}, null);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export default matchPath;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {connect} from 'react-redux';
|
|
2
2
|
import Shredder from 'xcraft-core-shredder';
|
|
3
|
-
import {matchPath} from 'react-router';
|
|
4
3
|
import {getParameter} from '../../lib/helpers.js';
|
|
5
4
|
import shallowEqualShredder from '../widget/utils/shallowEqualShredder.js';
|
|
5
|
+
import matchPath from './matchPath.js';
|
|
6
6
|
|
|
7
7
|
export function withRoute(path, watchedParams, watchedSearchs, watchHash) {
|
|
8
8
|
return connect(
|