@rodrigodagostino/svelte-draggable-drawer 0.1.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/LICENSE.md +21 -0
- package/README.md +18 -0
- package/dist/components/DraggableDrawer.svelte +103 -0
- package/dist/components/DraggableDrawer.svelte.d.ts +21 -0
- package/dist/components/DraggableDrawerBackdrop.svelte +41 -0
- package/dist/components/DraggableDrawerBackdrop.svelte.d.ts +16 -0
- package/dist/components/DraggableDrawerContent.svelte +57 -0
- package/dist/components/DraggableDrawerContent.svelte.d.ts +18 -0
- package/dist/components/DraggableDrawerHandle.svelte +25 -0
- package/dist/components/DraggableDrawerHandle.svelte.d.ts +18 -0
- package/dist/exports.d.ts +5 -0
- package/dist/exports.js +4 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/stores/coordinates.d.ts +25 -0
- package/dist/stores/coordinates.js +19 -0
- package/dist/stores/elements.d.ts +7 -0
- package/dist/stores/elements.js +19 -0
- package/dist/stores/index.d.ts +7 -0
- package/dist/stores/index.js +14 -0
- package/dist/stores/props.d.ts +3 -0
- package/dist/stores/props.js +7 -0
- package/dist/stores/states.d.ts +3 -0
- package/dist/stores/states.js +7 -0
- package/dist/styles.css +33 -0
- package/dist/types/coordinates.d.ts +14 -0
- package/dist/types/coordinates.js +1 -0
- package/dist/types/elements.d.ts +5 -0
- package/dist/types/elements.js +1 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/index.js +4 -0
- package/dist/types/props.d.ts +3 -0
- package/dist/types/props.js +1 -0
- package/dist/types/states.d.ts +1 -0
- package/dist/types/states.js +1 -0
- package/package.json +72 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Rodrigo D’Agostino
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+
|
|
5
|
+
# Svelte Draggable Drawer
|
|
6
|
+
|
|
7
|
+
A comprehensive package for creating accessible, draggable drawers in Svelte applications.
|
|
8
|
+
|
|
9
|
+
[](https://www.npmjs.com/package/@rodrigodagostino/svelte-draggable-drawer) [](https://github.com/rodrigodagostino/svelte-draggable-drawer/releases/latest) [](LICENSE.md) [](https://app.netlify.com/projects/svelte-draggable-drawer/deploys)
|
|
10
|
+
|
|
11
|
+
</div>
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## Live demos
|
|
16
|
+
|
|
17
|
+
- [Netlify](https://svelte-draggable-drawer.netlify.app)
|
|
18
|
+
- [Cloudflare](https://svelte-draggable-drawer.pages.dev/)
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
<script>import { onDestroy } from "svelte";
|
|
2
|
+
import {
|
|
3
|
+
setContent,
|
|
4
|
+
setContentOrigin,
|
|
5
|
+
setDragState,
|
|
6
|
+
setHandle,
|
|
7
|
+
setPointer,
|
|
8
|
+
setPointerOrigin,
|
|
9
|
+
setRootProps
|
|
10
|
+
} from "../stores/index.js";
|
|
11
|
+
export let isOpen = false;
|
|
12
|
+
const rootProps = setRootProps({ isOpen });
|
|
13
|
+
$: $rootProps = { isOpen };
|
|
14
|
+
const unsubscribe = rootProps.subscribe((value) => {
|
|
15
|
+
isOpen = value.isOpen;
|
|
16
|
+
});
|
|
17
|
+
onDestroy(unsubscribe);
|
|
18
|
+
let pointerId = null;
|
|
19
|
+
const pointer = setPointer(null);
|
|
20
|
+
const pointerOrigin = setPointerOrigin(null);
|
|
21
|
+
const content = setContent(null);
|
|
22
|
+
const contentOrigin = setContentOrigin(null);
|
|
23
|
+
const handle = setHandle(null);
|
|
24
|
+
const dragState = setDragState("idle");
|
|
25
|
+
const TOP_THRESHOLD = 2 / 5;
|
|
26
|
+
const BOTTOM_THRESHOLD = 3 / 5;
|
|
27
|
+
let transitionTimeoutId = null;
|
|
28
|
+
function handlePointerDown(e) {
|
|
29
|
+
const target = e.target;
|
|
30
|
+
if (!$handle || !target.closest('[data-role="handle"]') || !$content) return;
|
|
31
|
+
pointerId = e.pointerId;
|
|
32
|
+
$handle.setPointerCapture(pointerId);
|
|
33
|
+
$pointer = { x: e.clientX, y: e.clientY };
|
|
34
|
+
$pointerOrigin = { x: e.clientX, y: e.clientY };
|
|
35
|
+
$contentOrigin = $content.getBoundingClientRect();
|
|
36
|
+
$dragState = "drag-start";
|
|
37
|
+
$handle.addEventListener("pointermove", handlePointerMove);
|
|
38
|
+
$handle.addEventListener(
|
|
39
|
+
"pointerup",
|
|
40
|
+
() => {
|
|
41
|
+
$handle.removeEventListener("pointermove", handlePointerMove);
|
|
42
|
+
handlePointerUp();
|
|
43
|
+
},
|
|
44
|
+
{ once: true }
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
async function handlePointerMove({ clientX, clientY }) {
|
|
48
|
+
if (!$content || !$pointerOrigin) return;
|
|
49
|
+
$dragState = "drag";
|
|
50
|
+
$pointer = { x: clientX, y: clientY };
|
|
51
|
+
$rootProps.isOpen = $pointerOrigin.y > window.innerHeight / 2 ? clientY < window.innerHeight * BOTTOM_THRESHOLD : clientY < window.innerHeight * TOP_THRESHOLD;
|
|
52
|
+
}
|
|
53
|
+
function handlePointerUp() {
|
|
54
|
+
if (!$pointerOrigin || !$content) return;
|
|
55
|
+
$dragState = "drop";
|
|
56
|
+
function handleTransitionEnd({ propertyName }) {
|
|
57
|
+
if (propertyName === "transform") {
|
|
58
|
+
handlePointerAndKeyboardDragEnd();
|
|
59
|
+
$content?.removeEventListener("transitionend", handleTransitionEnd);
|
|
60
|
+
if (transitionTimeoutId) {
|
|
61
|
+
clearTimeout(transitionTimeoutId);
|
|
62
|
+
transitionTimeoutId = null;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
$content?.addEventListener("transitionend", handleTransitionEnd);
|
|
67
|
+
transitionTimeoutId = setTimeout(() => {
|
|
68
|
+
handlePointerAndKeyboardDragEnd();
|
|
69
|
+
$content?.removeEventListener("transitionend", handleTransitionEnd);
|
|
70
|
+
transitionTimeoutId = null;
|
|
71
|
+
}, 400 + 100);
|
|
72
|
+
}
|
|
73
|
+
async function handlePointerAndKeyboardDragEnd() {
|
|
74
|
+
if (pointerId) $content?.releasePointerCapture(pointerId);
|
|
75
|
+
$pointerOrigin = null;
|
|
76
|
+
$contentOrigin = null;
|
|
77
|
+
$dragState = "idle";
|
|
78
|
+
}
|
|
79
|
+
</script>
|
|
80
|
+
|
|
81
|
+
<div class="sdd-root" data-drag-state={$dragState} on:pointerdown={handlePointerDown}>
|
|
82
|
+
<slot />
|
|
83
|
+
</div>
|
|
84
|
+
|
|
85
|
+
<style>
|
|
86
|
+
.sdd-root {
|
|
87
|
+
position: fixed;
|
|
88
|
+
inset: 0;
|
|
89
|
+
pointer-events: none;
|
|
90
|
+
z-index: 9999;
|
|
91
|
+
|
|
92
|
+
&:not(:has([data-role='handle'])),
|
|
93
|
+
& [data-role='handle'] {
|
|
94
|
+
touch-action: none;
|
|
95
|
+
cursor: grab;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
&[data-drag-state*='drag'],
|
|
99
|
+
&[data-drag-state*='drag'] [data-role='handle'] {
|
|
100
|
+
cursor: grabbing;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
</style>
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { SvelteComponent } from "svelte";
|
|
2
|
+
import type { RootProps } from '../exports.js';
|
|
3
|
+
declare const __propDef: {
|
|
4
|
+
props: {
|
|
5
|
+
isOpen?: RootProps["isOpen"];
|
|
6
|
+
};
|
|
7
|
+
events: {
|
|
8
|
+
[evt: string]: CustomEvent<any>;
|
|
9
|
+
};
|
|
10
|
+
slots: {
|
|
11
|
+
default: {};
|
|
12
|
+
};
|
|
13
|
+
exports?: {} | undefined;
|
|
14
|
+
bindings?: string | undefined;
|
|
15
|
+
};
|
|
16
|
+
export type DraggableDrawerProps = typeof __propDef.props;
|
|
17
|
+
export type DraggableDrawerEvents = typeof __propDef.events;
|
|
18
|
+
export type DraggableDrawerSlots = typeof __propDef.slots;
|
|
19
|
+
export default class DraggableDrawer extends SvelteComponent<DraggableDrawerProps, DraggableDrawerEvents, DraggableDrawerSlots> {
|
|
20
|
+
}
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
<script>import { getPointer, getRootProps } from "../stores/index.js";
|
|
2
|
+
import { getDragState } from "../stores/states.js";
|
|
3
|
+
let offsetHeight;
|
|
4
|
+
const rootProps = getRootProps();
|
|
5
|
+
const pointer = getPointer();
|
|
6
|
+
const dragState = getDragState();
|
|
7
|
+
function getStyleOpacity(...args) {
|
|
8
|
+
if ($dragState === "drag" && $pointer) {
|
|
9
|
+
return ($pointer.y / offsetHeight / 2 - 0.5) * -1;
|
|
10
|
+
}
|
|
11
|
+
if ($rootProps.isOpen) return 0.5;
|
|
12
|
+
return 0;
|
|
13
|
+
}
|
|
14
|
+
function getStyleTransition(...args) {
|
|
15
|
+
if ($dragState !== "drag-start" && $dragState !== "drag") return "opacity 240ms";
|
|
16
|
+
return "none";
|
|
17
|
+
}
|
|
18
|
+
$: styleOpacity = getStyleOpacity($pointer, $dragState, $rootProps.isOpen);
|
|
19
|
+
$: styleTransition = getStyleTransition($dragState);
|
|
20
|
+
const handleClick = () => {
|
|
21
|
+
$rootProps.isOpen = false;
|
|
22
|
+
};
|
|
23
|
+
</script>
|
|
24
|
+
|
|
25
|
+
<div
|
|
26
|
+
bind:offsetHeight
|
|
27
|
+
class="sdd-backdrop"
|
|
28
|
+
style:opacity={styleOpacity}
|
|
29
|
+
style:transition={styleTransition}
|
|
30
|
+
style:pointer-events={$rootProps.isOpen ? 'auto' : 'none'}
|
|
31
|
+
aria-hidden="true"
|
|
32
|
+
on:click={handleClick}
|
|
33
|
+
></div>
|
|
34
|
+
|
|
35
|
+
<style>
|
|
36
|
+
.sdd-backdrop {
|
|
37
|
+
position: fixed;
|
|
38
|
+
inset: 0;
|
|
39
|
+
z-index: 0;
|
|
40
|
+
}
|
|
41
|
+
</style>
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { SvelteComponent } from "svelte";
|
|
2
|
+
declare const __propDef: {
|
|
3
|
+
props: Record<string, never>;
|
|
4
|
+
events: {
|
|
5
|
+
[evt: string]: CustomEvent<any>;
|
|
6
|
+
};
|
|
7
|
+
slots: {};
|
|
8
|
+
exports?: {} | undefined;
|
|
9
|
+
bindings?: string | undefined;
|
|
10
|
+
};
|
|
11
|
+
export type DraggableDrawerBackdropProps = typeof __propDef.props;
|
|
12
|
+
export type DraggableDrawerBackdropEvents = typeof __propDef.events;
|
|
13
|
+
export type DraggableDrawerBackdropSlots = typeof __propDef.slots;
|
|
14
|
+
export default class DraggableDrawerBackdrop extends SvelteComponent<DraggableDrawerBackdropProps, DraggableDrawerBackdropEvents, DraggableDrawerBackdropSlots> {
|
|
15
|
+
}
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
<script>import { onMount } from "svelte";
|
|
2
|
+
import { getContentOrigin, getPointer, getPointerOrigin } from "../stores/coordinates.js";
|
|
3
|
+
import { getContent, getHandle, getRootProps } from "../stores/index.js";
|
|
4
|
+
import { getDragState } from "../stores/states.js";
|
|
5
|
+
let contentRef;
|
|
6
|
+
const content = getContent();
|
|
7
|
+
const handle = getHandle();
|
|
8
|
+
$: handleRect = $handle?.getBoundingClientRect();
|
|
9
|
+
const rootProps = getRootProps();
|
|
10
|
+
const pointer = getPointer();
|
|
11
|
+
const pointerOrigin = getPointerOrigin();
|
|
12
|
+
const contentOrigin = getContentOrigin();
|
|
13
|
+
const dragState = getDragState();
|
|
14
|
+
onMount(() => {
|
|
15
|
+
$content = contentRef;
|
|
16
|
+
});
|
|
17
|
+
function getStyleTransform(...args) {
|
|
18
|
+
if ($dragState === "drag") {
|
|
19
|
+
if (!$pointer || !$pointerOrigin || !$contentOrigin) return "none";
|
|
20
|
+
const y = $pointerOrigin.y > window.innerHeight / 2 ? $pointer.y > $pointerOrigin.y ? $pointerOrigin.y : $pointer.y : $pointer.y < $pointerOrigin.y ? $pointerOrigin.y : $pointer.y;
|
|
21
|
+
const offset = $contentOrigin.y - $pointerOrigin.y;
|
|
22
|
+
return `translate3d(0, ${y + offset}px, 0)`;
|
|
23
|
+
}
|
|
24
|
+
if ($rootProps.isOpen) return `translate3d(0, calc(0% + ${handleRect?.height || 24}px), 0)`;
|
|
25
|
+
return `translate3d(0, calc(100% - ${handleRect?.height || 48}px), 0)`;
|
|
26
|
+
}
|
|
27
|
+
$: styleTransform = getStyleTransform($pointer, $dragState, $rootProps.isOpen);
|
|
28
|
+
$: styleTransition = $dragState !== "drag-start" && $dragState !== "drag" ? `transform 400ms cubic-bezier(0.32, 0.72, 0, 1)` : "none";
|
|
29
|
+
</script>
|
|
30
|
+
|
|
31
|
+
<div
|
|
32
|
+
bind:this={contentRef}
|
|
33
|
+
class="sdd-content"
|
|
34
|
+
style:transform={styleTransform}
|
|
35
|
+
style:transition={styleTransition}
|
|
36
|
+
>
|
|
37
|
+
<slot />
|
|
38
|
+
</div>
|
|
39
|
+
|
|
40
|
+
<style>
|
|
41
|
+
.sdd-content {
|
|
42
|
+
display: flex;
|
|
43
|
+
flex-direction: column;
|
|
44
|
+
width: calc(100% - 2rem);
|
|
45
|
+
height: 100%;
|
|
46
|
+
margin-inline: auto;
|
|
47
|
+
pointer-events: auto;
|
|
48
|
+
position: relative;
|
|
49
|
+
z-index: 1;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
@media (min-width: 48em) {
|
|
53
|
+
.sdd-content {
|
|
54
|
+
width: calc(100% - 2.5rem);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
</style>
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { SvelteComponent } from "svelte";
|
|
2
|
+
declare const __propDef: {
|
|
3
|
+
props: Record<string, never>;
|
|
4
|
+
events: {
|
|
5
|
+
[evt: string]: CustomEvent<any>;
|
|
6
|
+
};
|
|
7
|
+
slots: {
|
|
8
|
+
default: {};
|
|
9
|
+
};
|
|
10
|
+
exports?: {} | undefined;
|
|
11
|
+
bindings?: string | undefined;
|
|
12
|
+
};
|
|
13
|
+
export type DraggableDrawerContentProps = typeof __propDef.props;
|
|
14
|
+
export type DraggableDrawerContentEvents = typeof __propDef.events;
|
|
15
|
+
export type DraggableDrawerContentSlots = typeof __propDef.slots;
|
|
16
|
+
export default class DraggableDrawerContent extends SvelteComponent<DraggableDrawerContentProps, DraggableDrawerContentEvents, DraggableDrawerContentSlots> {
|
|
17
|
+
}
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
<script>import { onMount } from "svelte";
|
|
2
|
+
import { getHandle, getRootProps } from "../stores/index.js";
|
|
3
|
+
let handleRef;
|
|
4
|
+
const handle = getHandle();
|
|
5
|
+
const rootProps = getRootProps();
|
|
6
|
+
onMount(() => {
|
|
7
|
+
$handle = handleRef;
|
|
8
|
+
});
|
|
9
|
+
const handleKeyUp = ({ key }) => {
|
|
10
|
+
if (key === "Enter" || key === " ") {
|
|
11
|
+
$rootProps.isOpen = !$rootProps.isOpen;
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
</script>
|
|
15
|
+
|
|
16
|
+
<button bind:this={handleRef} class="sdd-handle" data-role="handle" on:keyup={handleKeyUp}>
|
|
17
|
+
<slot />
|
|
18
|
+
</button>
|
|
19
|
+
|
|
20
|
+
<style>
|
|
21
|
+
.sdd-handle {
|
|
22
|
+
margin-inline: auto;
|
|
23
|
+
user-select: none;
|
|
24
|
+
}
|
|
25
|
+
</style>
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { SvelteComponent } from "svelte";
|
|
2
|
+
declare const __propDef: {
|
|
3
|
+
props: Record<string, never>;
|
|
4
|
+
events: {
|
|
5
|
+
[evt: string]: CustomEvent<any>;
|
|
6
|
+
};
|
|
7
|
+
slots: {
|
|
8
|
+
default: {};
|
|
9
|
+
};
|
|
10
|
+
exports?: {} | undefined;
|
|
11
|
+
bindings?: string | undefined;
|
|
12
|
+
};
|
|
13
|
+
export type DraggableDrawerHandleProps = typeof __propDef.props;
|
|
14
|
+
export type DraggableDrawerHandleEvents = typeof __propDef.events;
|
|
15
|
+
export type DraggableDrawerHandleSlots = typeof __propDef.slots;
|
|
16
|
+
export default class DraggableDrawerHandle extends SvelteComponent<DraggableDrawerHandleProps, DraggableDrawerHandleEvents, DraggableDrawerHandleSlots> {
|
|
17
|
+
}
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { default as Root } from './components/DraggableDrawer.svelte';
|
|
2
|
+
export { default as Handle } from './components/DraggableDrawerHandle.svelte';
|
|
3
|
+
export { default as Content } from './components/DraggableDrawerContent.svelte';
|
|
4
|
+
export { default as Backdrop } from './components/DraggableDrawerBackdrop.svelte';
|
|
5
|
+
export type { DraggableDrawerRootProps as RootProps } from './types/index.js';
|
package/dist/exports.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { default as Root } from './components/DraggableDrawer.svelte';
|
|
2
|
+
export { default as Handle } from './components/DraggableDrawerHandle.svelte';
|
|
3
|
+
export { default as Content } from './components/DraggableDrawerContent.svelte';
|
|
4
|
+
export { default as Backdrop } from './components/DraggableDrawerBackdrop.svelte';
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * as DraggableDrawer from './exports.js';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * as DraggableDrawer from './exports.js';
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { DraggableDrawerCoordinates as Coordinates } from '../types/index.js';
|
|
2
|
+
export declare function setPointer(context: Coordinates['pointer']): import("svelte/store").Writable<{
|
|
3
|
+
x: number;
|
|
4
|
+
y: number;
|
|
5
|
+
} | null>;
|
|
6
|
+
export declare function getPointer(): import("svelte/store").Writable<{
|
|
7
|
+
x: number;
|
|
8
|
+
y: number;
|
|
9
|
+
} | null>;
|
|
10
|
+
export declare function setPointerOrigin(context: Coordinates['pointerOrigin']): import("svelte/store").Writable<{
|
|
11
|
+
x: number;
|
|
12
|
+
y: number;
|
|
13
|
+
} | null>;
|
|
14
|
+
export declare function getPointerOrigin(): import("svelte/store").Writable<{
|
|
15
|
+
x: number;
|
|
16
|
+
y: number;
|
|
17
|
+
} | null>;
|
|
18
|
+
export declare function setContentOrigin(context: Coordinates['contentOrigin']): import("svelte/store").Writable<{
|
|
19
|
+
x: number;
|
|
20
|
+
y: number;
|
|
21
|
+
} | null>;
|
|
22
|
+
export declare function getContentOrigin(): import("svelte/store").Writable<{
|
|
23
|
+
x: number;
|
|
24
|
+
y: number;
|
|
25
|
+
} | null>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { getWritableContext, setWritableContext } from './index.js';
|
|
2
|
+
export function setPointer(context) {
|
|
3
|
+
return setWritableContext('pointer', context);
|
|
4
|
+
}
|
|
5
|
+
export function getPointer() {
|
|
6
|
+
return getWritableContext('pointer');
|
|
7
|
+
}
|
|
8
|
+
export function setPointerOrigin(context) {
|
|
9
|
+
return setWritableContext('pointerOrigin', context);
|
|
10
|
+
}
|
|
11
|
+
export function getPointerOrigin() {
|
|
12
|
+
return getWritableContext('pointerOrigin');
|
|
13
|
+
}
|
|
14
|
+
export function setContentOrigin(context) {
|
|
15
|
+
return setWritableContext('contentOrigin', context);
|
|
16
|
+
}
|
|
17
|
+
export function getContentOrigin() {
|
|
18
|
+
return getWritableContext('contentOrigin');
|
|
19
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { DraggableDrawerElements as Elements } from '../types/index.js';
|
|
2
|
+
export declare function setRoot(context: Elements['root']): import("svelte/store").Writable<HTMLDivElement | null>;
|
|
3
|
+
export declare function getRoot(): import("svelte/store").Writable<HTMLDivElement | null>;
|
|
4
|
+
export declare function setContent(context: Elements['content']): import("svelte/store").Writable<HTMLDivElement | null>;
|
|
5
|
+
export declare function getContent(): import("svelte/store").Writable<HTMLDivElement | null>;
|
|
6
|
+
export declare function setHandle(context: Elements['handle']): import("svelte/store").Writable<HTMLButtonElement | null>;
|
|
7
|
+
export declare function getHandle(): import("svelte/store").Writable<HTMLButtonElement | null>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { getWritableContext, setWritableContext } from './index.js';
|
|
2
|
+
export function setRoot(context) {
|
|
3
|
+
return setWritableContext('root', context);
|
|
4
|
+
}
|
|
5
|
+
export function getRoot() {
|
|
6
|
+
return getWritableContext('root');
|
|
7
|
+
}
|
|
8
|
+
export function setContent(context) {
|
|
9
|
+
return setWritableContext('content', context);
|
|
10
|
+
}
|
|
11
|
+
export function getContent() {
|
|
12
|
+
return getWritableContext('content');
|
|
13
|
+
}
|
|
14
|
+
export function setHandle(context) {
|
|
15
|
+
return setWritableContext('handle', context);
|
|
16
|
+
}
|
|
17
|
+
export function getHandle() {
|
|
18
|
+
return getWritableContext('handle');
|
|
19
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * from './coordinates.js';
|
|
2
|
+
export * from './elements.js';
|
|
3
|
+
export * from './props.js';
|
|
4
|
+
export * from './states.js';
|
|
5
|
+
import { type Writable } from 'svelte/store';
|
|
6
|
+
export declare function setWritableContext<T>(key: string, context: T): Writable<T>;
|
|
7
|
+
export declare function getWritableContext<T>(key: string): Writable<T>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export * from './coordinates.js';
|
|
2
|
+
export * from './elements.js';
|
|
3
|
+
export * from './props.js';
|
|
4
|
+
export * from './states.js';
|
|
5
|
+
import { getContext, setContext } from 'svelte';
|
|
6
|
+
import { writable } from 'svelte/store';
|
|
7
|
+
export function setWritableContext(key, context) {
|
|
8
|
+
const uniqueKey = Symbol.for(key);
|
|
9
|
+
return setContext(uniqueKey, writable(context));
|
|
10
|
+
}
|
|
11
|
+
export function getWritableContext(key) {
|
|
12
|
+
const uniqueKey = Symbol.for(key);
|
|
13
|
+
return getContext(uniqueKey);
|
|
14
|
+
}
|
package/dist/styles.css
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
.sdd-content {
|
|
2
|
+
background-color: var(--sdd-white);
|
|
3
|
+
border-radius: 1rem 1rem 0 0;
|
|
4
|
+
|
|
5
|
+
&::after {
|
|
6
|
+
content: "";
|
|
7
|
+
position: absolute;
|
|
8
|
+
top: 100%;
|
|
9
|
+
left: 0;
|
|
10
|
+
width: 100%;
|
|
11
|
+
height: 50%;
|
|
12
|
+
background-color: inherit;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.sdd-handle {
|
|
17
|
+
padding: 1.3125rem;
|
|
18
|
+
border: none;
|
|
19
|
+
border-radius: 0.75rem;
|
|
20
|
+
|
|
21
|
+
& > span {
|
|
22
|
+
display: block;
|
|
23
|
+
width: 4rem;
|
|
24
|
+
height: 0.375rem;
|
|
25
|
+
border-radius: 0.25rem;
|
|
26
|
+
background-color: var(--sdd-gray-200);
|
|
27
|
+
text-indent: -9999px;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.sdd-backdrop {
|
|
32
|
+
background-color: var(--sdd-black);
|
|
33
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type DraggableDrawerDragState = 'idle' | 'drag-start' | 'drag' | 'drop';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@rodrigodagostino/svelte-draggable-drawer",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"author": "Rodrigo D’Agostino <rodrigo.dagostino@proton.me>",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"draggable",
|
|
7
|
+
"drawer",
|
|
8
|
+
"drag",
|
|
9
|
+
"drop",
|
|
10
|
+
"dnd",
|
|
11
|
+
"accessible",
|
|
12
|
+
"svelte",
|
|
13
|
+
"sveltekit"
|
|
14
|
+
],
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"type": "module",
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://github.com/rodrigodagostino/svelte-draggable-drawer.git"
|
|
20
|
+
},
|
|
21
|
+
"scripts": {
|
|
22
|
+
"dev": "vite dev",
|
|
23
|
+
"build": "vite build && npm run package",
|
|
24
|
+
"preview": "vite preview",
|
|
25
|
+
"package": "svelte-kit sync && svelte-package && publint",
|
|
26
|
+
"prepublishOnly": "npm run package",
|
|
27
|
+
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
|
|
28
|
+
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
|
|
29
|
+
"lint": "prettier --check . && eslint .",
|
|
30
|
+
"format": "prettier --write ."
|
|
31
|
+
},
|
|
32
|
+
"exports": {
|
|
33
|
+
".": {
|
|
34
|
+
"types": "./dist/index.d.ts",
|
|
35
|
+
"svelte": "./dist/index.js"
|
|
36
|
+
},
|
|
37
|
+
"./*.css": {
|
|
38
|
+
"import": "./dist/*.css"
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
"files": [
|
|
42
|
+
"dist",
|
|
43
|
+
"!dist/**/*.test.*",
|
|
44
|
+
"!dist/**/*.spec.*"
|
|
45
|
+
],
|
|
46
|
+
"peerDependencies": {
|
|
47
|
+
"svelte": "^4.0.0"
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"@sveltejs/adapter-auto": "7.0.1",
|
|
51
|
+
"@sveltejs/kit": "2.69.1",
|
|
52
|
+
"@sveltejs/package": "2.5.8",
|
|
53
|
+
"@sveltejs/vite-plugin-svelte": "3.1.2",
|
|
54
|
+
"@types/eslint": "9.6.1",
|
|
55
|
+
"@types/node": "22.20.0",
|
|
56
|
+
"eslint": "9.39.4",
|
|
57
|
+
"eslint-config-prettier": "9.1.2",
|
|
58
|
+
"eslint-plugin-prettier": "5.5.6",
|
|
59
|
+
"eslint-plugin-svelte": "3.20.0",
|
|
60
|
+
"globals": "17.7.0",
|
|
61
|
+
"prettier": "3.9.4",
|
|
62
|
+
"prettier-plugin-svelte": "3.5.2",
|
|
63
|
+
"publint": "0.3.21",
|
|
64
|
+
"svelte": "4.2.20",
|
|
65
|
+
"svelte-check": "4.7.1",
|
|
66
|
+
"typescript": "6.0.3",
|
|
67
|
+
"typescript-eslint": "8.62.1",
|
|
68
|
+
"vite": "5.4.21"
|
|
69
|
+
},
|
|
70
|
+
"svelte": "./dist/index.js",
|
|
71
|
+
"types": "./dist/index.d.ts"
|
|
72
|
+
}
|