@symbo.ls/router 2.12.111 → 2.12.113
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 +73 -37
- package/location.js +7 -0
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -1,15 +1,23 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
import * as utils from '@domql/utils'
|
|
4
|
-
const { setCookie, merge } =
|
|
4
|
+
const { setCookie, merge } = utils.default || utils
|
|
5
5
|
|
|
6
|
-
export
|
|
6
|
+
export * from './location.js'
|
|
7
|
+
|
|
8
|
+
export const getLocationPath = (
|
|
9
|
+
index = 0,
|
|
10
|
+
route = window.location.pathname
|
|
11
|
+
) => {
|
|
7
12
|
const routeArray = route.split('/')
|
|
8
13
|
const activeRoute = routeArray[index + 1]
|
|
9
14
|
if (activeRoute) return `/${activeRoute}`
|
|
10
15
|
}
|
|
11
16
|
|
|
12
|
-
export const getLastLocationPath = (
|
|
17
|
+
export const getLastLocationPath = (
|
|
18
|
+
level = 0,
|
|
19
|
+
route = window.location.pathname
|
|
20
|
+
) => {
|
|
13
21
|
const routeArray = route.split('/')
|
|
14
22
|
const activeRoute = routeArray[routeArray.length - level - 1]
|
|
15
23
|
if (activeRoute) return `/${activeRoute}`
|
|
@@ -41,12 +49,7 @@ const defaultOptions = {
|
|
|
41
49
|
scrollToOptions: { behavior: 'smooth' }
|
|
42
50
|
}
|
|
43
51
|
|
|
44
|
-
export function router (
|
|
45
|
-
path = '/',
|
|
46
|
-
el,
|
|
47
|
-
state = {},
|
|
48
|
-
passedOptions = {}
|
|
49
|
-
) {
|
|
52
|
+
export function router (path = '/', el, state = {}, passedOptions = {}) {
|
|
50
53
|
const element = el || (this && this.getRoot())
|
|
51
54
|
const options = merge(passedOptions, defaultOptions)
|
|
52
55
|
lastLevel = options.level
|
|
@@ -71,17 +74,30 @@ export function router (
|
|
|
71
74
|
|
|
72
75
|
const content = element.routes[routeInContent] || element.routes['/*']
|
|
73
76
|
|
|
74
|
-
const wasModal = element.call(
|
|
77
|
+
const wasModal = element.call(
|
|
78
|
+
'isModalRoute',
|
|
79
|
+
options.window.location.pathname.split('#')[0]
|
|
80
|
+
)
|
|
75
81
|
const isInitial = options.initialRender
|
|
76
82
|
const hashChanged = hash && hash !== options.window.location.hash
|
|
77
83
|
const pathChanged = pathname !== lastPathname
|
|
78
84
|
lastPathname = pathname
|
|
79
85
|
|
|
80
|
-
if (
|
|
86
|
+
if (
|
|
87
|
+
!content ||
|
|
88
|
+
(element.state.root.debugging && !options.allowRouterWhileInspect)
|
|
89
|
+
) {
|
|
90
|
+
return
|
|
91
|
+
}
|
|
81
92
|
if (options.pushState) {
|
|
82
|
-
options.window.history.pushState(
|
|
83
|
-
|
|
84
|
-
|
|
93
|
+
options.window.history.pushState(
|
|
94
|
+
{
|
|
95
|
+
prevUrl: options.window.location.href,
|
|
96
|
+
...state
|
|
97
|
+
},
|
|
98
|
+
null,
|
|
99
|
+
route + (search ? `${search}` : '') + (hash ? `${hash}` : '')
|
|
100
|
+
)
|
|
85
101
|
}
|
|
86
102
|
|
|
87
103
|
const isModal = !!element.call('isModalRoute', pathname)
|
|
@@ -91,53 +107,73 @@ export function router (
|
|
|
91
107
|
// || (!rootRouteHasChanged && { preventUpdateTriggerStateUpdate: true, preventContentUpdate: true })
|
|
92
108
|
|
|
93
109
|
if (options.updateState) {
|
|
94
|
-
element.state.update(
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
110
|
+
element.state.update(
|
|
111
|
+
{ route, hash, routeInContent, debugging: false },
|
|
112
|
+
{
|
|
113
|
+
preventUpdate: options.preventUpdate,
|
|
114
|
+
updateByRouter: true,
|
|
115
|
+
onlyUpdate: isModal && 'Modal',
|
|
116
|
+
...options.updateStateOptions
|
|
117
|
+
}
|
|
118
|
+
)
|
|
100
119
|
}
|
|
101
120
|
|
|
102
121
|
const hasSet = isInitial || (!isInitial && !isModal)
|
|
103
122
|
if (hasSet) {
|
|
104
123
|
if (options.forceContentUpdate || (!isInitial && wasModal)) {
|
|
105
|
-
element.content.update(
|
|
106
|
-
|
|
107
|
-
|
|
124
|
+
element.content.update(
|
|
125
|
+
{},
|
|
126
|
+
{
|
|
127
|
+
preventUpdate: options.preventUpdate
|
|
128
|
+
}
|
|
129
|
+
)
|
|
108
130
|
} else {
|
|
109
|
-
element.set(
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
131
|
+
element.set(
|
|
132
|
+
{
|
|
133
|
+
tag: options.useFragment && 'fragment',
|
|
134
|
+
extend: content
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
// ...(!isInitial && wasModal && !options.forceContentUpdate && { preventContentUpdate: true }),
|
|
138
|
+
preventUpdate: options.preventUpdate,
|
|
139
|
+
...options.setOptions
|
|
140
|
+
}
|
|
141
|
+
)
|
|
117
142
|
}
|
|
118
|
-
element.content.__ref.__componentKey = route
|
|
143
|
+
if (element.content) element.content.__ref.__componentKey = route
|
|
119
144
|
}
|
|
120
145
|
}
|
|
121
146
|
|
|
122
147
|
const rootNode = element.node
|
|
123
|
-
const scrollNode = options.scrollDocument
|
|
148
|
+
const scrollNode = options.scrollDocument
|
|
149
|
+
? options.window.document.documentElement
|
|
150
|
+
: rootNode
|
|
124
151
|
if (options.scrollToTop) {
|
|
125
152
|
scrollNode.scrollTo({
|
|
126
|
-
...(options.scrollToOptions || {}),
|
|
153
|
+
...(options.scrollToOptions || {}),
|
|
154
|
+
top: 0,
|
|
155
|
+
left: 0
|
|
127
156
|
})
|
|
128
157
|
}
|
|
129
158
|
if (options.scrollToNode) {
|
|
130
159
|
content.content.node.scrollTo({
|
|
131
|
-
...(options.scrollToOptions || {}),
|
|
160
|
+
...(options.scrollToOptions || {}),
|
|
161
|
+
top: 0,
|
|
162
|
+
left: 0
|
|
132
163
|
})
|
|
133
164
|
}
|
|
134
165
|
|
|
135
166
|
if (hash) {
|
|
136
167
|
const activeNode = options.window.document.getElementById(hash.slice(1))
|
|
137
168
|
if (activeNode) {
|
|
138
|
-
const top =
|
|
169
|
+
const top =
|
|
170
|
+
activeNode.getBoundingClientRect().top +
|
|
171
|
+
rootNode.scrollTop -
|
|
172
|
+
options.scrollToOffset || 0
|
|
139
173
|
scrollNode.scrollTo({
|
|
140
|
-
...(options.scrollToOptions || {}),
|
|
174
|
+
...(options.scrollToOptions || {}),
|
|
175
|
+
top,
|
|
176
|
+
left: 0
|
|
141
177
|
})
|
|
142
178
|
}
|
|
143
179
|
}
|
package/location.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@symbo.ls/router",
|
|
3
|
-
"version": "2.12.
|
|
3
|
+
"version": "2.12.113",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -12,6 +12,6 @@
|
|
|
12
12
|
"@domql/utils": "latest",
|
|
13
13
|
"@symbo.ls/auth-redirect": "latest"
|
|
14
14
|
},
|
|
15
|
-
"gitHead": "
|
|
15
|
+
"gitHead": "80b9cba1ca65e6636085e7c58dbeb062f923fdd7",
|
|
16
16
|
"source": "index.js"
|
|
17
17
|
}
|