@keenmate/svelte-spa-router 1.0.4 → 1.0.6

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 +30 -25
  2. package/package.json +1 -1
package/Router.svelte CHANGED
@@ -220,26 +220,6 @@
220
220
 
221
221
  updateLink(node, opts)
222
222
 
223
- if (!get(HashRoutingEnabled)) {
224
- node.addEventListener("click", ev => {
225
- ev.stopImmediatePropagation()
226
- ev.preventDefault()
227
-
228
- const linkTarget = ev.target.getAttribute("target")
229
- if (linkTarget && linkTarget !== "_self") {
230
- // prevent pushState when link is perhaps going outside of this window
231
- window.open(node.getAttribute("href"), linkTarget)
232
-
233
- return
234
- }
235
-
236
- const shouldReplace = typeof opts !== "string" && opts.shouldReplace
237
-
238
- jediForcePush(node.getAttribute("href"), shouldReplace)
239
- // window.dispatchEvent(new Event(SvelteSPARouterNavigationEvent))
240
- }, {capture: true})
241
- }
242
-
243
223
  return {
244
224
  update(updated) {
245
225
  updated = linkOpts(updated)
@@ -286,11 +266,36 @@
286
266
  }
287
267
 
288
268
  node.setAttribute("href", href)
289
- node.addEventListener("click", (event) => {
290
- // Prevent default anchor onclick behaviour
291
- event.preventDefault()
292
- if (!opts.disabled) {
293
- 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
+ ev.preventDefault()
282
+ // prevent pushState when link is perhaps going outside of this window
283
+ window.open(node.getAttribute("href"), linkTarget)
284
+
285
+ return
286
+ }
287
+ if (ev.ctrlKey || ev.shiftKey || ev.metaKey) {
288
+ // console.log("Modifier key has been held while opening link, keeping behaviour intact")
289
+ return
290
+ }
291
+
292
+ // console.log("Custom link operation is in place")
293
+ ev.preventDefault()
294
+
295
+ const shouldReplace = typeof opts !== "string" && opts.shouldReplace
296
+
297
+ jediForcePush(node.getAttribute("href"), shouldReplace)
298
+ // window.dispatchEvent(new Event(SvelteSPARouterNavigationEvent))
294
299
  }
295
300
  })
296
301
  }
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.4",
4
+ "version": "1.0.6",
5
5
  "description": "Router for SPAs using Svelte 4",
6
6
  "main": "Router.svelte",
7
7
  "svelte": "Router.svelte",