Skip to content

Commit 2f4616f

Browse files
babu-chclaude
andcommitted
Add per-package READMEs and bump to 0.1.1
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent dfe0f9d commit 2f4616f

8 files changed

Lines changed: 171 additions & 4 deletions

File tree

packages/core/README.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# link-interceptor
2+
3+
Framework-agnostic core for intercepting all `<a>` tag clicks in your SPA. Provides callbacks for internal and external links with URL mutation support.
4+
5+
For framework-specific wrappers, see:
6+
- [vue-link-interceptor](https://www.npmjs.com/package/vue-link-interceptor) — Vue 3 plugin
7+
- [react-link-interceptor](https://www.npmjs.com/package/react-link-interceptor) — React hook
8+
- [svelte-link-interceptor](https://www.npmjs.com/package/svelte-link-interceptor) — Svelte action
9+
10+
## Install
11+
12+
```bash
13+
npm install link-interceptor
14+
```
15+
16+
## Usage
17+
18+
```ts
19+
import { interceptLinks } from 'link-interceptor'
20+
21+
const cleanup = interceptLinks({
22+
onInternalLink(ctx) {
23+
ctx.preventDefault()
24+
history.pushState(null, '', ctx.path)
25+
},
26+
onExternalLink(ctx) {
27+
ctx.url.searchParams.set('utm_source', 'myapp')
28+
},
29+
})
30+
31+
// When done:
32+
cleanup()
33+
```
34+
35+
## API
36+
37+
### `interceptLinks(options): () => void`
38+
39+
Registers a capture-phase click listener on `document`. Returns a cleanup function.
40+
41+
### LinkContext
42+
43+
| Property | Type | Description |
44+
|----------|------|-------------|
45+
| `url` | `URL` | Parsed URL (mutable — changes reflected on `anchor.href`) |
46+
| `anchor` | `HTMLAnchorElement` | The clicked `<a>` element |
47+
| `event` | `MouseEvent` | The original click event |
48+
| `path` | `string` | `url.pathname + url.search + url.hash` |
49+
| `isExternal` | `boolean` | Whether the link is external |
50+
| `isModifierClick` | `boolean` | Whether Ctrl/Meta/Shift/Alt was held |
51+
| `preventDefault()` | `() => void` | Cancel the default navigation |
52+
53+
## License
54+
55+
[MIT](https://github.com/babu-ch/link-interceptor/blob/main/LICENSE)

packages/core/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "link-interceptor",
3-
"version": "0.1.0",
3+
"version": "0.1.1",
44
"description": "Intercept all <a> tag clicks in your SPA — framework-agnostic core for handling internal and external link navigation.",
55
"keywords": [
66
"anchor",
@@ -27,6 +27,7 @@
2727
"node": ">=18.0.0"
2828
},
2929
"files": [
30+
"README.md",
3031
"dist"
3132
],
3233
"type": "module",

packages/react/README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# react-link-interceptor
2+
3+
React hook to intercept all `<a>` tag clicks in your SPA. Handle internal routing and external link modifications with ease.
4+
5+
## Install
6+
7+
```bash
8+
npm install react-link-interceptor
9+
```
10+
11+
## Usage
12+
13+
```tsx
14+
import { useLinkInterceptor } from 'react-link-interceptor'
15+
16+
function App() {
17+
useLinkInterceptor({
18+
onInternalLink(ctx) {
19+
ctx.preventDefault()
20+
navigate(ctx.path) // react-router
21+
},
22+
onExternalLink(ctx) {
23+
ctx.url.searchParams.set('utm_source', 'myapp')
24+
},
25+
})
26+
return <div>...</div>
27+
}
28+
```
29+
30+
## Docs & Playground
31+
32+
https://babu-ch.github.io/link-interceptor/
33+
34+
## License
35+
36+
[MIT](https://github.com/babu-ch/link-interceptor/blob/main/LICENSE)

packages/react/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-link-interceptor",
3-
"version": "0.1.0",
3+
"version": "0.1.1",
44
"description": "React hook to intercept all <a> tag clicks in your SPA — handle internal routing and external link modifications with ease.",
55
"keywords": [
66
"anchor",
@@ -27,6 +27,7 @@
2727
"node": ">=18.0.0"
2828
},
2929
"files": [
30+
"README.md",
3031
"dist"
3132
],
3233
"type": "module",

packages/svelte/README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# svelte-link-interceptor
2+
3+
Svelte action to intercept all `<a>` tag clicks in your SPA. Handle internal routing and external link modifications with ease.
4+
5+
## Install
6+
7+
```bash
8+
npm install svelte-link-interceptor
9+
```
10+
11+
## Usage
12+
13+
```svelte
14+
<script>
15+
import { linkInterceptor } from 'svelte-link-interceptor'
16+
17+
const options = {
18+
onInternalLink(ctx) {
19+
ctx.preventDefault()
20+
goto(ctx.path) // SvelteKit
21+
},
22+
onExternalLink(ctx) {
23+
ctx.url.searchParams.set('utm_source', 'myapp')
24+
},
25+
}
26+
</script>
27+
28+
<div use:linkInterceptor={options}>
29+
...
30+
</div>
31+
```
32+
33+
## Docs & Playground
34+
35+
https://babu-ch.github.io/link-interceptor/
36+
37+
## License
38+
39+
[MIT](https://github.com/babu-ch/link-interceptor/blob/main/LICENSE)

packages/svelte/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "svelte-link-interceptor",
3-
"version": "0.1.0",
3+
"version": "0.1.1",
44
"description": "Svelte action to intercept all <a> tag clicks in your SPA — handle internal routing and external link modifications with ease.",
55
"keywords": [
66
"anchor",
@@ -27,6 +27,7 @@
2727
"node": ">=18.0.0"
2828
},
2929
"files": [
30+
"README.md",
3031
"dist"
3132
],
3233
"type": "module",

packages/vue/README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# vue-link-interceptor
2+
3+
Vue 3 plugin to intercept all `<a>` tag clicks in your SPA. Handle internal routing and external link modifications with ease.
4+
5+
## Install
6+
7+
```bash
8+
npm install vue-link-interceptor
9+
```
10+
11+
## Usage
12+
13+
```ts
14+
import { linkInterceptorPlugin } from 'vue-link-interceptor'
15+
16+
app.use(linkInterceptorPlugin, {
17+
onInternalLink(ctx) {
18+
ctx.preventDefault()
19+
router.push(ctx.path)
20+
},
21+
onExternalLink(ctx) {
22+
ctx.url.searchParams.set('utm_source', 'myapp')
23+
},
24+
})
25+
```
26+
27+
## Docs & Playground
28+
29+
https://babu-ch.github.io/link-interceptor/
30+
31+
## License
32+
33+
[MIT](https://github.com/babu-ch/link-interceptor/blob/main/LICENSE)

packages/vue/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-link-interceptor",
3-
"version": "0.1.0",
3+
"version": "0.1.1",
44
"description": "Vue 3 plugin to intercept all <a> tag clicks in your SPA — handle internal routing and external link modifications with ease.",
55
"keywords": [
66
"anchor",
@@ -28,6 +28,7 @@
2828
"node": ">=18.0.0"
2929
},
3030
"files": [
31+
"README.md",
3132
"dist"
3233
],
3334
"type": "module",

0 commit comments

Comments
 (0)