@johly/vaul-svelte 1.0.0-next.8

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 (53) hide show
  1. package/LICENSE +10 -0
  2. package/README.md +58 -0
  3. package/dist/components/drawer/drawer-content.svelte +60 -0
  4. package/dist/components/drawer/drawer-content.svelte.d.ts +5 -0
  5. package/dist/components/drawer/drawer-handle.svelte +31 -0
  6. package/dist/components/drawer/drawer-handle.svelte.d.ts +4 -0
  7. package/dist/components/drawer/drawer-nested.svelte +37 -0
  8. package/dist/components/drawer/drawer-nested.svelte.d.ts +3 -0
  9. package/dist/components/drawer/drawer-overlay.svelte +32 -0
  10. package/dist/components/drawer/drawer-overlay.svelte.d.ts +5 -0
  11. package/dist/components/drawer/drawer-portal.svelte +10 -0
  12. package/dist/components/drawer/drawer-portal.svelte.d.ts +3 -0
  13. package/dist/components/drawer/drawer.svelte +383 -0
  14. package/dist/components/drawer/drawer.svelte.d.ts +3 -0
  15. package/dist/components/drawer/index.d.ts +12 -0
  16. package/dist/components/drawer/index.js +11 -0
  17. package/dist/components/drawer/types.d.ts +126 -0
  18. package/dist/components/drawer/types.js +1 -0
  19. package/dist/components/index.d.ts +1 -0
  20. package/dist/components/index.js +1 -0
  21. package/dist/components/utils/mounted.svelte +12 -0
  22. package/dist/components/utils/mounted.svelte.d.ts +6 -0
  23. package/dist/context.d.ts +42 -0
  24. package/dist/context.js +2 -0
  25. package/dist/helpers.d.ts +16 -0
  26. package/dist/helpers.js +95 -0
  27. package/dist/index.d.ts +2 -0
  28. package/dist/index.js +2 -0
  29. package/dist/internal/browser.d.ts +8 -0
  30. package/dist/internal/browser.js +30 -0
  31. package/dist/internal/constants.d.ts +11 -0
  32. package/dist/internal/constants.js +11 -0
  33. package/dist/internal/noop.d.ts +1 -0
  34. package/dist/internal/noop.js +3 -0
  35. package/dist/internal/use-id.d.ts +4 -0
  36. package/dist/internal/use-id.js +8 -0
  37. package/dist/types.d.ts +12 -0
  38. package/dist/types.js +1 -0
  39. package/dist/use-drawer-content.svelte.js +187 -0
  40. package/dist/use-drawer-handle.svelte.d.ts +18 -0
  41. package/dist/use-drawer-handle.svelte.js +83 -0
  42. package/dist/use-drawer-overlay.svelte.d.ts +15 -0
  43. package/dist/use-drawer-overlay.svelte.js +40 -0
  44. package/dist/use-drawer-root.svelte.js +575 -0
  45. package/dist/use-position-fixed.svelte.d.ts +20 -0
  46. package/dist/use-position-fixed.svelte.js +114 -0
  47. package/dist/use-prevent-scroll.svelte.d.ts +15 -0
  48. package/dist/use-prevent-scroll.svelte.js +235 -0
  49. package/dist/use-scale-background.svelte.d.ts +1 -0
  50. package/dist/use-scale-background.svelte.js +57 -0
  51. package/dist/use-snap-points.svelte.d.ts +34 -0
  52. package/dist/use-snap-points.svelte.js +260 -0
  53. package/package.json +64 -0
