@surdeddd/bottom-sheet 0.8.1 → 0.9.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/dist/{BottomSheetEngine-7BDK2OWX.d.cts → BottomSheetEngine-BcyruNP1.d.cts} +12 -6
- package/dist/{BottomSheetEngine-BFTb0-4Z.d.ts → BottomSheetEngine-CBRcBwV-.d.ts} +12 -6
- package/dist/element.cjs +530 -349
- package/dist/element.d.cts +2 -1
- package/dist/element.d.ts +2 -1
- package/dist/element.iife.global.js +2 -2
- package/dist/element.js +530 -349
- package/dist/index.cjs +438 -294
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +438 -294
- package/dist/integrations/formik.d.cts +1 -1
- package/dist/integrations/formik.d.ts +1 -1
- package/dist/integrations/react-hook-form.d.cts +1 -1
- package/dist/integrations/react-hook-form.d.ts +1 -1
- package/dist/overlay.cjs +160 -96
- package/dist/overlay.d.cts +2 -0
- package/dist/overlay.d.ts +2 -0
- package/dist/overlay.js +160 -96
- package/dist/preact.d.cts +1 -1
- package/dist/preact.d.ts +1 -1
- package/dist/qwik.cjs +387 -211
- package/dist/qwik.d.cts +4 -3
- package/dist/qwik.d.ts +4 -3
- package/dist/qwik.js +387 -211
- package/dist/react.cjs +472 -296
- package/dist/react.d.cts +3 -2
- package/dist/react.d.ts +3 -2
- package/dist/react.js +472 -296
- package/dist/solid.cjs +417 -215
- package/dist/solid.d.cts +21 -7
- package/dist/solid.d.ts +21 -7
- package/dist/solid.js +417 -215
- package/dist/solid.source.jsx +412 -209
- package/dist/svelte-core.cjs +328 -209
- package/dist/svelte-core.js +328 -209
- package/dist/svelte-src/BottomSheet.svelte +56 -0
- package/dist/svelte.cjs +365 -210
- package/dist/svelte.d.cts +4 -0
- package/dist/svelte.d.ts +4 -0
- package/dist/svelte.js +365 -210
- package/dist/vue.cjs +365 -217
- package/dist/vue.d.cts +6 -0
- package/dist/vue.d.ts +6 -0
- package/dist/vue.js +365 -217
- package/package.json +6 -6
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
<script lang="ts" generics="TId extends string = string">
|
|
2
2
|
import { onMount, onDestroy, untrack, type Snippet } from "svelte";
|
|
3
3
|
import { BottomSheetEngine } from "@surdeddd/bottom-sheet";
|
|
4
|
+
import {
|
|
5
|
+
resolveTeleportTarget,
|
|
6
|
+
teleportElements,
|
|
7
|
+
type TeleportTarget,
|
|
8
|
+
} from "../core/features/teleport";
|
|
4
9
|
import type {
|
|
5
10
|
EngineState,
|
|
6
11
|
SnapPointDef,
|
|
@@ -30,6 +35,9 @@
|
|
|
30
35
|
disableClose?: boolean;
|
|
31
36
|
disableDrag?: boolean;
|
|
32
37
|
closeOnRouteChange?: boolean;
|
|
38
|
+
stackEffect?: boolean;
|
|
39
|
+
teleport?: boolean;
|
|
40
|
+
teleportTo?: TeleportTarget;
|
|
33
41
|
radius?: string | number;
|
|
34
42
|
maxHeight?: string | number;
|
|
35
43
|
backdropColor?: string;
|
|
@@ -45,6 +53,7 @@
|
|
|
45
53
|
screen?: Snippet;
|
|
46
54
|
children?: Snippet;
|
|
47
55
|
onsnap?: (id: TId) => void;
|
|
56
|
+
onbeforesnap?: (payload: SheetEventMap["before-snap"]) => void;
|
|
48
57
|
onopen?: (id: TId) => void;
|
|
49
58
|
onclose?: () => void;
|
|
50
59
|
onbeforeclose?: (payload: SheetEventMap["before-close"]) => void;
|
|
@@ -74,6 +83,9 @@
|
|
|
74
83
|
disableClose = false,
|
|
75
84
|
disableDrag = false,
|
|
76
85
|
closeOnRouteChange = false,
|
|
86
|
+
stackEffect = false,
|
|
87
|
+
teleport = false,
|
|
88
|
+
teleportTo,
|
|
77
89
|
radius,
|
|
78
90
|
maxHeight,
|
|
79
91
|
backdropColor,
|
|
@@ -89,6 +101,7 @@
|
|
|
89
101
|
screen,
|
|
90
102
|
children,
|
|
91
103
|
onsnap,
|
|
104
|
+
onbeforesnap,
|
|
92
105
|
onopen,
|
|
93
106
|
onclose,
|
|
94
107
|
onbeforeclose,
|
|
@@ -116,6 +129,7 @@
|
|
|
116
129
|
});
|
|
117
130
|
|
|
118
131
|
let engine: BottomSheetEngine | null = null;
|
|
132
|
+
let restoreTeleport: (() => void) | null = null;
|
|
119
133
|
|
|
120
134
|
onMount(() => {
|
|
121
135
|
if (!sheetEl) return;
|
|
@@ -141,10 +155,19 @@
|
|
|
141
155
|
disableClose,
|
|
142
156
|
disableDrag,
|
|
143
157
|
closeOnRouteChange,
|
|
158
|
+
stackEffect,
|
|
144
159
|
radius,
|
|
145
160
|
maxHeight,
|
|
146
161
|
returnFocusTo,
|
|
147
162
|
});
|
|
163
|
+
const teleportTarget =
|
|
164
|
+
teleport === false ? null : resolveTeleportTarget(teleportTo);
|
|
165
|
+
if (teleportTarget) {
|
|
166
|
+
restoreTeleport = teleportElements(
|
|
167
|
+
[backdropEl, screenEl, sheetEl],
|
|
168
|
+
teleportTarget,
|
|
169
|
+
);
|
|
170
|
+
}
|
|
148
171
|
const sync = () => {
|
|
149
172
|
if (!engine) return;
|
|
150
173
|
viewState = { ...engine.state } as EngineState & { activeId: TId };
|
|
@@ -168,6 +191,7 @@
|
|
|
168
191
|
onclose?.();
|
|
169
192
|
});
|
|
170
193
|
engine.on("before-close", payload => onbeforeclose?.(payload));
|
|
194
|
+
engine.on("before-snap", payload => onbeforesnap?.(payload));
|
|
171
195
|
engine.on("opened", payload => onopened?.(payload.id as TId));
|
|
172
196
|
engine.on("closed", () => onclosed?.());
|
|
173
197
|
engine.on("dragstart", () => {
|
|
@@ -181,6 +205,8 @@
|
|
|
181
205
|
});
|
|
182
206
|
|
|
183
207
|
onDestroy(() => {
|
|
208
|
+
restoreTeleport?.();
|
|
209
|
+
restoreTeleport = null;
|
|
184
210
|
engine?.destroy();
|
|
185
211
|
engine = null;
|
|
186
212
|
});
|
|
@@ -210,6 +236,36 @@
|
|
|
210
236
|
(engine?.state ?? viewState) as EngineState & { activeId: TId };
|
|
211
237
|
export const getEngine = (): BottomSheetEngine | null => engine;
|
|
212
238
|
|
|
239
|
+
let snapDefApplied = false;
|
|
240
|
+
$effect(() => {
|
|
241
|
+
const points = snapPoints;
|
|
242
|
+
if (!snapDefApplied) {
|
|
243
|
+
snapDefApplied = true;
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
engine?.setSnapPoints(
|
|
247
|
+
points as unknown as EngineOptions["snapPoints"],
|
|
248
|
+
untrack(() => allowed) as unknown as string[] | undefined,
|
|
249
|
+
);
|
|
250
|
+
});
|
|
251
|
+
let allowedApplied = false;
|
|
252
|
+
$effect(() => {
|
|
253
|
+
const ids = allowed;
|
|
254
|
+
if (!allowedApplied) {
|
|
255
|
+
allowedApplied = true;
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
if (ids) engine?.setAllowed(ids as unknown as string[]);
|
|
259
|
+
});
|
|
260
|
+
$effect(() => {
|
|
261
|
+
engine?.setPersistent(persistent);
|
|
262
|
+
});
|
|
263
|
+
$effect(() => {
|
|
264
|
+
engine?.setDisableClose(disableClose);
|
|
265
|
+
});
|
|
266
|
+
$effect(() => {
|
|
267
|
+
engine?.setDisableDrag(disableDrag);
|
|
268
|
+
});
|
|
213
269
|
$effect(() => {
|
|
214
270
|
if (radius !== undefined) engine?.setRadius(radius);
|
|
215
271
|
});
|