@domql/router 2.5.84 → 2.5.110
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/dist/cjs/index.js +7 -4
- package/index.js +7 -4
- package/package.json +2 -2
package/dist/cjs/index.js
CHANGED
|
@@ -49,15 +49,18 @@ const defaultOptions = {
|
|
|
49
49
|
scrollToOptions: { behavior: "smooth" }
|
|
50
50
|
};
|
|
51
51
|
const router = (path, element, state = {}, passedOptions = {}) => {
|
|
52
|
+
const win = element.context.window || import_utils.window;
|
|
53
|
+
const doc = element.context.document || import_utils.document;
|
|
52
54
|
const options = { ...defaultOptions, ...element.context.routerOptions, ...passedOptions };
|
|
53
55
|
lastLevel = options.lastLevel;
|
|
54
56
|
const contentElementKey = options.contentElementKey;
|
|
55
|
-
const
|
|
57
|
+
const urlObj = new win.URL(win.location.origin + path);
|
|
58
|
+
const { pathname, search, hash } = urlObj;
|
|
56
59
|
const rootNode = element.node;
|
|
57
60
|
const route = getActiveRoute(options.level, pathname);
|
|
58
61
|
const content = element.routes[route || "/"] || element.routes["/*"];
|
|
59
62
|
const scrollNode = options.scrollToNode ? rootNode : options.scrollNode;
|
|
60
|
-
const hashChanged = hash && hash !==
|
|
63
|
+
const hashChanged = hash && hash !== win.location.hash.slice(1);
|
|
61
64
|
const pathChanged = pathname !== lastPathname;
|
|
62
65
|
lastPathname = pathname;
|
|
63
66
|
if (!content || element.state.root.debugging) {
|
|
@@ -65,7 +68,7 @@ const router = (path, element, state = {}, passedOptions = {}) => {
|
|
|
65
68
|
return;
|
|
66
69
|
}
|
|
67
70
|
if (options.pushState) {
|
|
68
|
-
|
|
71
|
+
win.history.pushState(state, null, pathname + (search || "") + (hash || ""));
|
|
69
72
|
}
|
|
70
73
|
if (pathChanged || !hashChanged) {
|
|
71
74
|
if (options.updateState) {
|
|
@@ -94,7 +97,7 @@ const router = (path, element, state = {}, passedOptions = {}) => {
|
|
|
94
97
|
});
|
|
95
98
|
}
|
|
96
99
|
if (hash) {
|
|
97
|
-
const activeNode =
|
|
100
|
+
const activeNode = doc.getElementById(hash);
|
|
98
101
|
if (activeNode) {
|
|
99
102
|
const top = activeNode.getBoundingClientRect().top + rootNode.scrollTop - options.scrollToOffset || 0;
|
|
100
103
|
scrollNode.scrollTo({
|
package/index.js
CHANGED
|
@@ -32,17 +32,20 @@ export const router = (
|
|
|
32
32
|
state = {},
|
|
33
33
|
passedOptions = {}
|
|
34
34
|
) => {
|
|
35
|
+
const win = element.context.window || window
|
|
36
|
+
const doc = element.context.document || document
|
|
35
37
|
const options = { ...defaultOptions, ...element.context.routerOptions, ...passedOptions }
|
|
36
38
|
lastLevel = options.lastLevel
|
|
37
39
|
const contentElementKey = options.contentElementKey
|
|
38
40
|
|
|
39
|
-
const
|
|
41
|
+
const urlObj = new win.URL(win.location.origin + path)
|
|
42
|
+
const { pathname, search, hash } = urlObj
|
|
40
43
|
|
|
41
44
|
const rootNode = element.node
|
|
42
45
|
const route = getActiveRoute(options.level, pathname)
|
|
43
46
|
const content = element.routes[route || '/'] || element.routes['/*']
|
|
44
47
|
const scrollNode = options.scrollToNode ? rootNode : options.scrollNode
|
|
45
|
-
const hashChanged = hash && hash !==
|
|
48
|
+
const hashChanged = hash && hash !== win.location.hash.slice(1)
|
|
46
49
|
const pathChanged = pathname !== lastPathname
|
|
47
50
|
lastPathname = pathname
|
|
48
51
|
|
|
@@ -51,7 +54,7 @@ export const router = (
|
|
|
51
54
|
return
|
|
52
55
|
}
|
|
53
56
|
if (options.pushState) {
|
|
54
|
-
|
|
57
|
+
win.history.pushState(state, null, pathname + (search || '') + (hash || ''))
|
|
55
58
|
}
|
|
56
59
|
|
|
57
60
|
if (pathChanged || !hashChanged) {
|
|
@@ -81,7 +84,7 @@ export const router = (
|
|
|
81
84
|
}
|
|
82
85
|
|
|
83
86
|
if (hash) {
|
|
84
|
-
const activeNode =
|
|
87
|
+
const activeNode = doc.getElementById(hash)
|
|
85
88
|
if (activeNode) {
|
|
86
89
|
const top = activeNode.getBoundingClientRect().top + rootNode.scrollTop - options.scrollToOffset || 0
|
|
87
90
|
scrollNode.scrollTo({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@domql/router",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.110",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"@domql/globals": "latest",
|
|
26
26
|
"@domql/utils": "latest"
|
|
27
27
|
},
|
|
28
|
-
"gitHead": "
|
|
28
|
+
"gitHead": "2942c0972b473f8be846cbf0e5a9f1917cf20d65",
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@babel/core": "^7.12.0"
|
|
31
31
|
}
|