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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@milkdown-lab/plugin-menu

v1.3.1

Published

The plugin adds menubar of milkdown

Downloads

558

Readme

@milkdown-lab/plugin-menu

Plugin add menubar for milkdown editor

Usage

pnpm add @milkdown-lab/plugin-menu
import { menu, menuDefaultConfig } from '@milkdown-lab/plugin-menu'
// ...
const editor = await Editor.make()
  .config(menuDefaultConfig)
  .config(() => {
    ctx.set(rootCtx, document.querySelector('#app'))
  })
  .use(menu)
  .create()

Options

Styling

@milkdown-lab/plugin-menu is now headless as same as milkdown v7, see here for reason, so you need styling by yourself.

The style might be complex, this package offered a .css file @milkdown-lab/plugin-menu/style.css for reference

Menubar create by this plugin will create HTML structure like:

<div class="milkdown-menu">
    <ul role="menubar" aria-label="Editor menubar">
        <!-- for button menuitem -->
        <li role="none">
            <button role="menuitem" type="button">
                <span class="material-icons material-icons-outlined">turn_left</span>
            </button>
        </li>
        <!-- for select menuitem -->
        <li role="none">
            <button role="menuitem" type="button" aria-haspopup="true" aria-expanded="false" tab-index="0">
                Heading<span class="material-icons material-icons-outlined">expand_more</span>
            </button>
            <ul role="menu" data-option="Heading" aria-label="Heading" tabindex="-1" class="">
                <li role="menuitem" tabindex="-1">Large Heading</li>
                <li role="menuitem" tabindex="-1">Medium Heading</li>
                <li role="menuitem" tabindex="-1">Small Heading</li>
                <li role="menuitem" tabindex="-1">Plain Text</li>
            </ul>
        </li>
        <!-- for separator -->
        <li role="none">
            <div role="separator"></div>
        </li>
    </ul>
</div>

Adding custom attributes

You can also add attributes to menu element which was div.milkdown-menu by default configuration.

import { menu, menuConfigCtx, defaultConfigItems } from '@milkdown-lab/plugin-menu'
// ...
const editor = await Editor.make()
  .config(() => {
    ctx.set(menuConfigCtx.key, {
      attributes: { class: 'milkdown-menu', 'data-menu': 'true' },
      items: defaultConfigItems,
    })
    ctx.set(rootCtx, document.querySelector('#app'))
  })
  .use(menu)
  .create()

configuration menubar defaultConfigItems

menu items type just reference MenuConfigItem

import { menu, menuConfigCtx, MenuConfigItem } from '@milkdown-lab/plugin-menu'
// ...

const menuItems: MenuConfigItem[][] = [
  [
    {
      type: 'select',
      text: 'Heading',
      options: [
        { id: 1, content: 'Large Heading' },
        { id: 2, content: 'Medium Heading' },
        { id: 3, content: 'Small Heading' },
        { id: 0, content: 'Plain Text' },
      ],
      // return [commandKey,payload] or commandKey
      onSelect: (id) => (!!id ? ['WrapInHeading', id] : 'TurnIntoText'),
    },
  ],
  [
    {
      type: 'button',
      content: 'B',
      // commandKey
      key: 'ToggleStrong',
    },
    {
      type: 'button',
      content: 'I',
      key: 'ToggleEmphasis',
    },
    {
      type: 'button',
      content: 'S',
      key: 'ToggleStrikeThrough',
    },
  ],
]

const editor = await Editor.make()
  .config(() => {
    ctx.set(menuConfigCtx.key, {
      attributes: { class: 'milkdown-menu', 'data-menu': 'true' },
      items: menuItems,
    })
    ctx.set(rootCtx, document.querySelector('#app'))
  })
  .use(menu)
  .create()