@symbo.ls/router 2.34.34 → 3.1.1

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 +14 -31
  2. package/package.json +3 -3
package/index.js CHANGED
@@ -51,25 +51,12 @@ const defaultOptions = {
51
51
  scrollToOptions: { behavior: 'smooth' }
52
52
  }
53
53
 
54
- const lastElement = {}
55
-
56
54
  // eslint-disable-next-line default-param-last
57
- export async function router(path = '/', el, state = {}, passedOptions = {}) {
58
- const rootElem = this && this.getRoot()
59
- const element = el && el.routes ? el : rootElem
55
+ export async function router (path = '/', el, state = {}, passedOptions = {}) {
56
+ const element = el || (this && this.getRoot())
60
57
  const options = merge(passedOptions, defaultOptions)
61
58
  lastLevel = options.level
62
59
 
63
- const isModal = element.getRootState('activeModal')
64
- if (isModal) {
65
- if (options.event) {
66
- options.event.preventDefault()
67
- options.event.stopPropagation()
68
- }
69
- element.call('closeModal')
70
- if (options.event) {options.event.preventDefault()}
71
- }
72
-
73
60
  const urlObj = new options.window.URL(options.window.location.origin + path)
74
61
  const { pathname, search, hash } = urlObj
75
62
 
@@ -86,7 +73,10 @@ export async function router(path = '/', el, state = {}, passedOptions = {}) {
86
73
  const route = routeArray.join('/').replace('//', '/')
87
74
  const routeInContent = `/${routeArray[lastLevel + 1] || ''}`
88
75
 
89
- const content = element.routes[routeInContent] || element.routes['/*']
76
+ // const isPreview = location.pathname.includes('/editor')
77
+
78
+ const pages = element.routes || element.context.pages
79
+ const content = pages[routeInContent] || pages['/*']
90
80
 
91
81
  const wasModal = element.call(
92
82
  'isModalRoute',
@@ -103,7 +93,7 @@ export async function router(path = '/', el, state = {}, passedOptions = {}) {
103
93
  ) {
104
94
  return
105
95
  }
106
- if (options.pushState && options.level === 0) {
96
+ if (options.pushState) {
107
97
  options.window.history.pushState(
108
98
  {
109
99
  prevUrl: options.window.location.href,
@@ -114,48 +104,41 @@ export async function router(path = '/', el, state = {}, passedOptions = {}) {
114
104
  )
115
105
  }
116
106
 
107
+ const isModal = Boolean(element.call('isModalRoute', pathname))
108
+
117
109
  if (pathChanged || !hashChanged) {
118
110
  // || (!rootRouteHasChanged && { preventUpdateTriggerStateUpdate: true, preventContentUpdate: true })
119
- // console.log('ROUTER SETTING')
120
111
 
121
112
  if (options.updateState) {
122
113
  await element.state.update(
123
114
  { route, hash, routeInContent, debugging: false },
124
115
  {
125
116
  preventUpdate: [options.preventUpdate, 'content'],
126
- // preventContentUpdate: true, // prevent only platform.content
127
117
  updateByRouter: true,
118
+ onlyUpdate: isModal && 'Modal',
128
119
  ...options.updateStateOptions
129
120
  }
130
121
  )
131
122
  }
132
123
 
133
- const hasSet = isInitial || !isInitial
124
+ const hasSet = isInitial || (!isInitial && !isModal)
134
125
  if (hasSet) {
135
- if (
136
- element.content &&
137
- (options.forceContentUpdate || (!isInitial && wasModal))
138
- ) {
139
- await element.content?.update(
126
+ if (options.forceContentUpdate || (!isInitial && wasModal)) {
127
+ await element.content.update(
140
128
  {},
141
129
  {
142
130
  preventUpdate: options.preventUpdate
143
131
  }
144
132
  )
145
133
  } else {
146
- lastElement.content = content
147
- element.removeContent()
148
134
  await element.set(
149
135
  {
150
136
  tag: options.useFragment && 'fragment',
151
- extend: content
137
+ extends: content
152
138
  },
153
139
  {
154
140
  // ...(!isInitial && wasModal && !options.forceContentUpdate && { preventContentUpdate: true }),
155
- lastElement,
156
- routerContentElement: content,
157
141
  preventUpdate: options.preventUpdate,
158
-
159
142
  ...options.setOptions
160
143
  }
161
144
  )
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@symbo.ls/router",
3
- "version": "2.34.34",
3
+ "version": "3.1.1",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -8,8 +8,8 @@
8
8
  "vpatch": "npm version patch && npm publish --access public"
9
9
  },
10
10
  "dependencies": {
11
- "@domql/utils": "^2.34.34"
11
+ "@domql/utils": "^3.1.1"
12
12
  },
13
- "gitHead": "597f4c9a825058204d2e92c904d125ebbd58cc5c",
13
+ "gitHead": "39fb7a8c07355468ccce79e2f787ca3fa0715692",
14
14
  "source": "index.js"
15
15
  }