@symbo.ls/router 2.12.94 → 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.
- package/index.js +13 -18
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
import { setCookie } from '@domql/
|
|
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) => {
|
|
@@ -32,23 +30,24 @@ const defaultOptions = {
|
|
|
32
30
|
authCheck: true,
|
|
33
31
|
updateState: true,
|
|
34
32
|
updateStateOptions: {
|
|
35
|
-
preventUpdate: ['
|
|
33
|
+
preventUpdate: ['Canvas'],
|
|
36
34
|
preventUpdateTriggerStateUpdate: true
|
|
37
35
|
// preventContentUpdate: true,
|
|
38
36
|
// preventUpdate: ['MainHeaderCaptions', 'HeaderSubAside']
|
|
39
37
|
},
|
|
40
|
-
preventUpdate: ['
|
|
38
|
+
preventUpdate: ['Canvas', 'Modal'],
|
|
41
39
|
setOptions: {},
|
|
42
40
|
scrollToOffset: 120,
|
|
43
41
|
scrollToOptions: { behavior: 'smooth' }
|
|
44
42
|
}
|
|
45
43
|
|
|
46
|
-
export
|
|
44
|
+
export function router (
|
|
47
45
|
path = '/',
|
|
48
|
-
|
|
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
|
|
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
|
|
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
|
|
87
|
+
const isModal = !!element.call('isModalRoute', pathname)
|
|
90
88
|
|
|
91
89
|
if (pathChanged || !hashChanged) {
|
|
92
90
|
// const rootRouteHasChanged = rootRoute !== element.state.rootRoute
|
|
@@ -96,6 +94,7 @@ export const router = (
|
|
|
96
94
|
element.state.update({ route, hash, routeInContent, debugging: false }, {
|
|
97
95
|
preventUpdate: options.preventUpdate,
|
|
98
96
|
updateByRouter: true,
|
|
97
|
+
onlyUpdate: isModal && 'Modal',
|
|
99
98
|
...options.updateStateOptions
|
|
100
99
|
})
|
|
101
100
|
}
|
|
@@ -118,14 +117,10 @@ export const router = (
|
|
|
118
117
|
}
|
|
119
118
|
element.content.__ref.__componentKey = route
|
|
120
119
|
}
|
|
121
|
-
|
|
122
|
-
if (!isModal && element.Modal?.content) {
|
|
123
|
-
element.Modal.removeContent()
|
|
124
|
-
}
|
|
125
120
|
}
|
|
126
121
|
|
|
127
122
|
const rootNode = element.node
|
|
128
|
-
const scrollNode = options.scrollDocument ? document.documentElement : rootNode
|
|
123
|
+
const scrollNode = options.scrollDocument ? options.window.document.documentElement : rootNode
|
|
129
124
|
if (options.scrollToTop) {
|
|
130
125
|
scrollNode.scrollTo({
|
|
131
126
|
...(options.scrollToOptions || {}), top: 0, left: 0
|
|
@@ -138,7 +133,7 @@ export const router = (
|
|
|
138
133
|
}
|
|
139
134
|
|
|
140
135
|
if (hash) {
|
|
141
|
-
const activeNode = document.getElementById(hash)
|
|
136
|
+
const activeNode = options.window.document.getElementById(hash.slice(1))
|
|
142
137
|
if (activeNode) {
|
|
143
138
|
const top = activeNode.getBoundingClientRect().top + rootNode.scrollTop - options.scrollToOffset || 0
|
|
144
139
|
scrollNode.scrollTo({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@symbo.ls/router",
|
|
3
|
-
"version": "2.12.
|
|
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": "
|
|
14
|
+
"gitHead": "04d5f0f5019789ef7a8367f5850862d6a976eb66",
|
|
15
15
|
"source": "index.js"
|
|
16
16
|
}
|