@sveltek/attachments 0.1.0 → 0.2.0

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 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,44 @@ interface KeyboardOptions {
34
34
  keys?: string[];
35
35
  }
36
36
 
37
- export { clickOutside, keyboard };
38
- export type { ClickOutsideOptions, KeyboardOptions };
37
+ declare function preventScroll(options?: PreventScrollOptions): Attachment;
38
+
39
+ interface PreventScrollOptions {
40
+ wheel?: {
41
+ /**
42
+ * @default true
43
+ */
44
+ enable?: boolean;
45
+ /**
46
+ * @default this
47
+ */
48
+ target?: Element | Document | Window;
49
+ };
50
+ touchmove?: {
51
+ /**
52
+ * @default true
53
+ */
54
+ enable?: boolean;
55
+ /**
56
+ * @default this
57
+ */
58
+ target?: Element | Document | Window;
59
+ };
60
+ keydown?: {
61
+ /**
62
+ * @default true
63
+ */
64
+ enable?: boolean;
65
+ /**
66
+ * @default document
67
+ */
68
+ target?: Element | Document | Window;
69
+ /**
70
+ * @default ['ArrowLeft','ArrowRight','ArrowUp','ArrowDown','PageDown','PageUp','Home','End',' '],
71
+ */
72
+ keys?: string[];
73
+ };
74
+ }
75
+
76
+ export { clickOutside, keyboard, preventScroll };
77
+ export type { ClickOutsideOptions, KeyboardOptions, PreventScrollOptions };
package/dist/index.mjs CHANGED
@@ -29,4 +29,48 @@ function keyboard(callback, options = {}) {
29
29
  };
30
30
  }
31
31
 
32
- export { clickOutside, keyboard };
32
+ function preventScroll(options = {}) {
33
+ return (el) => {
34
+ const {
35
+ wheel: { enable: wheelEnable = true, target: wheelTarget = el } = {},
36
+ touchmove: { enable: touchEnable = true, target: touchTarget = el } = {},
37
+ keydown: {
38
+ enable: keyEnable = true,
39
+ target: keyTarget = document,
40
+ keys = [
41
+ "ArrowLeft",
42
+ "ArrowRight",
43
+ "ArrowUp",
44
+ "ArrowDown",
45
+ "PageDown",
46
+ "PageUp",
47
+ "Home",
48
+ "End",
49
+ " "
50
+ ]
51
+ } = {}
52
+ } = options;
53
+ const handler = (e) => e.preventDefault();
54
+ const handlerKey = (e) => {
55
+ if (keys.includes(e.key)) e.preventDefault();
56
+ };
57
+ if (wheelEnable) {
58
+ wheelTarget.addEventListener("wheel", handler, { passive: false });
59
+ }
60
+ if (touchEnable) {
61
+ touchTarget.addEventListener("touchmove", handler, { passive: false });
62
+ }
63
+ if (keyEnable) {
64
+ keyTarget.addEventListener("keydown", handlerKey);
65
+ }
66
+ return () => {
67
+ if (wheelEnable) wheelTarget.removeEventListener("wheel", handler);
68
+ if (touchEnable) touchTarget.removeEventListener("touchmove", handler);
69
+ if (keyEnable) {
70
+ keyTarget.removeEventListener("keydown", handlerKey);
71
+ }
72
+ };
73
+ };
74
+ }
75
+
76
+ export { clickOutside, keyboard, preventScroll };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sveltek/attachments",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "author": "Sveltek",
5
5
  "description": "A collection of custom attachments for Svelte.",
6
6
  "license": "MIT",
@@ -47,15 +47,15 @@
47
47
  "devDependencies": {
48
48
  "@hypernym/bundler": "^0.14.4",
49
49
  "@sveltejs/adapter-static": "^3.0.8",
50
- "@sveltejs/kit": "^2.25.1",
50
+ "@sveltejs/kit": "^2.27.2",
51
51
  "@sveltek/eslint-config": "^1.1.1",
52
52
  "@sveltek/prettier-config": "^1.0.4",
53
- "@types/node": "^24.0.15",
54
- "eslint": "^9.31.0",
53
+ "@types/node": "^24.2.0",
54
+ "eslint": "^9.32.0",
55
55
  "prettier": "^3.6.2",
56
- "svelte": "^5.36.13",
56
+ "svelte": "^5.38.0",
57
57
  "typescript": "^5.8.3",
58
- "vite": "^7.0.5"
58
+ "vite": "^7.1.0"
59
59
  },
60
60
  "scripts": {
61
61
  "build": "hyperbundler",