npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@hvniel/lexical-svelte

v0.1.1

Published

This package provides Lexical components and hooks for Svelte applications.

Readme

@hvniel/lexical-svelte

Stable release

Svelte 5 components and utilities for building Lexical editors. The package ports the useful composition and plugin surface of @lexical/react into Svelte-native components, snippets, effects, and context.

Installation

npm install lexical @hvniel/lexical-svelte

Preprocessor setup

Lexical deliberately prefixes update/read-scope functions with $, but Svelte reserves that prefix for runes and store subscriptions. The included preprocessor lets you use Lexical's canonical named imports without manual aliases or namespace imports.

Configure the component preprocessor in svelte.config.js:

import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
import { lexicalPreprocess } from '@hvniel/lexical-svelte/preprocess';

/** @type {import('@sveltejs/kit').Config} */
const config = {
	preprocess: [lexicalPreprocess(), vitePreprocess()]
};

export default config;

Add the companion Vite hook for .svelte.js, .svelte.ts, and Svelte test modules in vite.config.ts:

import { sveltekit } from '@sveltejs/kit/vite';
import { lexicalImports } from '@hvniel/lexical-svelte/preprocess';
import { defineConfig } from 'vite';

export default defineConfig({
	plugins: [lexicalImports(), sveltekit()]
});

Both functions accept the same options:

const lexicalOptions = {
	packages: ['lexical', '@lexical', '@hvniel/lexical-svelte', '@acme/editor', '$lib', '.', '..'],
	markers: ['@lexical-scope', 'lex']
};

lexicalPreprocess(lexicalOptions);
lexicalImports(lexicalOptions);
  • packages controls which named imports are processed. Entries match the package itself and its subpaths. The defaults are lexical, @lexical, and @hvniel/lexical-svelte.
  • markers accepts one string or an array. The default is @lexical-scope.
  • Named imports remain statically analyzable and tree-shakeable.
  • Explicit aliases, type-only imports, unrelated packages, and shadowed bindings remain unchanged.

Local scope functions

Use an exact, adjacent marker when declaring a Lexical-scope function inside .svelte or .svelte.ts source:

<script lang="ts">
	// @lexical-scope
	function $readSelection() {
		return $getSelection();
	}
</script>

Block comments work too:

/* @lexical-scope */
function $readSelection() {
	return $getSelection();
}

The marker must directly precede a function declaration. A blank line detaches it. Plain .ts and .js files do not need markers because they are not subject to Svelte's dollar-prefix restriction.

Basic editor

<script lang="ts">
	import { $getRoot, $getSelection } from 'lexical';
	import {
		ContentEditable,
		HistoryPlugin,
		LexicalComposer,
		LexicalErrorBoundary,
		OnChangePlugin,
		PlainTextPlugin
	} from '@hvniel/lexical-svelte';

	const theme = {};

	function onError(error: Error) {
		throw error;
	}

	const initialConfig = {
		namespace: 'MyEditor',
		theme,
		onError
	};

	function onChange(editorState) {
		editorState.read(() => {
			const root = $getRoot();
			const selection = $getSelection();
			console.log(root, selection);
		});
	}
</script>

<LexicalComposer {initialConfig}>
	<PlainTextPlugin errorBoundary={LexicalErrorBoundary}>
		{#snippet contenteditable()}
			<ContentEditable />
		{/snippet}
	</PlainTextPlugin>
	<HistoryPlugin />
	<OnChangePlugin {onChange} />
</LexicalComposer>

Lexical Svelte plugins are ordinary Svelte components, so they compose naturally and can be loaded only where an editor needs them.