@@ -0,0 +1,83 @@
1
+ import { useRefById } from "svelte-toolbelt";
2
+ import { DrawerContext } from "./context.js";
3
+ const LONG_HANDLE_PRESS_TIMEOUT = 250;
4
+ const DOUBLE_TAP_TIMEOUT = 120;
5
+ export function useDrawerHandle(opts) {
6
+ const ctx = DrawerContext.get();
7
+ useRefById({
8
+ id: opts.id,
9
+ ref: opts.ref,
10
+ deps: () => ctx.open.current,
11
+ });
12
+ let closeTimeoutId = null;
13
+ let shouldCancelInteraction = false;
14
+ function handleStartInteraction() {
15
+ closeTimeoutId = window.setTimeout(() => {
16
+ // Cancel click interaction on a long press
17
+ shouldCancelInteraction = true;
18
+ }, LONG_HANDLE_PRESS_TIMEOUT);
19
+ }
20
+ function handleCancelInteraction() {
21
+ if (closeTimeoutId) {
22
+ window.clearTimeout(closeTimeoutId);
23
+ }
24
+ shouldCancelInteraction = false;
25
+ }
26
+ function handleCycleSnapPoints() {
27
+ // Prevent accidental taps while resizing drawer
28
+ if (ctx.isDragging || opts.preventCycle.current || shouldCancelInteraction) {
29
+ handleCancelInteraction();
30
+ return;
31
+ }
32
+ // Make sure to clear the timeout id if the user releases the handle before the cancel timeout
33
+ handleCancelInteraction();
34
+ if (!ctx.snapPoints.current || ctx.snapPoints.current.length === 0) {
35
+ if (!ctx.dismissible.current) {
36
+ ctx.closeDrawer();
37
+ }
38
+ return;
39
+ }
40
+ const isLastSnapPoint = ctx.activeSnapPoint.current ===
41
+ ctx.snapPoints.current[ctx.snapPoints.current.length - 1];
42
+ if (isLastSnapPoint && ctx.dismissible.current) {
43
+ ctx.closeDrawer();
44
+ return;
45
+ }
46
+ const currentSnapIndex = ctx.snapPoints.current.findIndex((point) => point === ctx.activeSnapPoint.current);
47
+ if (currentSnapIndex === -1 || currentSnapIndex === undefined)
48
+ return; // activeSnapPoint not found in snapPoints
49
+ const nextSnapPoint = ctx.snapPoints.current[currentSnapIndex + 1];
50
+ ctx.activeSnapPoint.current = nextSnapPoint;
51
+ }
52
+ function handleStartCycle() {
53
+ if (shouldCancelInteraction) {
54
+ handleCancelInteraction();
55
+ return;
56
+ }
57
+ window.setTimeout(() => {
58
+ handleCycleSnapPoints();
59
+ }, DOUBLE_TAP_TIMEOUT);
60
+ }
61
+ const props = $derived({
62
+ id: opts.id.current,
63
+ "data-vaul-drawer-visible": ctx.open.current ? "true" : "false",
64
+ "data-vaul-handle": "",
65
+ "aria-hidden": "true",
66
+ onclick: handleStartCycle,
67
+ onpointercancel: handleCancelInteraction,
68
+ onpointerdown: (e) => {
69
+ if (ctx.handleOnly.current)
70
+ ctx.onPress(e);
71
+ handleStartInteraction();
72
+ },
73
+ onpointermove: (e) => {
74
+ if (ctx.handleOnly.current)
75
+ ctx.onDrag(e);
76
+ },
77
+ });
78
+ return {
79
+ get props() {
80
+ return props;
81
+ },
82
+ };
83
+ }
@@ -0,0 +1,15 @@
1
+ import { type WithRefProps } from "svelte-toolbelt";
2
+ type UseDrawerOverlayProps = WithRefProps;
3
+ export declare function useDrawerOverlay(opts: UseDrawerOverlayProps): {
4
+ readonly props: {
5
+ id: string;
6
+ onmouseup: (event: PointerEvent | null) => void;
7
+ "data-vaul-overlay": string;
8
+ "data-vaul-snap-points": string;
9
+ "data-vaul-snap-points-overlay": string;
10
+ "data-vaul-animate": string;
11
+ };
12
+ readonly shouldRender: boolean;
13
+ setMounted: (value: boolean) => void;
14
+ };
15
+ export {};
@@ -0,0 +1,40 @@
1
+ import { useRefById } from "svelte-toolbelt";
2
+ import { DrawerContext } from "./context.js";
3
+ export function useDrawerOverlay(opts) {
4
+ const ctx = DrawerContext.get();
5
+ let mounted = $state(false);
6
+ useRefById({
7
+ id: opts.id,
8
+ ref: opts.ref,
9
+ deps: () => mounted,
10
+ onRefChange: (node) => {
11
+ if (!mounted) {
12
+ ctx.setOverlayNode(null);
13
+ }
14
+ else {
15
+ ctx.setOverlayNode(node);
16
+ }
17
+ },
18
+ });
19
+ const hasSnapPoints = $derived(ctx.snapPoints.current && ctx.snapPoints.current.length > 0);
20
+ const shouldRender = $derived(ctx.modal.current);
21
+ const props = $derived({
22
+ id: opts.id.current,
23
+ onmouseup: ctx.onRelease,
24
+ "data-vaul-overlay": "",
25
+ "data-vaul-snap-points": ctx.open.current && hasSnapPoints ? "true" : "false",
26
+ "data-vaul-snap-points-overlay": ctx.open.current && ctx.shouldFade ? "true" : "false",
27
+ "data-vaul-animate": ctx.shouldAnimate ? "true" : "false",
28
+ });
29
+ return {
30
+ get props() {
31
+ return props;
32
+ },
33
+ get shouldRender() {
34
+ return shouldRender;
35
+ },
36
+ setMounted: (value) => {
37
+ mounted = value;
38
+ },
39
+ };
40
+ }