@sveltek/attachments 0.1.0 → 0.2.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.
- package/README.md +1 -6
- package/dist/index.d.mts +53 -2
- package/dist/index.mjs +46 -1
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -30,12 +30,7 @@ npm install @sveltek/attachments
|
|
|
30
30
|
|
|
31
31
|
- [clickOutside](./src/attachments/click-outside/README.md) → Triggers a callback when clicking outside the target element.
|
|
32
32
|
- [keyboard](./src/attachments/keyboard/README.md) → Triggers a callback when a specified keyboard event occurs.
|
|
33
|
-
|
|
34
|
-
## Community
|
|
35
|
-
|
|
36
|
-
Feel free to ask questions or share new ideas.
|
|
37
|
-
|
|
38
|
-
Use the official [discussions](https://github.com/sveltek/attachments/discussions) to get involved.
|
|
33
|
+
- [preventScroll](./src/attachments/prevent-scroll/README.md) → Prevents scrolling on the target element.
|
|
39
34
|
|
|
40
35
|
## License
|
|
41
36
|
|
package/dist/index.d.mts
CHANGED
|
@@ -34,5 +34,56 @@ interface KeyboardOptions {
|
|
|
34
34
|
keys?: string[];
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
declare function preventScroll(options?: PreventScrollOptions): Attachment;
|
|
38
|
+
|
|
39
|
+
interface PreventScrollOptions {
|
|
40
|
+
/**
|
|
41
|
+
* @default undefined
|
|
42
|
+
*/
|
|
43
|
+
target?: Element | Document | Window;
|
|
44
|
+
/**
|
|
45
|
+
* @default (e: Event): void => e.preventDefault()
|
|
46
|
+
*/
|
|
47
|
+
handler?: (e: Event) => void;
|
|
48
|
+
/**
|
|
49
|
+
* @default (e: KeyboardEvent): void => { if (keys.includes(e.key)) e.preventDefault() }
|
|
50
|
+
*/
|
|
51
|
+
handlerKey?: (e: KeyboardEvent) => void;
|
|
52
|
+
wheel?: {
|
|
53
|
+
/**
|
|
54
|
+
* @default true
|
|
55
|
+
*/
|
|
56
|
+
enable?: boolean;
|
|
57
|
+
/**
|
|
58
|
+
* @default this
|
|
59
|
+
*/
|
|
60
|
+
target?: Element | Document | Window;
|
|
61
|
+
};
|
|
62
|
+
touchmove?: {
|
|
63
|
+
/**
|
|
64
|
+
* @default true
|
|
65
|
+
*/
|
|
66
|
+
enable?: boolean;
|
|
67
|
+
/**
|
|
68
|
+
* @default this
|
|
69
|
+
*/
|
|
70
|
+
target?: Element | Document | Window;
|
|
71
|
+
};
|
|
72
|
+
keydown?: {
|
|
73
|
+
/**
|
|
74
|
+
* @default true
|
|
75
|
+
*/
|
|
76
|
+
enable?: boolean;
|
|
77
|
+
/**
|
|
78
|
+
* @default document
|
|
79
|
+
*/
|
|
80
|
+
target?: Element | Document | Window;
|
|
81
|
+
/**
|
|
82
|
+
* @default ['ArrowLeft','ArrowRight','ArrowUp','ArrowDown','PageDown','PageUp','Home','End',' '],
|
|
83
|
+
*/
|
|
84
|
+
keys?: string[];
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export { clickOutside, keyboard, preventScroll };
|
|
89
|
+
export type { ClickOutsideOptions, KeyboardOptions, PreventScrollOptions };
|
package/dist/index.mjs
CHANGED
|
@@ -29,4 +29,49 @@ function keyboard(callback, options = {}) {
|
|
|
29
29
|
};
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
|
|
32
|
+
function preventScroll(options = {}) {
|
|
33
|
+
return (el) => {
|
|
34
|
+
const keys = options.keydown?.keys || [
|
|
35
|
+
"ArrowLeft",
|
|
36
|
+
"ArrowRight",
|
|
37
|
+
"ArrowUp",
|
|
38
|
+
"ArrowDown",
|
|
39
|
+
"PageDown",
|
|
40
|
+
"PageUp",
|
|
41
|
+
"Home",
|
|
42
|
+
"End",
|
|
43
|
+
" "
|
|
44
|
+
];
|
|
45
|
+
const {
|
|
46
|
+
target,
|
|
47
|
+
handler = (e) => e.preventDefault(),
|
|
48
|
+
handlerKey = (e) => {
|
|
49
|
+
if (keys.includes(e.key)) e.preventDefault();
|
|
50
|
+
},
|
|
51
|
+
wheel: { enable: wheelEnable = true, target: wheelEl = el } = {},
|
|
52
|
+
touchmove: { enable: touchEnable = true, target: touchEl = el } = {},
|
|
53
|
+
keydown: { enable: keyEnable = true, target: keyEl = document } = {}
|
|
54
|
+
} = options;
|
|
55
|
+
const wheelTarget = target || wheelEl;
|
|
56
|
+
const touchTarget = target || touchEl;
|
|
57
|
+
const keyTarget = target || keyEl;
|
|
58
|
+
if (wheelEnable) {
|
|
59
|
+
wheelTarget.addEventListener("wheel", handler, { passive: false });
|
|
60
|
+
}
|
|
61
|
+
if (touchEnable) {
|
|
62
|
+
touchTarget.addEventListener("touchmove", handler, { passive: false });
|
|
63
|
+
}
|
|
64
|
+
if (keyEnable) {
|
|
65
|
+
keyTarget.addEventListener("keydown", handlerKey);
|
|
66
|
+
}
|
|
67
|
+
return () => {
|
|
68
|
+
if (wheelEnable) wheelTarget.removeEventListener("wheel", handler);
|
|
69
|
+
if (touchEnable) touchTarget.removeEventListener("touchmove", handler);
|
|
70
|
+
if (keyEnable) {
|
|
71
|
+
keyTarget.removeEventListener("keydown", handlerKey);
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export { clickOutside, keyboard, preventScroll };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sveltek/attachments",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"author": "Sveltek",
|
|
5
5
|
"description": "A collection of custom attachments for Svelte.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -46,16 +46,16 @@
|
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"@hypernym/bundler": "^0.14.4",
|
|
49
|
-
"@sveltejs/adapter-static": "^3.0.
|
|
50
|
-
"@sveltejs/kit": "^2.
|
|
49
|
+
"@sveltejs/adapter-static": "^3.0.9",
|
|
50
|
+
"@sveltejs/kit": "^2.27.3",
|
|
51
51
|
"@sveltek/eslint-config": "^1.1.1",
|
|
52
52
|
"@sveltek/prettier-config": "^1.0.4",
|
|
53
|
-
"@types/node": "^24.0
|
|
54
|
-
"eslint": "^9.
|
|
53
|
+
"@types/node": "^24.2.0",
|
|
54
|
+
"eslint": "^9.32.0",
|
|
55
55
|
"prettier": "^3.6.2",
|
|
56
|
-
"svelte": "^5.
|
|
56
|
+
"svelte": "^5.38.0",
|
|
57
57
|
"typescript": "^5.8.3",
|
|
58
|
-
"vite": "^7.
|
|
58
|
+
"vite": "^7.1.1"
|
|
59
59
|
},
|
|
60
60
|
"scripts": {
|
|
61
61
|
"build": "hyperbundler",
|