@keenmate/svelte-spa-router 1.0.3 → 1.0.5

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/Router.svelte +29 -23
  2. package/package.json +1 -1
package/Router.svelte CHANGED
@@ -220,24 +220,6 @@
220
220
 
221
221
  updateLink(node, opts)
222
222
 
223
- if (!get(HashRoutingEnabled)) {
224
- node.addEventListener("click", ev => {
225
- const linkTarget = ev.target.getAttribute("target")
226
- if (linkTarget && linkTarget !== "_self") {
227
- // prevent pushState when link is perhaps going outside of this window
228
- return
229
- }
230
-
231
- ev.stopImmediatePropagation()
232
- ev.preventDefault()
233
-
234
- const shouldReplace = typeof opts !== "string" && opts.shouldReplace
235
-
236
- jediForcePush(node.getAttribute("href"), shouldReplace)
237
- // window.dispatchEvent(new Event(SvelteSPARouterNavigationEvent))
238
- }, {capture: true})
239
- }
240
-
241
223
  return {
242
224
  update(updated) {
243
225
  updated = linkOpts(updated)
@@ -284,11 +266,35 @@
284
266
  }
285
267
 
286
268
  node.setAttribute("href", href)
287
- node.addEventListener("click", (event) => {
288
- // Prevent default anchor onclick behaviour
289
- event.preventDefault()
290
- if (!opts.disabled) {
291
- scrollstateHistoryHandler(event.currentTarget.getAttribute("href"))
269
+ node.addEventListener("click", ev => {
270
+ if (get(HashRoutingEnabled)) {
271
+ // Prevent default anchor onclick behaviour
272
+ ev.preventDefault()
273
+ if (!opts.disabled) {
274
+ scrollstateHistoryHandler(ev.currentTarget.getAttribute("href"))
275
+ }
276
+ } else {
277
+ console.log("Handling link click event")
278
+ const linkTarget = ev.target.getAttribute("target")
279
+ if (linkTarget && linkTarget !== "_self") {
280
+ console.log("Link has special target attr, opening href instead")
281
+ // prevent pushState when link is perhaps going outside of this window
282
+ window.open(node.getAttribute("href"), linkTarget)
283
+
284
+ return
285
+ }
286
+ if (ev.ctrlKey || ev.shiftKey || ev.metaKey) {
287
+ console.log("Modifier key has been held while opening link, keeping behaviour intact")
288
+ return
289
+ }
290
+
291
+ console.log("Custom link operation is in place")
292
+ ev.preventDefault()
293
+
294
+ const shouldReplace = typeof opts !== "string" && opts.shouldReplace
295
+
296
+ jediForcePush(node.getAttribute("href"), shouldReplace)
297
+ // window.dispatchEvent(new Event(SvelteSPARouterNavigationEvent))
292
298
  }
293
299
  })
294
300
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@keenmate/svelte-spa-router",
3
3
  "private": false,
4
- "version": "1.0.3",
4
+ "version": "1.0.5",
5
5
  "description": "Router for SPAs using Svelte 4",
6
6
  "main": "Router.svelte",
7
7
  "svelte": "Router.svelte",