fix: add `anchor` support to mount() API (#11050)

* fix: add `anchor` support to mount() API

* use ??

* fix inconsistent formatting

* required options before optional ones

* regenerate types

---------

Co-authored-by: Rich Harris <rich.harris@vercel.com>
pull/11057/head
Dominic Gannaway 8 months ago committed by GitHub
parent b2892b02e1
commit b87d57dc6e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
"svelte": patch
---
fix: add `anchor` support to mount() API

@ -90,6 +90,7 @@ export function stringify(value) {
* @param {import('../../index.js').ComponentType<import('../../index.js').SvelteComponent<Props, Events>>} component * @param {import('../../index.js').ComponentType<import('../../index.js').SvelteComponent<Props, Events>>} component
* @param {{ * @param {{
* target: Document | Element | ShadowRoot; * target: Document | Element | ShadowRoot;
* anchor?: Node;
* props?: Props; * props?: Props;
* events?: { [Property in keyof Events]: (e: Events[Property]) => any }; * events?: { [Property in keyof Events]: (e: Events[Property]) => any };
* context?: Map<any, any>; * context?: Map<any, any>;
@ -98,7 +99,7 @@ export function stringify(value) {
* @returns {Exports} * @returns {Exports}
*/ */
export function mount(component, options) { export function mount(component, options) {
const anchor = options.target.appendChild(empty()); const anchor = options.anchor ?? options.target.appendChild(empty());
// Don't flush previous effects to ensure order of outer effects stays consistent // Don't flush previous effects to ensure order of outer effects stays consistent
return flush_sync(() => _mount(component, { ...options, anchor }), false); return flush_sync(() => _mount(component, { ...options, anchor }), false);
} }

@ -300,6 +300,7 @@ declare module 'svelte' {
* */ * */
export function mount<Props extends Record<string, any>, Exports extends Record<string, any>, Events extends Record<string, any>>(component: ComponentType<SvelteComponent<Props, Events, any>>, options: { export function mount<Props extends Record<string, any>, Exports extends Record<string, any>, Events extends Record<string, any>>(component: ComponentType<SvelteComponent<Props, Events, any>>, options: {
target: Document | Element | ShadowRoot; target: Document | Element | ShadowRoot;
anchor?: Node | undefined;
props?: Props | undefined; props?: Props | undefined;
events?: { [Property in keyof Events]: (e: Events[Property]) => any; } | undefined; events?: { [Property in keyof Events]: (e: Events[Property]) => any; } | undefined;
context?: Map<any, any> | undefined; context?: Map<any, any> | undefined;

Loading…
Cancel
Save