@symbo.ls/router 2.12.60 → 2.12.62

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 +27 -17
  2. package/package.json +2 -2
package/index.js CHANGED
@@ -3,8 +3,7 @@
3
3
  import { setCookie } from '@domql/cookie'
4
4
  import { redirectBasedOnAuth } from '@symbo.ls/auth-redirect'
5
5
  import { isModalRoute } from '@symbo.ls/platform-utils'
6
-
7
- const { location } = window
6
+ import { deepMerge } from '@domql/utils'
8
7
 
9
8
  export const getActiveRoute = (level = 0, route = window.location.pathname) => {
10
9
  const routeArray = route.split('/')
@@ -31,6 +30,13 @@ const defaultOptions = {
31
30
  useFragment: false,
32
31
  authCheck: true,
33
32
  updateState: true,
33
+ updateStateOptions: {
34
+ preventUpdateTriggerStateUpdate: true,
35
+ preventContentUpdate: true,
36
+ preventUpdate: ['Modal', 'MainHeaderCaptions', 'HeaderSubAside']
37
+ },
38
+ preventUpdate: ['MainHeaderCaptions', 'HeaderSubAside'],
39
+ setOptions: {},
34
40
  scrollToOffset: 120,
35
41
  scrollToOptions: { behavior: 'smooth' }
36
42
  }
@@ -41,7 +47,7 @@ export const router = (
41
47
  state = {},
42
48
  passedOptions = {}
43
49
  ) => {
44
- const options = { ...defaultOptions, ...passedOptions }
50
+ const options = deepMerge(passedOptions, defaultOptions)
45
51
  lastLevel = options.level
46
52
 
47
53
  const [pathname, hash] = path.split('#')
@@ -59,11 +65,11 @@ export const router = (
59
65
  const route = routeArray.join('/').replace('//', '/')
60
66
  const routeInContent = `/${routeArray[lastLevel + 1] || ''}`
61
67
 
62
- const isPreview = location.pathname.includes('/preview')
68
+ // const isPreview = location.pathname.includes('/editor')
63
69
 
64
70
  const content = element.routes[routeInContent] || element.routes['/*']
65
71
 
66
- const wasModal = isModalRoute(location.pathname.split('#')[0], element)
72
+ const wasModal = isModalRoute(window.location.pathname.split('#')[0], element)
67
73
  const isInitial = options.initialRender
68
74
  const hashChanged = hash && hash !== window.location.hash.slice(1)
69
75
  const pathChanged = pathname !== lastPathname
@@ -84,27 +90,31 @@ export const router = (
84
90
  // || (!rootRouteHasChanged && { preventUpdateTriggerStateUpdate: true, preventContentUpdate: true })
85
91
 
86
92
  if (options.updateState) {
87
- element.state.update({
88
- route, hash, routeInContent
89
- }, {
90
- preventUpdateTriggerStateUpdate: true,
91
- preventContentUpdate: true,
92
- preventUpdate: ['Modal', 'MainHeaderCaptions', 'HeaderSubAside']
93
+ element.state.update({ route, hash, routeInContent }, {
94
+ preventUpdate: options.preventUpdate,
95
+ ...options.updateStateOptions
93
96
  })
94
97
  }
95
98
 
96
99
  if (!isModal && element.Modal) {
97
100
  element.Modal.removeContent()
101
+ } else if (isModal && element.content?.Tabs) {
102
+ element.content.Tabs.update()
98
103
  }
99
104
 
100
105
  if (hasSet) {
101
- element.set({
102
- tag: options.useFragment && 'fragment',
103
- extend: content
104
- }, {
106
+ if (options.forceContentUpdate || (!isInitial && wasModal)) {
107
+ element.content.update()
108
+ } else {
109
+ element.set({
110
+ tag: options.useFragment && 'fragment',
111
+ extend: content
112
+ }, {
105
113
  // ...(!isInitial && wasModal && !options.forceContentUpdate && { preventContentUpdate: true }),
106
- preventUpdate: ['MainHeaderCaptions', 'HeaderSubAside']
107
- })
114
+ preventUpdate: options.preventUpdate,
115
+ ...options.setOptions
116
+ })
117
+ }
108
118
  }
109
119
  }
110
120
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@symbo.ls/router",
3
- "version": "2.12.60",
3
+ "version": "2.12.62",
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": "fb7db9d1214620c4cd3c107c4d9bd296b7d90f66",
14
+ "gitHead": "c4a5ed5b900cf83573a4b15c5c86dc4a568fd589",
15
15
  "source": "index.js"
16
16
  }