diff --git a/.cursor/rules/svelte-style.mdc b/.cursor/rules/svelte-style.mdc new file mode 100644 index 0000000..c23295e --- /dev/null +++ b/.cursor/rules/svelte-style.mdc @@ -0,0 +1,90 @@ +--- +description: +globs: *.svelte +alwaysApply: false +--- +# Svelte Style + +Observe the the following style guidelines when programming Svelte components or SvelteKit pages: + +- Always use idiomatic Svelte 5 syntax and features. Svelte 5 idioms include: + - Runes, such as `$state`, `$derived`, `$effect`, and `$props`. + - Callback props. + - Snippets. +- Avoid using deprecated Svelte 4 syntax and features. Depecrated features include: + - Props declared via `export let`. + - Event handlers attached via the `on:` directive. + - Event dispatchers. + - Component slots. +- Remember that Svelte 5 state is deeply reactive. + - Mutating a state object automatically triggers reactivity in most cases. + - Avoid trying to trigger reactivity by reassigning state variables unless other options have failed. +- Write components in TypeScript, and prefer strong typing for variables, props, and function signatures. +- Limit component logic to rendering concerns. Extract business logic into separate TypeScript modules, and import functions and classes into Svelte components as needed. + +## Component Code Organization Example + +When writing or editing a Svelte component, organize the code according to the following template: + +``` + + + +{#snippet contentParagraph(content: string, publicationType: string, isSectionStart: boolean)} +
+ {@html content} +
+{/snippet} + + +
+ {#await leafEvent} + {@render contentParagraph(leafEvent.content.toString(), publicationType ?? 'article', false)} + {/await} +
+ + + +``` \ No newline at end of file