@tinkoff/router 0.2.7 → 0.2.8
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/components/react/context.browser.js +7 -0
- package/lib/components/react/context.es.js +7 -0
- package/lib/components/react/context.js +13 -0
- package/lib/components/react/provider.browser.js +12 -0
- package/lib/components/react/provider.es.js +12 -0
- package/lib/components/react/provider.js +16 -0
- package/lib/components/react/useNavigate.browser.js +17 -0
- package/lib/components/react/useNavigate.es.js +17 -0
- package/lib/components/react/useNavigate.js +21 -0
- package/lib/components/react/useRoute.browser.js +8 -0
- package/lib/components/react/useRoute.es.js +8 -0
- package/lib/components/react/useRoute.js +12 -0
- package/lib/components/react/useRouter.browser.js +8 -0
- package/lib/components/react/useRouter.es.js +8 -0
- package/lib/components/react/useRouter.js +12 -0
- package/lib/components/react/useUrl.browser.js +8 -0
- package/lib/components/react/useUrl.es.js +8 -0
- package/lib/components/react/useUrl.js +12 -0
- package/lib/history/base.browser.js +11 -0
- package/lib/history/base.es.js +11 -0
- package/lib/history/base.js +15 -0
- package/lib/history/client.browser.js +121 -0
- package/lib/history/client.es.js +121 -0
- package/lib/history/client.js +125 -0
- package/lib/history/server.es.js +15 -0
- package/lib/history/server.js +19 -0
- package/lib/history/wrapper.browser.js +72 -0
- package/lib/history/wrapper.es.js +72 -0
- package/lib/history/wrapper.js +80 -0
- package/lib/index.browser.js +12 -1169
- package/lib/index.es.js +12 -1097
- package/lib/index.js +36 -1124
- package/lib/logger.browser.js +15 -0
- package/lib/logger.es.js +15 -0
- package/lib/logger.js +23 -0
- package/lib/router/abstract.browser.js +395 -0
- package/lib/router/abstract.es.js +395 -0
- package/lib/router/abstract.js +404 -0
- package/lib/router/browser.browser.js +166 -0
- package/lib/router/client.browser.js +116 -0
- package/lib/router/client.es.js +116 -0
- package/lib/router/client.js +120 -0
- package/lib/router/clientNoSpa.browser.js +17 -0
- package/lib/router/clientNoSpa.es.js +17 -0
- package/lib/router/clientNoSpa.js +21 -0
- package/lib/router/server.es.js +85 -0
- package/lib/router/server.js +89 -0
- package/lib/tree/constants.browser.js +6 -0
- package/lib/tree/constants.es.js +6 -0
- package/lib/tree/constants.js +13 -0
- package/lib/tree/tree.browser.js +148 -0
- package/lib/tree/tree.es.js +148 -0
- package/lib/tree/tree.js +158 -0
- package/lib/tree/utils.browser.js +77 -0
- package/lib/tree/utils.es.js +77 -0
- package/lib/tree/utils.js +90 -0
- package/lib/utils.browser.js +35 -0
- package/lib/utils.es.js +35 -0
- package/lib/utils.js +48 -0
- package/package.json +5 -6
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var logger = require('../logger.js');
|
|
6
|
+
var base = require('./base.js');
|
|
7
|
+
|
|
8
|
+
class ServerHistory extends base.History {
|
|
9
|
+
save() { }
|
|
10
|
+
go() {
|
|
11
|
+
logger.logger.warn({
|
|
12
|
+
event: 'history.server',
|
|
13
|
+
message: 'Trying to change history on server',
|
|
14
|
+
});
|
|
15
|
+
return Promise.resolve();
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
exports.ServerHistory = ServerHistory;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import noop from '@tinkoff/utils/function/noop';
|
|
2
|
+
|
|
3
|
+
const supportsHtml5History = typeof window !== 'undefined' && window.history && window.history.pushState;
|
|
4
|
+
const wrapHistory = ({ onNavigate }) => {
|
|
5
|
+
if (!supportsHtml5History) {
|
|
6
|
+
const navigate = (data, title, url) => {
|
|
7
|
+
window.location.href = url.toString();
|
|
8
|
+
};
|
|
9
|
+
window.history.pushState = navigate;
|
|
10
|
+
window.history.replaceState = navigate;
|
|
11
|
+
return {
|
|
12
|
+
navigate: ({ path }) => navigate({}, '', path),
|
|
13
|
+
history: () => {
|
|
14
|
+
throw new Error('Method not implemented');
|
|
15
|
+
},
|
|
16
|
+
init: noop,
|
|
17
|
+
subscribe: noop,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
let browserHistory = window.history;
|
|
21
|
+
if ('__originalHistory' in window.history) {
|
|
22
|
+
browserHistory = window.history.__originalHistory;
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
window.history.__originalHistory = {
|
|
26
|
+
pushState: browserHistory.pushState.bind(window.history),
|
|
27
|
+
replaceState: browserHistory.replaceState.bind(window.history),
|
|
28
|
+
go: browserHistory.go.bind(window.history),
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
const pushState = browserHistory.pushState.bind(window.history);
|
|
32
|
+
const replaceState = browserHistory.replaceState.bind(window.history);
|
|
33
|
+
const go = browserHistory.go.bind(window.history);
|
|
34
|
+
const navigate = ({ path, replace, state }) => {
|
|
35
|
+
if (replace) {
|
|
36
|
+
replaceState(state, '', path);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
pushState(state, '', path);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
const history = (delta) => {
|
|
43
|
+
go(delta);
|
|
44
|
+
};
|
|
45
|
+
const browserNavigate = (replace = false) => {
|
|
46
|
+
return (navigateState, title, url) => {
|
|
47
|
+
onNavigate({ url: url.toString(), replace, navigateState });
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
window.history.pushState = browserNavigate(false);
|
|
51
|
+
window.history.replaceState = browserNavigate(true);
|
|
52
|
+
window.history.go = history;
|
|
53
|
+
window.history.back = () => history(-1);
|
|
54
|
+
window.history.forward = () => history(1);
|
|
55
|
+
return {
|
|
56
|
+
navigate,
|
|
57
|
+
history,
|
|
58
|
+
init: (state) => {
|
|
59
|
+
replaceState(state, '');
|
|
60
|
+
},
|
|
61
|
+
subscribe: (handler) => {
|
|
62
|
+
window.addEventListener('popstate', ({ state }) => {
|
|
63
|
+
handler({
|
|
64
|
+
path: window.location.pathname + window.location.search + window.location.hash,
|
|
65
|
+
state,
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export { wrapHistory };
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import noop from '@tinkoff/utils/function/noop';
|
|
2
|
+
|
|
3
|
+
const supportsHtml5History = typeof window !== 'undefined' && window.history && window.history.pushState;
|
|
4
|
+
const wrapHistory = ({ onNavigate }) => {
|
|
5
|
+
if (!supportsHtml5History) {
|
|
6
|
+
const navigate = (data, title, url) => {
|
|
7
|
+
window.location.href = url.toString();
|
|
8
|
+
};
|
|
9
|
+
window.history.pushState = navigate;
|
|
10
|
+
window.history.replaceState = navigate;
|
|
11
|
+
return {
|
|
12
|
+
navigate: ({ path }) => navigate({}, '', path),
|
|
13
|
+
history: () => {
|
|
14
|
+
throw new Error('Method not implemented');
|
|
15
|
+
},
|
|
16
|
+
init: noop,
|
|
17
|
+
subscribe: noop,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
let browserHistory = window.history;
|
|
21
|
+
if ('__originalHistory' in window.history) {
|
|
22
|
+
browserHistory = window.history.__originalHistory;
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
window.history.__originalHistory = {
|
|
26
|
+
pushState: browserHistory.pushState.bind(window.history),
|
|
27
|
+
replaceState: browserHistory.replaceState.bind(window.history),
|
|
28
|
+
go: browserHistory.go.bind(window.history),
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
const pushState = browserHistory.pushState.bind(window.history);
|
|
32
|
+
const replaceState = browserHistory.replaceState.bind(window.history);
|
|
33
|
+
const go = browserHistory.go.bind(window.history);
|
|
34
|
+
const navigate = ({ path, replace, state }) => {
|
|
35
|
+
if (replace) {
|
|
36
|
+
replaceState(state, '', path);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
pushState(state, '', path);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
const history = (delta) => {
|
|
43
|
+
go(delta);
|
|
44
|
+
};
|
|
45
|
+
const browserNavigate = (replace = false) => {
|
|
46
|
+
return (navigateState, title, url) => {
|
|
47
|
+
onNavigate({ url: url.toString(), replace, navigateState });
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
window.history.pushState = browserNavigate(false);
|
|
51
|
+
window.history.replaceState = browserNavigate(true);
|
|
52
|
+
window.history.go = history;
|
|
53
|
+
window.history.back = () => history(-1);
|
|
54
|
+
window.history.forward = () => history(1);
|
|
55
|
+
return {
|
|
56
|
+
navigate,
|
|
57
|
+
history,
|
|
58
|
+
init: (state) => {
|
|
59
|
+
replaceState(state, '');
|
|
60
|
+
},
|
|
61
|
+
subscribe: (handler) => {
|
|
62
|
+
window.addEventListener('popstate', ({ state }) => {
|
|
63
|
+
handler({
|
|
64
|
+
path: window.location.pathname + window.location.search + window.location.hash,
|
|
65
|
+
state,
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export { wrapHistory };
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var noop = require('@tinkoff/utils/function/noop');
|
|
6
|
+
|
|
7
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
8
|
+
|
|
9
|
+
var noop__default = /*#__PURE__*/_interopDefaultLegacy(noop);
|
|
10
|
+
|
|
11
|
+
const supportsHtml5History = typeof window !== 'undefined' && window.history && window.history.pushState;
|
|
12
|
+
const wrapHistory = ({ onNavigate }) => {
|
|
13
|
+
if (!supportsHtml5History) {
|
|
14
|
+
const navigate = (data, title, url) => {
|
|
15
|
+
window.location.href = url.toString();
|
|
16
|
+
};
|
|
17
|
+
window.history.pushState = navigate;
|
|
18
|
+
window.history.replaceState = navigate;
|
|
19
|
+
return {
|
|
20
|
+
navigate: ({ path }) => navigate({}, '', path),
|
|
21
|
+
history: () => {
|
|
22
|
+
throw new Error('Method not implemented');
|
|
23
|
+
},
|
|
24
|
+
init: noop__default["default"],
|
|
25
|
+
subscribe: noop__default["default"],
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
let browserHistory = window.history;
|
|
29
|
+
if ('__originalHistory' in window.history) {
|
|
30
|
+
browserHistory = window.history.__originalHistory;
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
window.history.__originalHistory = {
|
|
34
|
+
pushState: browserHistory.pushState.bind(window.history),
|
|
35
|
+
replaceState: browserHistory.replaceState.bind(window.history),
|
|
36
|
+
go: browserHistory.go.bind(window.history),
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
const pushState = browserHistory.pushState.bind(window.history);
|
|
40
|
+
const replaceState = browserHistory.replaceState.bind(window.history);
|
|
41
|
+
const go = browserHistory.go.bind(window.history);
|
|
42
|
+
const navigate = ({ path, replace, state }) => {
|
|
43
|
+
if (replace) {
|
|
44
|
+
replaceState(state, '', path);
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
pushState(state, '', path);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
const history = (delta) => {
|
|
51
|
+
go(delta);
|
|
52
|
+
};
|
|
53
|
+
const browserNavigate = (replace = false) => {
|
|
54
|
+
return (navigateState, title, url) => {
|
|
55
|
+
onNavigate({ url: url.toString(), replace, navigateState });
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
window.history.pushState = browserNavigate(false);
|
|
59
|
+
window.history.replaceState = browserNavigate(true);
|
|
60
|
+
window.history.go = history;
|
|
61
|
+
window.history.back = () => history(-1);
|
|
62
|
+
window.history.forward = () => history(1);
|
|
63
|
+
return {
|
|
64
|
+
navigate,
|
|
65
|
+
history,
|
|
66
|
+
init: (state) => {
|
|
67
|
+
replaceState(state, '');
|
|
68
|
+
},
|
|
69
|
+
subscribe: (handler) => {
|
|
70
|
+
window.addEventListener('popstate', ({ state }) => {
|
|
71
|
+
handler({
|
|
72
|
+
path: window.location.pathname + window.location.search + window.location.hash,
|
|
73
|
+
state,
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
exports.wrapHistory = wrapHistory;
|