Skip to content

Commit ff30c2b

Browse files
Adds snap events (#4947)
* adds snap events * types: Correct event type & backport SnapEvent DOM type --------- Co-authored-by: Ryan Christian <[email protected]>
1 parent 8ac2681 commit ff30c2b

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

src/dom.d.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,22 @@ interface CommandEventInit extends EventInit {
3333
command: string;
3434
}
3535

36+
/** [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/SnapEvent) */
37+
interface SnapEvent extends Event {
38+
readonly snapTargetBlock: Element | null;
39+
readonly snapTargetInline: Element | null;
40+
}
41+
42+
declare var SnapEvent: {
43+
prototype: SnapEvent;
44+
new (type: string, eventInitDict?: SnapEventInit): SnapEvent;
45+
}
46+
47+
interface SnapEventInit extends EventInit {
48+
snapTargetBlock?: Element | null;
49+
snapTargetInline?: Element | null;
50+
}
51+
3652
type Booleanish = boolean | 'true' | 'false';
3753

3854
export interface SignalLike<T> {
@@ -494,6 +510,10 @@ export type TargetedPointerEvent<Target extends EventTarget> = TargetedEvent<
494510
Target,
495511
PointerEvent
496512
>;
513+
export type TargetedSnapEvent<Target extends EventTarget> = TargetedEvent<
514+
Target,
515+
SnapEvent
516+
>;
497517
export type TargetedSubmitEvent<Target extends EventTarget> = TargetedEvent<
498518
Target,
499519
SubmitEvent
@@ -561,6 +581,9 @@ export type MouseEventHandler<Target extends EventTarget> = EventHandler<
561581
export type PointerEventHandler<Target extends EventTarget> = EventHandler<
562582
TargetedPointerEvent<Target>
563583
>;
584+
export type SnapEventHandler<Target extends EventTarget> = EventHandler<
585+
TargetedSnapEvent<Target>
586+
>;
564587
export type SubmitEventHandler<Target extends EventTarget> = EventHandler<
565588
TargetedSubmitEvent<Target>
566589
>;
@@ -777,6 +800,10 @@ export interface DOMAttributes<Target extends EventTarget>
777800
onScrollCapture?: GenericEventHandler<Target> | undefined;
778801
onScrollEnd?: GenericEventHandler<Target> | undefined;
779802
onScrollEndCapture?: GenericEventHandler<Target> | undefined;
803+
onScrollSnapChange?: SnapEventHandler<Target> | undefined;
804+
onScrollSnapChangeCapture?: SnapEventHandler<Target> | undefined;
805+
onScrollSnapChanging?: SnapEventHandler<Target> | undefined;
806+
onScrollSnapChangingCapture?: SnapEventHandler<Target> | undefined;
780807

781808
// Wheel Events
782809
onWheel?: WheelEventHandler<Target> | undefined;

src/jsx.d.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,22 @@ interface CommandEventInit extends EventInit {
5959
command: string;
6060
}
6161

62+
/** [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/SnapEvent) */
63+
interface SnapEvent extends Event {
64+
readonly snapTargetBlock: Element | null;
65+
readonly snapTargetInline: Element | null;
66+
}
67+
68+
declare var SnapEvent: {
69+
prototype: SnapEvent;
70+
new (type: string, eventInitDict?: SnapEventInit): SnapEvent;
71+
}
72+
73+
interface SnapEventInit extends EventInit {
74+
snapTargetBlock?: Element | null;
75+
snapTargetInline?: Element | null;
76+
}
77+
6278
export namespace JSXInternal {
6379
export type LibraryManagedAttributes<Component, Props> = Component extends {
6480
defaultProps: infer Defaults;
@@ -563,6 +579,11 @@ export namespace JSXInternal {
563579
PointerEvent
564580
>;
565581
/** @deprecated Please import from the Preact namespace instead */
582+
export type TargetedSnapEvent<Target extends EventTarget> = TargetedEvent<
583+
Target,
584+
SnapEvent
585+
>;
586+
/** @deprecated Please import from the Preact namespace instead */
566587
export type TargetedSubmitEvent<Target extends EventTarget> = TargetedEvent<
567588
Target,
568589
SubmitEvent
@@ -647,6 +668,10 @@ export namespace JSXInternal {
647668
TargetedPointerEvent<Target>
648669
>;
649670
/** @deprecated Please import from the Preact namespace instead */
671+
export type SnapEventHandler<Target extends EventTarget> = EventHandler<
672+
TargetedSnapEvent<Target>
673+
>;
674+
/** @deprecated Please import from the Preact namespace instead */
650675
export type SubmitEventHandler<Target extends EventTarget> = EventHandler<
651676
TargetedSubmitEvent<Target>
652677
>;
@@ -869,6 +894,10 @@ export namespace JSXInternal {
869894
onScrollCapture?: GenericEventHandler<Target> | undefined;
870895
onScrollEnd?: GenericEventHandler<Target> | undefined;
871896
onScrollEndCapture?: GenericEventHandler<Target> | undefined;
897+
onScrollSnapChange?: SnapEventHandler<Target> | undefined;
898+
onScrollSnapChangeCapture?: SnapEventHandler<Target> | undefined;
899+
onScrollSnapChanging?: SnapEventHandler<Target> | undefined;
900+
onScrollSnapChangingCapture?: SnapEventHandler<Target> | undefined;
872901

873902
// Wheel Events
874903
onWheel?: WheelEventHandler<Target> | undefined;

0 commit comments

Comments
 (0)