@domql/router 2.5.83 → 2.5.94

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 CHANGED
@@ -49,6 +49,8 @@ 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;
@@ -57,7 +59,7 @@ const router = (path, element, state = {}, passedOptions = {}) => {
57
59
  const route = getActiveRoute(options.level, pathname);
58
60
  const content = element.routes[route || "/"] || element.routes["/*"];
59
61
  const scrollNode = options.scrollToNode ? rootNode : options.scrollNode;
60
- const hashChanged = hash && hash !== import_utils.window.location.hash.slice(1);
62
+ const hashChanged = hash && hash !== win.location.hash.slice(1);
61
63
  const pathChanged = pathname !== lastPathname;
62
64
  lastPathname = pathname;
63
65
  if (!content || element.state.root.debugging) {
@@ -65,7 +67,7 @@ const router = (path, element, state = {}, passedOptions = {}) => {
65
67
  return;
66
68
  }
67
69
  if (options.pushState) {
68
- import_utils.window.history.pushState(state, null, pathname + (hash ? `#${hash}` : ""));
70
+ win.history.pushState(state, null, pathname + (hash ? `#${hash}` : ""));
69
71
  }
70
72
  if (pathChanged || !hashChanged) {
71
73
  if (options.updateState) {
@@ -94,7 +96,7 @@ const router = (path, element, state = {}, passedOptions = {}) => {
94
96
  });
95
97
  }
96
98
  if (hash) {
97
- const activeNode = import_utils.document.getElementById(hash);
99
+ const activeNode = doc.getElementById(hash);
98
100
  if (activeNode) {
99
101
  const top = activeNode.getBoundingClientRect().top + rootNode.scrollTop - options.scrollToOffset || 0;
100
102
  scrollNode.scrollTo({
package/index.js CHANGED
@@ -32,6 +32,8 @@ 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
@@ -42,7 +44,7 @@ export const router = (
42
44
  const route = getActiveRoute(options.level, pathname)
43
45
  const content = element.routes[route || '/'] || element.routes['/*']
44
46
  const scrollNode = options.scrollToNode ? rootNode : options.scrollNode
45
- const hashChanged = hash && hash !== window.location.hash.slice(1)
47
+ const hashChanged = hash && hash !== win.location.hash.slice(1)
46
48
  const pathChanged = pathname !== lastPathname
47
49
  lastPathname = pathname
48
50
 
@@ -51,7 +53,7 @@ export const router = (
51
53
  return
52
54
  }
53
55
  if (options.pushState) {
54
- window.history.pushState(state, null, pathname + (hash ? `#${hash}` : ''))
56
+ win.history.pushState(state, null, pathname + (hash ? `#${hash}` : ''))
55
57
  }
56
58
 
57
59
  if (pathChanged || !hashChanged) {
@@ -81,7 +83,7 @@ export const router = (
81
83
  }
82
84
 
83
85
  if (hash) {
84
- const activeNode = document.getElementById(hash)
86
+ const activeNode = doc.getElementById(hash)
85
87
  if (activeNode) {
86
88
  const top = activeNode.getBoundingClientRect().top + rootNode.scrollTop - options.scrollToOffset || 0
87
89
  scrollNode.scrollTo({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@domql/router",
3
- "version": "2.5.83",
3
+ "version": "2.5.94",
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": "289086b924f79a0e92b9bc26a1963f3141930fbc",
28
+ "gitHead": "76edeab829524b706fd1a0bd3fac3fd5563a3b84",
29
29
  "devDependencies": {
30
30
  "@babel/core": "^7.12.0"
31
31
  }