@domql/router 2.2.4 → 2.2.5

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.
Files changed (2) hide show
  1. package/index.js +10 -4
  2. package/package.json +2 -2
package/index.js CHANGED
@@ -7,6 +7,7 @@ export const router = (rootElement, path, state = {}, level = 0, pushState = tru
7
7
 
8
8
  if (path.slice(0, 1) === '#') {
9
9
  window.location.hash = path
10
+ return
10
11
  }
11
12
 
12
13
  const routes = splitRoute(route)
@@ -22,12 +23,17 @@ export const router = (rootElement, path, state = {}, level = 0, pushState = tru
22
23
  if (hasHash[1]) currentRoute += `#${hasHash[1]}`
23
24
  if (pushState) window.history.pushState(state, null, currentRoute)
24
25
 
25
- const newContent = rootElement.set({ proto: content }).content.node
26
- newContent.scrollIntoView({ behavior: 'smooth', block: 'start' })
26
+ const rootNode = rootElement.node
27
+ rootNode.scrollTo({ behavior: 'smooth', top: 0, left: 0 })
27
28
  if (hasHash[1]) {
28
- // window.location.hash = hasHash[1]
29
- document.getElementById(hasHash[1]).scrollIntoView({ behavior: 'smooth', block: 'start' })
29
+ const activeNode = document.getElementById(hasHash[1])
30
+ if (activeNode) {
31
+ const top = activeNode.getBoundingClientRect().top + rootNode.scrollTop - 140
32
+ rootNode.scrollTo({ behavior: 'smooth', top, left: 0 })
33
+ }
30
34
  }
35
+
36
+ rootElement.set({ proto: content })
31
37
  }
32
38
 
33
39
  if (level === 0) rootElement.state.update({ currentRoute })
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@domql/router",
3
- "version": "2.2.4",
3
+ "version": "2.2.5",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
6
  "scripts": {
7
7
  "vpatch": "npm version patch && npm publish --access public"
8
8
  },
9
- "gitHead": "a105ac3a4a89d120ec7199d9a4b9706e76ce128f",
9
+ "gitHead": "c275ad11c795e7abd68cce00d0c758905c4e4f18",
10
10
  "source": "index.js"
11
11
  }