@surdeddd/bottom-sheet 0.3.0 → 0.4.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/dist/{BottomSheetEngine-CAymrH-P.d.cts → BottomSheetEngine-BJrH7qY3.d.cts} +39 -3
- package/dist/{BottomSheetEngine-DcqcuudN.d.ts → BottomSheetEngine-L05jGZvU.d.ts} +39 -3
- package/dist/element.cjs +490 -91
- package/dist/element.d.cts +23 -4
- package/dist/element.d.ts +23 -4
- package/dist/element.iife.global.js +2 -2
- package/dist/element.js +490 -91
- package/dist/index.cjs +347 -80
- package/dist/index.d.cts +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.js +347 -80
- 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 +13 -2
- package/dist/overlay.js +13 -2
- package/dist/preact.d.cts +1 -1
- package/dist/preact.d.ts +1 -1
- package/dist/qwik.cjs +358 -81
- package/dist/qwik.d.cts +4 -2
- package/dist/qwik.d.ts +4 -2
- package/dist/qwik.js +358 -81
- package/dist/react.cjs +451 -89
- package/dist/react.d.cts +29 -4
- package/dist/react.d.ts +29 -4
- package/dist/react.js +451 -89
- package/dist/solid.cjs +347 -80
- package/dist/solid.d.cts +38 -2
- package/dist/solid.d.ts +38 -2
- package/dist/solid.js +347 -80
- package/dist/solid.source.jsx +347 -80
- package/dist/styles.css +68 -55
- package/dist/svelte-core.cjs +352 -80
- package/dist/svelte-core.js +352 -80
- package/dist/svelte-src/BottomSheet.svelte +113 -15
- package/dist/svelte.cjs +474 -133
- package/dist/svelte.d.cts +21 -0
- package/dist/svelte.d.ts +21 -0
- package/dist/svelte.js +474 -133
- package/dist/vue.cjs +610 -109
- package/dist/vue.d.cts +51 -2
- package/dist/vue.d.ts +51 -2
- package/dist/vue.js +611 -110
- package/package.json +8 -8
package/dist/svelte-core.cjs
CHANGED
|
@@ -39,6 +39,15 @@ var SheetStack = class {
|
|
|
39
39
|
size() {
|
|
40
40
|
return this.entries.length;
|
|
41
41
|
}
|
|
42
|
+
depthOf(id) {
|
|
43
|
+
const open = [];
|
|
44
|
+
for (const entry of this.entries) {
|
|
45
|
+
if (!entry.isOpen || entry.isOpen()) open.push(entry);
|
|
46
|
+
}
|
|
47
|
+
const idx = open.findIndex((e) => e.id === id);
|
|
48
|
+
if (idx === -1) return 0;
|
|
49
|
+
return open.length - 1 - idx;
|
|
50
|
+
}
|
|
42
51
|
clear() {
|
|
43
52
|
this.entries = [];
|
|
44
53
|
}
|
|
@@ -157,7 +166,9 @@ var PERCENT = /^(-?\d+(?:\.\d+)?)%$/;
|
|
|
157
166
|
var resolveSnap = (point, mode, measureFit) => {
|
|
158
167
|
if (typeof point === "number") return Math.max(0, point);
|
|
159
168
|
if (point === "full") return viewportSize(mode);
|
|
160
|
-
if (point === "fit"
|
|
169
|
+
if (point === "fit" || point === "content") {
|
|
170
|
+
return Math.max(0, measureFit?.() ?? 0);
|
|
171
|
+
}
|
|
161
172
|
const pctMatch = point.match(PERCENT);
|
|
162
173
|
if (pctMatch) {
|
|
163
174
|
const pct = parseFloat(pctMatch[1]) / 100;
|
|
@@ -394,6 +405,42 @@ function notifyLinkedSheets(sheets, self) {
|
|
|
394
405
|
}
|
|
395
406
|
|
|
396
407
|
// src/core/features/route.ts
|
|
408
|
+
var closers = [];
|
|
409
|
+
var handlerInstalled = false;
|
|
410
|
+
var suppress = 0;
|
|
411
|
+
var ensureHandler = () => {
|
|
412
|
+
if (handlerInstalled || typeof window === "undefined") return;
|
|
413
|
+
handlerInstalled = true;
|
|
414
|
+
window.addEventListener("popstate", () => {
|
|
415
|
+
if (suppress > 0) {
|
|
416
|
+
suppress -= 1;
|
|
417
|
+
return;
|
|
418
|
+
}
|
|
419
|
+
let target = null;
|
|
420
|
+
for (let i = closers.length - 1; i >= 0; i -= 1) {
|
|
421
|
+
const c = closers[i];
|
|
422
|
+
if (!c.isOpen()) continue;
|
|
423
|
+
if (!target) target = c;
|
|
424
|
+
if (c.isTop()) {
|
|
425
|
+
target = c;
|
|
426
|
+
break;
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
if (!target) return;
|
|
430
|
+
target.consumed = true;
|
|
431
|
+
const idx = closers.indexOf(target);
|
|
432
|
+
if (idx !== -1) closers.splice(idx, 1);
|
|
433
|
+
target.close();
|
|
434
|
+
});
|
|
435
|
+
};
|
|
436
|
+
var programmaticBack = () => {
|
|
437
|
+
suppress += 1;
|
|
438
|
+
try {
|
|
439
|
+
history.back();
|
|
440
|
+
} catch {
|
|
441
|
+
suppress = Math.max(0, suppress - 1);
|
|
442
|
+
}
|
|
443
|
+
};
|
|
397
444
|
function installRoute(deps) {
|
|
398
445
|
if (typeof window === "undefined") {
|
|
399
446
|
return () => {
|
|
@@ -403,82 +450,81 @@ function installRoute(deps) {
|
|
|
403
450
|
return () => {
|
|
404
451
|
};
|
|
405
452
|
}
|
|
406
|
-
let
|
|
407
|
-
let
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
453
|
+
let pushed = false;
|
|
454
|
+
let closer = null;
|
|
455
|
+
const teardownEntry = () => {
|
|
456
|
+
if (closer) {
|
|
457
|
+
const idx = closers.indexOf(closer);
|
|
458
|
+
if (idx !== -1) closers.splice(idx, 1);
|
|
459
|
+
}
|
|
460
|
+
const wasConsumed = closer?.consumed ?? false;
|
|
461
|
+
closer = null;
|
|
462
|
+
if (pushed && !wasConsumed) {
|
|
463
|
+
pushed = false;
|
|
464
|
+
programmaticBack();
|
|
465
|
+
} else {
|
|
466
|
+
pushed = false;
|
|
416
467
|
}
|
|
417
468
|
};
|
|
418
469
|
const onOpen = () => {
|
|
419
|
-
if (
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
}
|
|
433
|
-
};
|
|
434
|
-
window.addEventListener("popstate", onPop);
|
|
435
|
-
detachPopstate = () => window.removeEventListener("popstate", onPop);
|
|
436
|
-
} else if (deps.closeOnBack && !detachPopstate) {
|
|
437
|
-
try {
|
|
470
|
+
if (closer) return;
|
|
471
|
+
closer = {
|
|
472
|
+
isOpen: () => !deps.isDestroyed() && deps.getSize() > 0,
|
|
473
|
+
isTop: () => deps.isTopSheet(),
|
|
474
|
+
close: () => void deps.close(),
|
|
475
|
+
consumed: false
|
|
476
|
+
};
|
|
477
|
+
ensureHandler();
|
|
478
|
+
closers.push(closer);
|
|
479
|
+
try {
|
|
480
|
+
if (deps.routedTo !== void 0) {
|
|
481
|
+
history.pushState({ __bsRouted: deps.sheetId }, "", deps.routedTo);
|
|
482
|
+
} else {
|
|
438
483
|
history.pushState({ __bsSheet: deps.sheetId }, "");
|
|
439
|
-
closeOnBackPushed = true;
|
|
440
|
-
} catch {
|
|
441
484
|
}
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
const state = history.state;
|
|
446
|
-
if (state?.__bsSheet !== deps.sheetId) closeOnBackPushed = false;
|
|
447
|
-
void deps.close();
|
|
448
|
-
}
|
|
449
|
-
};
|
|
450
|
-
window.addEventListener("popstate", onPop);
|
|
451
|
-
detachPopstate = () => window.removeEventListener("popstate", onPop);
|
|
452
|
-
}
|
|
453
|
-
};
|
|
454
|
-
const onClose = () => {
|
|
455
|
-
detachPopstate?.();
|
|
456
|
-
detachPopstate = null;
|
|
457
|
-
if (routePushed) {
|
|
458
|
-
routePushed = false;
|
|
459
|
-
if (deps.routedTo !== void 0) popOurMarker("__bsRouted", deps.routedTo);
|
|
460
|
-
}
|
|
461
|
-
if (closeOnBackPushed) {
|
|
462
|
-
closeOnBackPushed = false;
|
|
463
|
-
popOurMarker("__bsSheet", deps.sheetId);
|
|
485
|
+
pushed = true;
|
|
486
|
+
} catch {
|
|
487
|
+
pushed = false;
|
|
464
488
|
}
|
|
465
489
|
};
|
|
466
490
|
const unsubscribeOpen = deps.on("open", onOpen);
|
|
467
|
-
const unsubscribeClose = deps.on("close",
|
|
491
|
+
const unsubscribeClose = deps.on("close", teardownEntry);
|
|
468
492
|
if (deps.getSize() > 0) onOpen();
|
|
469
493
|
return () => {
|
|
470
494
|
unsubscribeOpen();
|
|
471
495
|
unsubscribeClose();
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
496
|
+
teardownEntry();
|
|
497
|
+
};
|
|
498
|
+
}
|
|
499
|
+
function installRouteChange(deps) {
|
|
500
|
+
if (typeof window === "undefined" || typeof history === "undefined") {
|
|
501
|
+
return () => {
|
|
502
|
+
};
|
|
503
|
+
}
|
|
504
|
+
const onChange = () => {
|
|
505
|
+
if (deps.isDestroyed() || deps.getSize() <= 0) return;
|
|
506
|
+
void deps.close();
|
|
507
|
+
};
|
|
508
|
+
const wrap = (key) => {
|
|
509
|
+
const original = history[key];
|
|
510
|
+
const patched = function(...args) {
|
|
511
|
+
original.apply(this, args);
|
|
512
|
+
onChange();
|
|
513
|
+
};
|
|
514
|
+
history[key] = patched;
|
|
515
|
+
return () => {
|
|
516
|
+
if (history[key] === patched) {
|
|
517
|
+
history[key] = original;
|
|
518
|
+
}
|
|
519
|
+
};
|
|
520
|
+
};
|
|
521
|
+
window.addEventListener("popstate", onChange);
|
|
522
|
+
const restorePush = wrap("pushState");
|
|
523
|
+
const restoreReplace = wrap("replaceState");
|
|
524
|
+
return () => {
|
|
525
|
+
window.removeEventListener("popstate", onChange);
|
|
526
|
+
restorePush();
|
|
527
|
+
restoreReplace();
|
|
482
528
|
};
|
|
483
529
|
}
|
|
484
530
|
|
|
@@ -786,6 +832,7 @@ function applyOverlayPosition(ws, mode, position, inset) {
|
|
|
786
832
|
|
|
787
833
|
// src/core/controllers/scrim-controller.ts
|
|
788
834
|
var VALID_CSS_LENGTH = /^-?\d+(?:\.\d+)?(?:px|em|rem|%)$/;
|
|
835
|
+
var DEFAULT_SCRIM_DIM = "rgba(0, 0, 0, 0.4)";
|
|
789
836
|
var ScrimController = class {
|
|
790
837
|
constructor(deps, opts) {
|
|
791
838
|
__publicField(this, "screenComponent");
|
|
@@ -824,9 +871,11 @@ var ScrimController = class {
|
|
|
824
871
|
this.backdropRange = opts.backdropRange ?? preset?.range ?? [0, 1];
|
|
825
872
|
this.screenRange = opts.screenRange ?? preset?.range ?? [0, 1];
|
|
826
873
|
this.scrimTapToCloseEnabled = opts.scrimTapToClose ?? false;
|
|
874
|
+
const explicitColor = opts.scrimColor ?? preset?.color;
|
|
875
|
+
const effectiveColor = explicitColor ?? (this.scrimMode !== "off" && !this.backdrop ? DEFAULT_SCRIM_DIM : void 0);
|
|
827
876
|
if (this.screenComponent) {
|
|
828
877
|
this.applyScrimStyles({
|
|
829
|
-
color:
|
|
878
|
+
color: effectiveColor,
|
|
830
879
|
blur: opts.scrimBlur ?? preset?.blur,
|
|
831
880
|
interactive: opts.scrimInteractive ?? preset?.interactive ?? false
|
|
832
881
|
});
|
|
@@ -1600,7 +1649,7 @@ var LifecycleController = class {
|
|
|
1600
1649
|
this.releaseScrollLock = null;
|
|
1601
1650
|
this.inertSiblings.remove();
|
|
1602
1651
|
if (this.returnFocus) {
|
|
1603
|
-
const target = typeof this.returnFocus === "function" ? this.returnFocus() : this.returnFocus;
|
|
1652
|
+
const target = typeof this.returnFocus === "function" ? this.returnFocus() : typeof this.returnFocus === "string" ? typeof document !== "undefined" ? document.querySelector(this.returnFocus) : null : this.returnFocus;
|
|
1604
1653
|
target?.focus?.();
|
|
1605
1654
|
}
|
|
1606
1655
|
}
|
|
@@ -1767,6 +1816,7 @@ var GestureController = class {
|
|
|
1767
1816
|
__publicField(this, "dragStartSize", 0);
|
|
1768
1817
|
__publicField(this, "currentPointerKind", "touch");
|
|
1769
1818
|
__publicField(this, "keyboardDismissed", false);
|
|
1819
|
+
__publicField(this, "dragSuppressed", false);
|
|
1770
1820
|
__publicField(this, "dragPayload", { size: 0, delta: 0 });
|
|
1771
1821
|
this.deps = deps;
|
|
1772
1822
|
}
|
|
@@ -1777,6 +1827,11 @@ var GestureController = class {
|
|
|
1777
1827
|
if (this.detach) return this.detach;
|
|
1778
1828
|
this.detach = installGestures(this.deps.handle, this.deps.mode, {
|
|
1779
1829
|
onStart: (_coord, kind) => {
|
|
1830
|
+
if (this.deps.getDisableDrag?.()) {
|
|
1831
|
+
this.dragSuppressed = true;
|
|
1832
|
+
return;
|
|
1833
|
+
}
|
|
1834
|
+
this.dragSuppressed = false;
|
|
1780
1835
|
this.deps.cancelAnimation();
|
|
1781
1836
|
this.isDragging_ = true;
|
|
1782
1837
|
this.dragStartSize = this.deps.getDragContext().size;
|
|
@@ -1787,6 +1842,7 @@ var GestureController = class {
|
|
|
1787
1842
|
this.deps.emit("dragstart", { size: this.dragStartSize });
|
|
1788
1843
|
},
|
|
1789
1844
|
onMove: (delta) => {
|
|
1845
|
+
if (this.dragSuppressed) return;
|
|
1790
1846
|
const ctx = this.deps.getDragContext();
|
|
1791
1847
|
const { min, max } = ctx.range;
|
|
1792
1848
|
const maxAxis = ctx.maxAxisSize;
|
|
@@ -1810,6 +1866,10 @@ var GestureController = class {
|
|
|
1810
1866
|
}
|
|
1811
1867
|
},
|
|
1812
1868
|
onEnd: (delta, velocity, kind) => {
|
|
1869
|
+
if (this.dragSuppressed) {
|
|
1870
|
+
this.dragSuppressed = false;
|
|
1871
|
+
return;
|
|
1872
|
+
}
|
|
1813
1873
|
this.isDragging_ = false;
|
|
1814
1874
|
this.keyboardDismissed = false;
|
|
1815
1875
|
this.deps.getRoot()?.removeAttribute("data-dragging");
|
|
@@ -1820,6 +1880,10 @@ var GestureController = class {
|
|
|
1820
1880
|
this.deps.settleAfterDrag(delta, velocity, kind);
|
|
1821
1881
|
},
|
|
1822
1882
|
onCancel: () => {
|
|
1883
|
+
if (this.dragSuppressed) {
|
|
1884
|
+
this.dragSuppressed = false;
|
|
1885
|
+
return;
|
|
1886
|
+
}
|
|
1823
1887
|
this.isDragging_ = false;
|
|
1824
1888
|
this.keyboardDismissed = false;
|
|
1825
1889
|
this.deps.getRoot()?.removeAttribute("data-dragging");
|
|
@@ -2199,6 +2263,12 @@ function resolveEngineOptions(opts, extras) {
|
|
|
2199
2263
|
dragThreshold: opts.dragThreshold ?? DEFAULT_DRAG_THRESHOLD,
|
|
2200
2264
|
rubberBandEnabled: opts.rubberBand ?? true,
|
|
2201
2265
|
closeOnBack: opts.closeOnBack ?? false,
|
|
2266
|
+
persistent: opts.persistent ?? false,
|
|
2267
|
+
disableClose: opts.disableClose ?? false,
|
|
2268
|
+
disableDrag: opts.disableDrag ?? false,
|
|
2269
|
+
closeOnRouteChange: opts.closeOnRouteChange ?? false,
|
|
2270
|
+
radius: opts.radius,
|
|
2271
|
+
maxHeight: opts.maxHeight,
|
|
2202
2272
|
initialAllowed,
|
|
2203
2273
|
initialId,
|
|
2204
2274
|
scrim: {
|
|
@@ -2225,7 +2295,8 @@ function resolveEngineOptions(opts, extras) {
|
|
|
2225
2295
|
closeOnEscape: opts.closeOnEscape,
|
|
2226
2296
|
lockBodyScroll: opts.lockBodyScroll,
|
|
2227
2297
|
inertSiblings: opts.inertSiblings,
|
|
2228
|
-
shouldApplyInertSiblings: extras?.shouldApplyInertSiblings
|
|
2298
|
+
shouldApplyInertSiblings: extras?.shouldApplyInertSiblings,
|
|
2299
|
+
returnFocus: opts.returnFocusTo
|
|
2229
2300
|
}
|
|
2230
2301
|
};
|
|
2231
2302
|
}
|
|
@@ -2270,6 +2341,11 @@ var BottomSheetEngine = class {
|
|
|
2270
2341
|
__publicField(this, "lifecycle");
|
|
2271
2342
|
__publicField(this, "closeOnBack");
|
|
2272
2343
|
__publicField(this, "routedTo");
|
|
2344
|
+
__publicField(this, "persistent");
|
|
2345
|
+
__publicField(this, "disableCloseFlag");
|
|
2346
|
+
__publicField(this, "disableDragFlag");
|
|
2347
|
+
__publicField(this, "closeOnRouteChange");
|
|
2348
|
+
__publicField(this, "maxHeightCap");
|
|
2273
2349
|
__publicField(this, "snapPointsRaw");
|
|
2274
2350
|
__publicField(this, "snaps");
|
|
2275
2351
|
__publicField(this, "activeId");
|
|
@@ -2282,6 +2358,7 @@ var BottomSheetEngine = class {
|
|
|
2282
2358
|
__publicField(this, "sizeWriteSentinel", new WriteSentinel());
|
|
2283
2359
|
__publicField(this, "progressWriteSentinel", new WriteSentinel());
|
|
2284
2360
|
__publicField(this, "isTopSheet", true);
|
|
2361
|
+
__publicField(this, "opening", false);
|
|
2285
2362
|
__publicField(this, "progressPayload", {
|
|
2286
2363
|
value: 0,
|
|
2287
2364
|
size: 0
|
|
@@ -2338,7 +2415,8 @@ var BottomSheetEngine = class {
|
|
|
2338
2415
|
void this.snapTo(id);
|
|
2339
2416
|
},
|
|
2340
2417
|
close: () => {
|
|
2341
|
-
|
|
2418
|
+
if (!this.canDismiss()) return;
|
|
2419
|
+
void this.close("backdrop");
|
|
2342
2420
|
}
|
|
2343
2421
|
},
|
|
2344
2422
|
resolved.scrim
|
|
@@ -2362,6 +2440,10 @@ var BottomSheetEngine = class {
|
|
|
2362
2440
|
);
|
|
2363
2441
|
this.closeOnBack = resolved.closeOnBack;
|
|
2364
2442
|
this.routedTo = opts.routedTo;
|
|
2443
|
+
this.persistent = resolved.persistent;
|
|
2444
|
+
this.disableCloseFlag = resolved.disableClose;
|
|
2445
|
+
this.disableDragFlag = resolved.disableDrag;
|
|
2446
|
+
this.closeOnRouteChange = resolved.closeOnRouteChange;
|
|
2365
2447
|
this.stackEffectEnabled = opts.stackEffect ?? false;
|
|
2366
2448
|
this.snapPointsRaw = opts.snapPoints;
|
|
2367
2449
|
this.persistKey = opts.persistKey;
|
|
@@ -2375,7 +2457,7 @@ var BottomSheetEngine = class {
|
|
|
2375
2457
|
this.snapPointsRaw,
|
|
2376
2458
|
resolved.initialAllowed,
|
|
2377
2459
|
this.mode,
|
|
2378
|
-
() =>
|
|
2460
|
+
() => this.measureFitSize(),
|
|
2379
2461
|
(maxAxisSize) => {
|
|
2380
2462
|
this.element.style[layoutAxis(this.mode)] = `${maxAxisSize}px`;
|
|
2381
2463
|
}
|
|
@@ -2409,6 +2491,19 @@ var BottomSheetEngine = class {
|
|
|
2409
2491
|
io.observe(this.element);
|
|
2410
2492
|
this.teardowns.add(() => io.disconnect());
|
|
2411
2493
|
}
|
|
2494
|
+
this.installFitObserver();
|
|
2495
|
+
if (resolved.radius !== void 0) this.setRadius(resolved.radius);
|
|
2496
|
+
if (resolved.maxHeight !== void 0) this.setMaxHeight(resolved.maxHeight);
|
|
2497
|
+
this.applyAutoAriaLabelledBy();
|
|
2498
|
+
if (this.closeOnRouteChange) {
|
|
2499
|
+
this.teardowns.add(
|
|
2500
|
+
installRouteChange({
|
|
2501
|
+
isDestroyed: () => this.destroyed,
|
|
2502
|
+
getSize: () => this.size,
|
|
2503
|
+
close: () => this.close()
|
|
2504
|
+
})
|
|
2505
|
+
);
|
|
2506
|
+
}
|
|
2412
2507
|
if (this.persistKey) {
|
|
2413
2508
|
this.teardowns.add(installPersist(this, this.persistKey));
|
|
2414
2509
|
}
|
|
@@ -2433,7 +2528,7 @@ var BottomSheetEngine = class {
|
|
|
2433
2528
|
isTopSheet: () => this.isTopSheet,
|
|
2434
2529
|
getSize: () => this.size,
|
|
2435
2530
|
isDestroyed: () => this.destroyed,
|
|
2436
|
-
close: () => this.close(),
|
|
2531
|
+
close: () => this.close("back"),
|
|
2437
2532
|
on: (event, fn) => this.on(event, fn),
|
|
2438
2533
|
sheetId: this.id
|
|
2439
2534
|
})
|
|
@@ -2527,6 +2622,10 @@ var BottomSheetEngine = class {
|
|
|
2527
2622
|
const previousSize = this.size;
|
|
2528
2623
|
this.scrollCache.cache(previousId, previousSize, target.size);
|
|
2529
2624
|
this.activeId = id;
|
|
2625
|
+
if (wasClosed && target.size > 0) {
|
|
2626
|
+
this.opening = true;
|
|
2627
|
+
sheetStack.promote(this.id);
|
|
2628
|
+
}
|
|
2530
2629
|
if (this.animation.viewTransitionsAvailable) {
|
|
2531
2630
|
this.currentViewTransition?.skipTransition?.();
|
|
2532
2631
|
const vt = document.startViewTransition(() => {
|
|
@@ -2541,19 +2640,26 @@ var BottomSheetEngine = class {
|
|
|
2541
2640
|
} else {
|
|
2542
2641
|
await this.animation.animateTo(target.size, velocityPxPerMs);
|
|
2543
2642
|
}
|
|
2643
|
+
this.opening = false;
|
|
2544
2644
|
externalSignal?.removeEventListener("abort", onExternalAbort);
|
|
2545
2645
|
if (signal.aborted) return;
|
|
2546
2646
|
this.scrollCache.restore(id, previousSize, target.size);
|
|
2547
2647
|
this.updateAriaSlider();
|
|
2548
|
-
this.emit("snap", {
|
|
2648
|
+
this.emit("snap", {
|
|
2649
|
+
id,
|
|
2650
|
+
size: target.size,
|
|
2651
|
+
progress: this.computeProgress(target.size)
|
|
2652
|
+
});
|
|
2549
2653
|
if (wasClosed && target.size > 0) {
|
|
2550
2654
|
this.emit("open", { id });
|
|
2551
2655
|
this.handleOpen();
|
|
2552
2656
|
notifyLinkedSheets(this.linkedSheets, this);
|
|
2657
|
+
this.emit("opened", { id });
|
|
2553
2658
|
}
|
|
2554
2659
|
if (target.size === 0) {
|
|
2555
2660
|
this.emit("close", void 0);
|
|
2556
2661
|
this.handleClose();
|
|
2662
|
+
this.emit("closed", void 0);
|
|
2557
2663
|
}
|
|
2558
2664
|
}
|
|
2559
2665
|
async dragTo(targetSize, velocityOrOpts = 0) {
|
|
@@ -2578,11 +2684,74 @@ var BottomSheetEngine = class {
|
|
|
2578
2684
|
const target = id ?? this.snaps.getAllowedIds().find((a) => a !== "closed") ?? this.activeId;
|
|
2579
2685
|
return this.snapTo(target);
|
|
2580
2686
|
}
|
|
2581
|
-
close() {
|
|
2687
|
+
close(reason = "programmatic") {
|
|
2582
2688
|
if (this.destroyed) return Promise.resolve();
|
|
2689
|
+
if (this.disableCloseFlag) return Promise.resolve();
|
|
2690
|
+
if (this.size > 0 && this.emitBeforeClose(reason)) return Promise.resolve();
|
|
2583
2691
|
const closedId = this.snapPointsRaw.find((p) => p.id === "closed")?.id ?? this.snaps.getAllowedIds()[0];
|
|
2584
2692
|
return this.snapTo(closedId ?? this.activeId);
|
|
2585
2693
|
}
|
|
2694
|
+
canDismiss() {
|
|
2695
|
+
return !this.persistent && !this.disableCloseFlag && !this.destroyed;
|
|
2696
|
+
}
|
|
2697
|
+
isTop() {
|
|
2698
|
+
return this.isTopSheet;
|
|
2699
|
+
}
|
|
2700
|
+
depth() {
|
|
2701
|
+
return sheetStack.depthOf(this.id);
|
|
2702
|
+
}
|
|
2703
|
+
expand() {
|
|
2704
|
+
if (this.destroyed) return Promise.resolve();
|
|
2705
|
+
const ids = this.allowedIdsBySize();
|
|
2706
|
+
const target = ids[ids.length - 1];
|
|
2707
|
+
if (!target) return Promise.resolve();
|
|
2708
|
+
return this.snapTo(target);
|
|
2709
|
+
}
|
|
2710
|
+
collapse() {
|
|
2711
|
+
if (this.destroyed) return Promise.resolve();
|
|
2712
|
+
const ids = this.allowedIdsBySize();
|
|
2713
|
+
const nonZero = ids.find((id) => (this.snaps.findById(id)?.size ?? 0) > 0);
|
|
2714
|
+
const target = nonZero ?? ids[0];
|
|
2715
|
+
if (!target) return Promise.resolve();
|
|
2716
|
+
return this.snapTo(target);
|
|
2717
|
+
}
|
|
2718
|
+
setRadius(r) {
|
|
2719
|
+
if (this.destroyed) return;
|
|
2720
|
+
this.element.style.setProperty(
|
|
2721
|
+
"--bs-radius",
|
|
2722
|
+
typeof r === "number" ? `${r}px` : r
|
|
2723
|
+
);
|
|
2724
|
+
}
|
|
2725
|
+
setMaxHeight(h) {
|
|
2726
|
+
if (this.destroyed) return;
|
|
2727
|
+
const value = typeof h === "number" ? `${h}px` : h;
|
|
2728
|
+
const axis = layoutAxis(this.mode);
|
|
2729
|
+
this.element.style.setProperty(
|
|
2730
|
+
axis === "height" ? "maxHeight" : "maxWidth",
|
|
2731
|
+
value
|
|
2732
|
+
);
|
|
2733
|
+
if (typeof h === "number") {
|
|
2734
|
+
this.maxHeightCap = h;
|
|
2735
|
+
this.clampToMaxHeight();
|
|
2736
|
+
} else if (typeof window !== "undefined") {
|
|
2737
|
+
const probe2 = document.createElement("div");
|
|
2738
|
+
probe2.style.cssText = `position:absolute;visibility:hidden;pointer-events:none;${axis === "height" ? "height" : "width"}:${value};`;
|
|
2739
|
+
document.body.appendChild(probe2);
|
|
2740
|
+
const measured = axis === "height" ? probe2.offsetHeight : probe2.offsetWidth;
|
|
2741
|
+
probe2.remove();
|
|
2742
|
+
this.maxHeightCap = measured > 0 ? measured : void 0;
|
|
2743
|
+
this.clampToMaxHeight();
|
|
2744
|
+
}
|
|
2745
|
+
}
|
|
2746
|
+
clampToMaxHeight() {
|
|
2747
|
+
if (this.maxHeightCap === void 0) return;
|
|
2748
|
+
if (this.snaps.getMaxAxisSize() > this.maxHeightCap) {
|
|
2749
|
+
this.snaps.setMaxAxisSize(this.maxHeightCap);
|
|
2750
|
+
}
|
|
2751
|
+
if (this.size > this.maxHeightCap && !this.gesture?.isDragging) {
|
|
2752
|
+
this.applySize(this.maxHeightCap);
|
|
2753
|
+
}
|
|
2754
|
+
}
|
|
2586
2755
|
setAllowed(ids, snap) {
|
|
2587
2756
|
if (this.destroyed) return;
|
|
2588
2757
|
this.snaps.setAllowedIds(ids);
|
|
@@ -2716,8 +2885,53 @@ var BottomSheetEngine = class {
|
|
|
2716
2885
|
}
|
|
2717
2886
|
this.updateAriaSlider();
|
|
2718
2887
|
}
|
|
2888
|
+
recompute() {
|
|
2889
|
+
if (this.destroyed) return;
|
|
2890
|
+
this.snaps.recompute();
|
|
2891
|
+
this.scrim.invalidateOpacityCache();
|
|
2892
|
+
if (this.gesture?.isDragging) return;
|
|
2893
|
+
const current = this.snaps.findById(this.activeId);
|
|
2894
|
+
if (current) {
|
|
2895
|
+
this.size = current.size;
|
|
2896
|
+
this.applySize(this.size);
|
|
2897
|
+
this.updateAriaSlider();
|
|
2898
|
+
}
|
|
2899
|
+
}
|
|
2900
|
+
measureFitSize() {
|
|
2901
|
+
const vertical = layoutAxis(this.mode) === "height";
|
|
2902
|
+
const handleSize = vertical ? this.handle.offsetHeight : this.handle.offsetWidth;
|
|
2903
|
+
const content = this.scrollContainer;
|
|
2904
|
+
const natural = content ? handleSize + (vertical ? content.scrollHeight : content.scrollWidth) : handleSize;
|
|
2905
|
+
if (typeof window === "undefined") return natural;
|
|
2906
|
+
const viewport = vertical ? window.innerHeight : window.innerWidth;
|
|
2907
|
+
return viewport > 0 ? Math.min(natural, viewport) : natural;
|
|
2908
|
+
}
|
|
2909
|
+
installFitObserver() {
|
|
2910
|
+
if (typeof ResizeObserver === "undefined") return;
|
|
2911
|
+
if (!this.snapPointsRaw.some((p) => p.size === "fit" || p.size === "content"))
|
|
2912
|
+
return;
|
|
2913
|
+
const targets = [this.handle];
|
|
2914
|
+
if (this.scrollContainer && this.scrollContainer !== this.handle) {
|
|
2915
|
+
targets.push(this.scrollContainer);
|
|
2916
|
+
}
|
|
2917
|
+
let raf = 0;
|
|
2918
|
+
const ro = new ResizeObserver(() => {
|
|
2919
|
+
if (raf) return;
|
|
2920
|
+
raf = requestAnimationFrame(() => {
|
|
2921
|
+
raf = 0;
|
|
2922
|
+
if (this.destroyed || this.gesture?.isDragging) return;
|
|
2923
|
+
this.recompute();
|
|
2924
|
+
});
|
|
2925
|
+
});
|
|
2926
|
+
for (const t of targets) ro.observe(t);
|
|
2927
|
+
this.teardowns.add(() => {
|
|
2928
|
+
ro.disconnect();
|
|
2929
|
+
if (raf) cancelAnimationFrame(raf);
|
|
2930
|
+
});
|
|
2931
|
+
}
|
|
2719
2932
|
destroy() {
|
|
2720
2933
|
this.destroyed = true;
|
|
2934
|
+
this.opening = false;
|
|
2721
2935
|
this.currentAbort.abort();
|
|
2722
2936
|
this.currentViewTransition?.skipTransition?.();
|
|
2723
2937
|
this.currentViewTransition = null;
|
|
@@ -2767,6 +2981,36 @@ var BottomSheetEngine = class {
|
|
|
2767
2981
|
frozen = true;
|
|
2768
2982
|
return cancelled;
|
|
2769
2983
|
}
|
|
2984
|
+
emitBeforeClose(reason) {
|
|
2985
|
+
let cancelled = false;
|
|
2986
|
+
let frozen = false;
|
|
2987
|
+
this.emit("before-close", {
|
|
2988
|
+
reason,
|
|
2989
|
+
cancel: () => {
|
|
2990
|
+
if (frozen) {
|
|
2991
|
+
console.warn(
|
|
2992
|
+
"[BottomSheet] before-close.cancel() called asynchronously \u2014 ignored. cancel() must be invoked synchronously inside the listener."
|
|
2993
|
+
);
|
|
2994
|
+
return;
|
|
2995
|
+
}
|
|
2996
|
+
cancelled = true;
|
|
2997
|
+
}
|
|
2998
|
+
});
|
|
2999
|
+
frozen = true;
|
|
3000
|
+
return cancelled;
|
|
3001
|
+
}
|
|
3002
|
+
applyAutoAriaLabelledBy() {
|
|
3003
|
+
if (typeof document === "undefined") return;
|
|
3004
|
+
if (!this.lifecycle.focusTrapEnabled) return;
|
|
3005
|
+
if (this.element.getAttribute("aria-labelledby")) return;
|
|
3006
|
+
const scope = this.handle ?? this.element;
|
|
3007
|
+
const titled = scope.querySelector("[data-bs-title]") ?? scope.querySelector("h1,h2,h3,h4,h5,h6");
|
|
3008
|
+
if (!titled) return;
|
|
3009
|
+
if (!titled.id) {
|
|
3010
|
+
titled.id = nextInstanceId("bs-title");
|
|
3011
|
+
}
|
|
3012
|
+
this.element.setAttribute("aria-labelledby", titled.id);
|
|
3013
|
+
}
|
|
2770
3014
|
recomputeSnaps() {
|
|
2771
3015
|
const seen = /* @__PURE__ */ new Set();
|
|
2772
3016
|
for (const p of this.snapPointsRaw) {
|
|
@@ -2802,11 +3046,8 @@ var BottomSheetEngine = class {
|
|
|
2802
3046
|
},
|
|
2803
3047
|
setIsTop: (isTop) => {
|
|
2804
3048
|
this.isTopSheet = isTop;
|
|
2805
|
-
if (this.backdrop) {
|
|
2806
|
-
this.backdrop.style.display = isTop ? "" : "none";
|
|
2807
|
-
}
|
|
2808
3049
|
},
|
|
2809
|
-
isOpen: () => this.size > 0,
|
|
3050
|
+
isOpen: () => this.size > 0 || this.opening,
|
|
2810
3051
|
setDepth: (depth) => this.applyStackDepth(depth)
|
|
2811
3052
|
}));
|
|
2812
3053
|
}
|
|
@@ -2838,6 +3079,7 @@ var BottomSheetEngine = class {
|
|
|
2838
3079
|
buf.rubberBandEnabled = this.rubberBandEnabled;
|
|
2839
3080
|
return buf;
|
|
2840
3081
|
},
|
|
3082
|
+
getDisableDrag: () => this.disableDragFlag,
|
|
2841
3083
|
cancelAnimation: () => this.animation.cancel(),
|
|
2842
3084
|
applySize: (size) => this.applySize(size),
|
|
2843
3085
|
animateTo: (size, velocity) => this.animation.animateTo(size, velocity),
|
|
@@ -2917,8 +3159,9 @@ var BottomSheetEngine = class {
|
|
|
2917
3159
|
if (this.lifecycle.closeOnEscape) {
|
|
2918
3160
|
const onKey = (e) => {
|
|
2919
3161
|
if (this.destroyed || e.defaultPrevented) return;
|
|
3162
|
+
if (!this.canDismiss()) return;
|
|
2920
3163
|
if (e.key === "Escape" && this.isTopSheet && this.size > 0) {
|
|
2921
|
-
void this.close();
|
|
3164
|
+
void this.close("escape");
|
|
2922
3165
|
}
|
|
2923
3166
|
};
|
|
2924
3167
|
document.addEventListener("keydown", onKey);
|
|
@@ -2981,20 +3224,31 @@ var BottomSheetEngine = class {
|
|
|
2981
3224
|
const previousSnapSize = this.snaps.findById(previousId)?.size;
|
|
2982
3225
|
this.scrollCache.cache(previousId, previousSize, target.size);
|
|
2983
3226
|
this.activeId = target.id;
|
|
3227
|
+
if (previousSnapSize === 0 && target.size > 0) {
|
|
3228
|
+
this.opening = true;
|
|
3229
|
+
sheetStack.promote(this.id);
|
|
3230
|
+
}
|
|
2984
3231
|
void this.animation.animateTo(target.size, velocity).then(() => {
|
|
3232
|
+
this.opening = false;
|
|
2985
3233
|
if (signal.aborted) return;
|
|
2986
3234
|
this.scrollCache.restore(target.id, previousSize, target.size);
|
|
2987
3235
|
this.updateAriaSlider();
|
|
2988
|
-
this.emit("snap", {
|
|
3236
|
+
this.emit("snap", {
|
|
3237
|
+
id: target.id,
|
|
3238
|
+
size: target.size,
|
|
3239
|
+
progress: this.computeProgress(target.size)
|
|
3240
|
+
});
|
|
2989
3241
|
this.haptic();
|
|
2990
3242
|
if (previousSnapSize === 0 && target.size > 0) {
|
|
2991
3243
|
this.emit("open", { id: target.id });
|
|
2992
3244
|
this.handleOpen();
|
|
2993
3245
|
notifyLinkedSheets(this.linkedSheets, this);
|
|
3246
|
+
this.emit("opened", { id: target.id });
|
|
2994
3247
|
}
|
|
2995
3248
|
if (target.size === 0) {
|
|
2996
3249
|
this.emit("close", void 0);
|
|
2997
3250
|
this.handleClose();
|
|
3251
|
+
this.emit("closed", void 0);
|
|
2998
3252
|
}
|
|
2999
3253
|
});
|
|
3000
3254
|
}
|
|
@@ -3019,6 +3273,9 @@ var BottomSheetEngine = class {
|
|
|
3019
3273
|
if (this.anchorHost && this.anchorHost !== this.scrimParent) {
|
|
3020
3274
|
this.anchorHost.style.setProperty("--bs-size", `${size}px`);
|
|
3021
3275
|
}
|
|
3276
|
+
if (this.rootEl && this.rootEl !== this.scrimParent && this.rootEl !== this.anchorHost) {
|
|
3277
|
+
this.rootEl.style.setProperty("--bs-size", `${size}px`);
|
|
3278
|
+
}
|
|
3022
3279
|
}
|
|
3023
3280
|
const progress = this.computeProgress(size);
|
|
3024
3281
|
const progressChanged = this.progressWriteSentinel.shouldWrite(
|
|
@@ -3030,6 +3287,9 @@ var BottomSheetEngine = class {
|
|
|
3030
3287
|
if (this.anchorHost) {
|
|
3031
3288
|
this.anchorHost.style.setProperty("--bs-progress", String(progress));
|
|
3032
3289
|
}
|
|
3290
|
+
if (this.rootEl && this.rootEl !== this.anchorHost) {
|
|
3291
|
+
this.rootEl.style.setProperty("--bs-progress", String(progress));
|
|
3292
|
+
}
|
|
3033
3293
|
}
|
|
3034
3294
|
this.scrim.applyOpacity(progress, progressChanged);
|
|
3035
3295
|
if (progressChanged && this.bus.listenerCount("progress") > 0) {
|
|
@@ -3063,17 +3323,24 @@ var BottomSheetEngine = class {
|
|
|
3063
3323
|
const target = this.snaps.findById(this.activeId);
|
|
3064
3324
|
if (!target) return;
|
|
3065
3325
|
this.updateAriaSlider();
|
|
3066
|
-
this.emit("snap", {
|
|
3326
|
+
this.emit("snap", {
|
|
3327
|
+
id: target.id,
|
|
3328
|
+
size: target.size,
|
|
3329
|
+
progress: this.computeProgress(target.size)
|
|
3330
|
+
});
|
|
3067
3331
|
if (target.size > 0 && !this.lifecycle.isInstalled) {
|
|
3068
3332
|
this.emit("open", { id: target.id });
|
|
3069
3333
|
this.handleOpen();
|
|
3070
3334
|
notifyLinkedSheets(this.linkedSheets, this);
|
|
3335
|
+
this.emit("opened", { id: target.id });
|
|
3071
3336
|
} else if (target.size === 0 && this.lifecycle.isInstalled) {
|
|
3072
3337
|
this.emit("close", void 0);
|
|
3073
3338
|
this.handleClose();
|
|
3339
|
+
this.emit("closed", void 0);
|
|
3074
3340
|
}
|
|
3075
3341
|
}
|
|
3076
3342
|
handleClose() {
|
|
3343
|
+
this.opening = false;
|
|
3077
3344
|
this.lifecycle.release();
|
|
3078
3345
|
sheetStack.update();
|
|
3079
3346
|
}
|
|
@@ -3127,6 +3394,10 @@ function createBottomSheet(opts) {
|
|
|
3127
3394
|
snapTo: (id) => engine?.snapTo(id) ?? Promise.resolve(),
|
|
3128
3395
|
open: (id) => engine?.open(id) ?? Promise.resolve(),
|
|
3129
3396
|
close: () => engine?.close() ?? Promise.resolve(),
|
|
3397
|
+
expand: () => engine?.expand() ?? Promise.resolve(),
|
|
3398
|
+
collapse: () => engine?.collapse() ?? Promise.resolve(),
|
|
3399
|
+
isTop: () => engine?.isTop() ?? false,
|
|
3400
|
+
depth: () => engine?.depth() ?? 0,
|
|
3130
3401
|
setAllowed: (ids, snap) => engine?.setAllowed(ids, snap),
|
|
3131
3402
|
setSnapPoints: (points, allowed) => engine?.setSnapPoints(points, allowed),
|
|
3132
3403
|
setScrim: (scrimOpts) => engine?.setScrim(scrimOpts),
|
|
@@ -3136,6 +3407,7 @@ function createBottomSheet(opts) {
|
|
|
3136
3407
|
}),
|
|
3137
3408
|
setScrimStages: (stagesOpts) => engine?.setScrimStages(stagesOpts) ?? (() => {
|
|
3138
3409
|
}),
|
|
3410
|
+
recompute: () => engine?.recompute(),
|
|
3139
3411
|
destroy: () => {
|
|
3140
3412
|
engine?.destroy();
|
|
3141
3413
|
engine = null;
|