@symbo.ls/router 2.12.95 → 2.12.100

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 -12
  2. package/package.json +2 -2
package/index.js CHANGED
@@ -1,8 +1,6 @@
1
1
  'use strict'
2
2
 
3
- import { setCookie } from '@domql/cookie'
4
- import { redirectBasedOnAuth } from '@symbo.ls/auth-redirect'
5
- import { isModalRoute } from '@symbo.ls/platform-utils'
3
+ import { setCookie } from '@domql/utils'
6
4
  import { merge } from 'smbls'
7
5
 
8
6
  export const getLocationPath = (index = 0, route = window.location.pathname) => {
@@ -43,12 +41,13 @@ const defaultOptions = {
43
41
  scrollToOptions: { behavior: 'smooth' }
44
42
  }
45
43
 
46
- export const router = (
44
+ export function router (
47
45
  path = '/',
48
- element,
46
+ el,
49
47
  state = {},
50
48
  passedOptions = {}
51
- ) => {
49
+ ) {
50
+ const element = el || (this && this.getRoot())
52
51
  const options = merge(passedOptions, defaultOptions)
53
52
  lastLevel = options.level
54
53
 
@@ -59,8 +58,7 @@ export const router = (
59
58
  let routeArray = pathname.split('/')
60
59
 
61
60
  if (options.authCheck) {
62
- const authRedirect = redirectBasedOnAuth(rootRoute, element, element.state)
63
-
61
+ const authRedirect = element.call('redirectBasedOnAuth', rootRoute)
64
62
  if (authRedirect && rootRoute !== authRedirect) {
65
63
  routeArray = authRedirect.split('/')
66
64
  }
@@ -73,7 +71,7 @@ export const router = (
73
71
 
74
72
  const content = element.routes[routeInContent] || element.routes['/*']
75
73
 
76
- const wasModal = isModalRoute(options.window.location.pathname.split('#')[0], element)
74
+ const wasModal = element.call('isModalRoute', options.window.location.pathname.split('#')[0])
77
75
  const isInitial = options.initialRender
78
76
  const hashChanged = hash && hash !== options.window.location.hash
79
77
  const pathChanged = pathname !== lastPathname
@@ -86,7 +84,7 @@ export const router = (
86
84
  }, null, route + (search ? `${search}` : '') + (hash ? `${hash}` : ''))
87
85
  }
88
86
 
89
- const isModal = !!isModalRoute(pathname, element)
87
+ const isModal = !!element.call('isModalRoute', pathname)
90
88
 
91
89
  if (pathChanged || !hashChanged) {
92
90
  // const rootRouteHasChanged = rootRoute !== element.state.rootRoute
@@ -122,7 +120,7 @@ export const router = (
122
120
  }
123
121
 
124
122
  const rootNode = element.node
125
- const scrollNode = options.scrollDocument ? document.documentElement : rootNode
123
+ const scrollNode = options.scrollDocument ? options.window.document.documentElement : rootNode
126
124
  if (options.scrollToTop) {
127
125
  scrollNode.scrollTo({
128
126
  ...(options.scrollToOptions || {}), top: 0, left: 0
@@ -135,7 +133,7 @@ export const router = (
135
133
  }
136
134
 
137
135
  if (hash) {
138
- const activeNode = document.getElementById(hash)
136
+ const activeNode = options.window.document.getElementById(hash.slice(1))
139
137
  if (activeNode) {
140
138
  const top = activeNode.getBoundingClientRect().top + rootNode.scrollTop - options.scrollToOffset || 0
141
139
  scrollNode.scrollTo({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@symbo.ls/router",
3
- "version": "2.12.95",
3
+ "version": "2.12.100",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
6
  "scripts": {
@@ -11,6 +11,6 @@
11
11
  "@domql/utils": "latest",
12
12
  "@symbo.ls/auth-redirect": "latest"
13
13
  },
14
- "gitHead": "4f7cde31ba4020b8f3f8ca509143eea404480036",
14
+ "gitHead": "04d5f0f5019789ef7a8367f5850862d6a976eb66",
15
15
  "source": "index.js"
16
16
  }