File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ ---
2+ " @svelte-put/intersect " : patch
3+ ---
4+
5+ provide ambient typings for custom events
Original file line number Diff line number Diff line change @@ -22,10 +22,6 @@ declare namespace svelte.JSX {
2222 ) => void ;
2323 // on:movableend
2424 onmovableend ?: ( event : CustomEvent < import ( '@svelte-put/movable' ) . MovableEventDetails > ) => void ;
25- // on:intersect
26- onintersect ?: ( event : CustomEvent < import ( '@svelte-put/intersect' ) . IntersectDetail > ) => void ;
27- // on:intersectonce
28- onintersectonce ?: ( event : CustomEvent < import ( '@svelte-put/intersect' ) . IntersectDetail > ) => void ;
2925 // on:toc
3026 ontoc ?: ( event : CustomEvent < import ( '@svelte-put/toc' ) . TocEventDetails > ) => void ;
3127 }
Original file line number Diff line number Diff line change @@ -56,7 +56,7 @@ See [examples here](https://github.com/vnphanquang/svelte-put/blob/main/packages
5656
5757### Typescript support
5858
59- Ambient types for ` on:clickoutside ` should be available automatically when ` clickoutside ` is imported
59+ Ambient types for custom events should be available automatically where ` clickoutside ` is imported.
6060
6161<details open >
6262 <summary > show / hide </summary >
Original file line number Diff line number Diff line change @@ -61,6 +61,27 @@ See [examples here](https://github.com/vnphanquang/svelte-put/blob/main/packages
6161
6262### Typescript support
6363
64+ Ambient types for custom events should be available automatically where ` intersect ` is imported.
65+
66+ <details open >
67+ <summary > show / hide </summary >
68+
69+ ``` html
70+ <script lang =" ts" >
71+ import { intersect } from ' @svelte-put/intersect' ;
72+ </script >
73+
74+ <!-- on:intersect, on:intersectonce should be typed -->
75+ <div
76+ use:intersect
77+ on:intersect
78+ on:intersectonce
79+ />
80+ ```
81+
82+ </details >
83+
84+ If the above is not working, fall back to this:
6485<details open >
6586 <summary > app.d.ts: show / hide </summary >
6687
Original file line number Diff line number Diff line change 77 */
88
99export * from './intersect' ;
10+ export * from './intersect.types' ;
Original file line number Diff line number Diff line change 1- /**
2- * svelte action parameters to config behavior of `movable`
3- * @public
4- *
5- * @remarks
6- *
7- * parameters for `intersect` extends {@link https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserver | IntersectionObserverInit }
8- * (second parameter passed to IntersectionObserver constructor)
9- */
10- export interface IntersectParameters extends IntersectionObserverInit {
11- /** whether to activate the action. Default to `true` */
12- enabled ?: boolean ;
13- }
1+ import { IntersectAttributes , IntersectDetail , IntersectParameters } from './intersect.types' ;
142
15- /**
16- * `detail` payload for `intersect` and `intersectonce` CustomEvent
17- * @public
18- * ```
19- */
20- export interface IntersectDetail {
21- /** the IntersectionObserver itself */
22- readonly observer : IntersectionObserver ;
23- /** list of IntersectionObserverEntry passed from IntersectionObserver callback */
24- readonly entries : IntersectionObserverEntry [ ] ;
3+ // ambient typing
4+ declare global {
5+ // eslint-disable-next-line @typescript-eslint/no-namespace
6+ export namespace svelte . JSX {
7+ // eslint-disable-next-line @typescript-eslint/no-empty-interface
8+ export interface HTMLAttributes extends IntersectAttributes { }
9+ }
2510}
2611
2712/**
Original file line number Diff line number Diff line change 1+ /**
2+ * Additional attributes extended from `svelte-put/intersect`
3+ * @public
4+ *
5+ * @remarks
6+ * The ambient types for these extended attributes should be available automatically
7+ * whenever `svelte-put/intersect` is imported.
8+ *
9+ * ```html
10+ * <script lang="ts">
11+ * import { intersect } from '@svelte-put/intersect';
12+ * </script>
13+ *
14+ * <!-- on:intersect, on:intersectonce should be typed -->
15+ * <div
16+ * use:intersect
17+ * on:intersect
18+ * on:intersectonce
19+ * />
20+ * ```
21+ */
22+ export interface IntersectAttributes {
23+ onintersect ?: ( event : CustomEvent < IntersectDetail > ) => void ; // on:intersect
24+ onintersectonce ?: ( event : CustomEvent < IntersectDetail > ) => void ; // on:intersectonce
25+ }
26+
27+ /**
28+ * svelte action parameters to config behavior of `movable`
29+ * @public
30+ *
31+ * @remarks
32+ *
33+ * parameters for `intersect` extends {@link https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserver | IntersectionObserverInit }
34+ * (second parameter passed to IntersectionObserver constructor)
35+ */
36+ export interface IntersectParameters extends IntersectionObserverInit {
37+ /** whether to activate the action. Default to `true` */
38+ enabled ?: boolean ;
39+ }
40+
41+ /**
42+ * `detail` payload for `intersect` and `intersectonce` CustomEvent
43+ * @public
44+ * ```
45+ */
46+ export interface IntersectDetail {
47+ /** the IntersectionObserver itself */
48+ readonly observer : IntersectionObserver ;
49+ /** list of IntersectionObserverEntry passed from IntersectionObserver callback */
50+ readonly entries : IntersectionObserverEntry [ ] ;
51+ }
You can’t perform that action at this time.
0 commit comments