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

@lexion-rte/ui

v0.1.0

Published

Toolbar UI primitives for integrating Lexion editors.

Downloads

11

Readme

Lexion Logo

This package is part of the Lexion framework-agnostic rich text editor.

Lexion is a framework-agnostic, headless rich text editor platform built on ProseMirror, designed to provide a shared core, reusable extensions, and framework-specific adapters.

@lexion-rte/ui

Toolbar UI primitives for Lexion integrations.

Overview

@lexion-rte/ui provides a toolbar area with icon-first buttons and command wiring to @lexion-rte/core.

It supports:

  • command execution through editor.execute(...)
  • automatic focus restoration through editor.focus?.() before command execution
  • item management methods (setItems, addItem, updateItem, removeItem)
  • icon states: enabled, disabled, hidden
  • Remix Icon class names (for example ri-bold)

Install

pnpm add @lexion-rte/ui remixicon

Example 1: Minimal Toolbar

import { LexionEditor } from "@lexion-rte/core";
import { starterKitExtension } from "@lexion-rte/starter-kit";
import {
  createLexionToolbar,
  createToolbarSeparatorItem,
  lexionToolbarIcons,
  injectLexionToolbarStyles
} from "@lexion-rte/ui";

import "remixicon/fonts/remixicon.css";

injectLexionToolbarStyles();

const editor = new LexionEditor({ extensions: [starterKitExtension] });
const toolbarHost = document.getElementById("toolbar");
if (!toolbarHost) throw new Error("Missing #toolbar");

const toolbar = createLexionToolbar({
  element: toolbarHost,
  editor,
  items: [
    { id: "bold", iconClass: lexionToolbarIcons.bold, label: "Bold", command: "toggleBold" },
    { id: "italic", iconClass: lexionToolbarIcons.italic, label: "Italic", command: "toggleItalic" },
    createToolbarSeparatorItem("sep-main"),
    { id: "undo", iconClass: lexionToolbarIcons.undo, label: "Undo", command: "undo" }
  ]
});

Example 2: Full Starter-kit Preset

import { LexionEditor } from "@lexion-rte/core";
import { starterKitExtension } from "@lexion-rte/starter-kit";
import {
  createLexionToolbar,
  createStarterKitToolbarItems,
  injectLexionToolbarStyles
} from "@lexion-rte/ui";

import "remixicon/fonts/remixicon.css";

injectLexionToolbarStyles();

const editor = new LexionEditor({ extensions: [starterKitExtension] });

const toolbar = createLexionToolbar({
  element: document.getElementById("toolbar")!,
  editor,
  items: createStarterKitToolbarItems({ withLabels: true })
});

// Example state changes
toolbar.disableItem("redo");
toolbar.hideItem("unset-link");

Example 3: Group Buttons in a Dropdown

const toolbar = createLexionToolbar({
  element: document.getElementById("toolbar")!,
  editor,
  items: [
    {
      id: "inline-format",
      iconClass: lexionToolbarIcons.textFormat,
      title: "Inline format",
      items: [
        { id: "bold", iconClass: lexionToolbarIcons.bold, label: "Bold", command: "toggleBold" },
        { id: "italic", iconClass: lexionToolbarIcons.italic, label: "Italic", command: "toggleItalic" },
        { id: "underline", iconClass: lexionToolbarIcons.underline, label: "Underline", command: "toggleUnderline" }
      ]
    }
  ]
});

Each dropdown row renders the icon + command name.

Example 4: Dynamic Enabled/Disabled/Hidden States

import type { LexionToolbar } from "@lexion-rte/ui";

function applyToolbarPolicy(toolbar: LexionToolbar, canEdit: boolean, canLink: boolean): void {
  toolbar.setItemStates({
    bold: canEdit ? "enabled" : "disabled",
    italic: canEdit ? "enabled" : "disabled",
    "set-link": canLink ? "enabled" : "hidden",
    "unset-link": canLink ? "enabled" : "hidden"
  });
}

Example 5: Add Visual Separators (No Dropdown)

toolbar.setItems([
  { id: "bold", iconClass: lexionToolbarIcons.bold, title: "Bold", command: "toggleBold" },
  { id: "italic", iconClass: lexionToolbarIcons.italic, title: "Italic", command: "toggleItalic" },
  { id: "sep-inline-actions", separator: true },
  { id: "undo", iconClass: lexionToolbarIcons.undo, title: "Undo", command: "undo" },
  { id: "redo", iconClass: lexionToolbarIcons.redo, title: "Redo", command: "redo" }
]);

Example 6: Add/Update/Remove Items at Runtime

toolbar.addItem({
  id: "save",
  iconClass: lexionToolbarIcons.save,
  label: "Save",
  title: "Save document",
  onClick: () => {
    console.log("saved");
    return false; // stop command execution path
  }
});

toolbar.updateItem("save", {
  iconClass: lexionToolbarIcons.check,
  label: "Saved",
  state: "disabled"
});

toolbar.removeItem("save");

Example 7: Integrate with @lexion-rte/web

import { createLexionWebEditor } from "@lexion-rte/web";
import {
  createLexionToolbar,
  createStarterKitToolbarItems,
  injectLexionToolbarStyles
} from "@lexion-rte/ui";

import "remixicon/fonts/remixicon.css";

injectLexionToolbarStyles();

const editorHost = document.getElementById("editor")!;
const toolbarHost = document.getElementById("toolbar")!;

const webEditor = createLexionWebEditor({
  element: editorHost
});

const toolbar = createLexionToolbar({
  element: toolbarHost,
  editor: webEditor,
  items: createStarterKitToolbarItems({ withLabels: false }),
  onItemExecute: (event) => {
    console.log(`toolbar: ${event.item.id}, executed: ${event.executed}`);
  }
});

// cleanup
window.addEventListener("beforeunload", () => {
  toolbar.destroy();
  webEditor.destroy();
});

Example 8: Inject Styles into a Specific Document

Useful for iframes or custom document roots.

const iframeDocument = iframe.contentDocument;
if (!iframeDocument) throw new Error("Iframe document not ready");

injectLexionToolbarStyles({
  document: iframeDocument,
  id: "lexion-toolbar-ui-styles"
});

API

LexionToolbarOptions

  • element: HTMLElement (required)
  • editor?: { execute(command, ...args): boolean; focus?(): void }
  • items?: LexionToolbarItemInput[]
  • className?: string
  • onItemExecute?: (event) => void

LexionToolbarItemInput supports:

  • command button item (command, args, label, iconClass, ...)
  • dropdown group item (items) where each nested item has iconClass + label + command config
  • separator item (separator: true) for visual grouping in the same toolbar row

LexionToolbarItemState

  • "enabled"
  • "disabled"
  • "hidden"

LexionToolbar methods

  • setEditor(editor | null)
  • getItems()
  • setItems(items)
  • addItem(item, index?)
  • updateItem(id, update)
  • removeItem(id)
  • clearItems()
  • setItemState(id, state)
  • setItemStates(record)
  • enableItem(id)
  • disableItem(id)
  • hideItem(id)
  • showItem(id, state?)
  • destroy()

Styling helpers

  • lexionToolbarStyles
  • injectLexionToolbarStyles(options?)
  • lexionToolbarAppearance

Starter-kit preset

  • createStarterKitToolbarItems(options?)
  • createToolbarSeparatorItem(id, state?)
  • lexionToolbarIcons