@symbo.ls/router 2.12.58 → 2.12.61

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