-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: provide SvelteKit html typings
This makes it possible to delete these from svelte/elements in Svelte 5 and have them controled in SvelteKit, decoupling the two closes #10534
- Loading branch information
1 parent
184331a
commit 5be5689
Showing
4 changed files
with
51 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@sveltejs/kit': minor | ||
--- | ||
|
||
feat: provide SvelteKit html typings |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import path from 'node:path'; | ||
import { GENERATED_COMMENT } from '../../constants.js'; | ||
import { write_if_changed } from './utils.js'; | ||
|
||
// `declare module "svelte/elements"` needs to happen in a non-ambient module, and dts-buddy generates one big ambient module, | ||
// so we can't add it there - therefore generate the typings ourselves here. | ||
// We're not using the `declare namespace svelteHTML` variant because that one doesn't augment the HTMLAttributes interface | ||
// people could use to type their own components. | ||
// The T generic is needed or else there's a "all declarations must have identical type parameters" error. | ||
const template = ` | ||
${GENERATED_COMMENT} | ||
declare module "svelte/elements" { | ||
export interface HTMLAttributes<T> { | ||
'data-sveltekit-keepfocus'?: true | '' | 'off' | undefined | null; | ||
'data-sveltekit-noscroll'?: true | '' | 'off' | undefined | null; | ||
'data-sveltekit-preload-code'?: | ||
| true | ||
| '' | ||
| 'eager' | ||
| 'viewport' | ||
| 'hover' | ||
| 'tap' | ||
| 'off' | ||
| undefined | ||
| null; | ||
'data-sveltekit-preload-data'?: true | '' | 'hover' | 'tap' | 'off' | undefined | null; | ||
'data-sveltekit-reload'?: true | '' | 'off' | undefined | null; | ||
'data-sveltekit-replacestate'?: true | '' | 'off' | undefined | null; | ||
} | ||
} | ||
export {}; | ||
`; | ||
|
||
/** | ||
* Writes non-ambient declarations to the output directory | ||
* @param {import('types').ValidatedKitConfig} config | ||
*/ | ||
export function write_non_ambient(config) { | ||
write_if_changed(path.join(config.outDir, 'non-ambient.d.ts'), template); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters