-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: support svelte v5 * Revert prettier-plugin-svelte * chore: update cypress * Call flushSync after mounting * make sure flushSync won't be imported in v4 * refactor variable name * fix build
- Loading branch information
Showing
15 changed files
with
651 additions
and
2,195 deletions.
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 @@ | ||
--- | ||
"@prosemirror-adapter/svelte": minor | ||
--- | ||
|
||
Support Svelte v5. |
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
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
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
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
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,35 @@ | ||
import * as svelte from 'svelte' | ||
import type { | ||
SvelteClassComponentConstructor, | ||
SvelteComponentConstructor, | ||
} from './types' | ||
|
||
const isSvelte5 = !!svelte.mount && !!svelte.flushSync | ||
|
||
interface MountOptions { | ||
target: HTMLElement | ||
context: Map<string, unknown> | ||
} | ||
|
||
function mountFunctionComponent(UserComponent: SvelteComponentConstructor, options: MountOptions): VoidFunction { | ||
// Using Svelte v5, where components are functions | ||
const component = svelte.mount(UserComponent, { ...options }) as svelte.SvelteComponent | ||
// Unlike `new UserComponent()` in Svelte v4, `mount()` in Svelte v5 doesn't | ||
// call `onMount()` and action functions automatically. So we need to call | ||
// `flushSync()` to ensure they run. | ||
svelte.flushSync() | ||
return () => svelte.unmount(component) | ||
} | ||
|
||
function mountClassComponent(UserComponent: SvelteComponentConstructor, options: MountOptions): VoidFunction { | ||
// Using Svelte v4, where components are classes | ||
const component = new (UserComponent as SvelteClassComponentConstructor)(options) | ||
return () => component.$destroy() | ||
} | ||
|
||
/** | ||
* Mounts a Svelte component to a DOM element. | ||
* | ||
* Returns a function that unmounts the component. | ||
*/ | ||
export const mount = isSvelte5 ? mountFunctionComponent : mountClassComponent |
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
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import type { ComponentConstructorOptions, SvelteComponent } from 'svelte' | ||
import type { Component, ComponentConstructorOptions, SvelteComponent } from 'svelte' | ||
|
||
export type AnyRecord = Record<string, any> | ||
export type SvelteComponentConstructor<T extends AnyRecord = AnyRecord> = new (options: ComponentConstructorOptions<T>) => SvelteComponent | ||
export type SvelteClassComponentConstructor<T extends AnyRecord = AnyRecord> = new (options: ComponentConstructorOptions<T>) => SvelteComponent | ||
export type SvelteComponentConstructor<T extends AnyRecord = AnyRecord> = SvelteClassComponentConstructor<T> | Component<T> | ||
|
||
export type Obj2Map<T extends AnyRecord> = Map<keyof T, T[keyof T]> |
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
Oops, something went wrong.