Installations
npm install prosemirror-menu
Score
99.5
Supply Chain
99.6
Quality
75.9
Maintenance
100
Vulnerability
100
License
Releases
Unable to fetch releases
Contributors
Developer
Developer Guide
Module System
ESM
Min. Node Version
Typescript Support
Yes
Node Version
19.7.0
NPM Version
9.6.7
Statistics
53 Stars
359 Commits
75 Forks
6 Watching
1 Branches
25 Contributors
Updated on 23 Oct 2024
Languages
TypeScript (90.98%)
CSS (9.02%)
Total Downloads
Cumulative downloads
Total Downloads
58,627,982
Last day
-3.9%
221,977
Compared to previous day
Last week
1.6%
1,189,924
Compared to previous week
Last month
15.4%
4,974,810
Compared to previous month
Last year
172.8%
40,957,484
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dev Dependencies
1
prosemirror-menu
[ WEBSITE | ISSUES | FORUM | GITTER ]
This is a non-core example module for ProseMirror. ProseMirror is a well-behaved rich semantic content editor based on contentEditable, with support for collaborative editing and custom document schemas.
This module defines an abstraction for building a menu for the ProseMirror editor, along with an implementation of a menubar.
Note that this module exists mostly as an example of how you might want to approach adding a menu to ProseMirror, but is not maintained as actively as the core modules related to actual editing. If you want to extend or improve it, the recommended way is to fork it. If you are interested in maintaining a serious menu component for ProseMirror, publish your fork, and if it works for me, I'll gladly deprecate this in favor of your module.
This code is released under an MIT license. There's a forum for general discussion and support requests, and the Github bug tracker is the place to report issues.
Documentation
This module defines a number of building blocks for ProseMirror menus, along with a menu bar implementation.
When using this module, you should make sure its
style/menu.css
file is loaded into your page.
interface MenuElement
The types defined in this module aren't the only thing you can display in your menu. Anything that conforms to this interface can be put into a menu structure.
render
(pm: EditorView) → {dom: HTMLElement, update: fn(state: EditorState) → boolean}
Render the element for display in the menu. Must return a DOM element and a function that can be used to update the element to a new state. Theupdate
function must return false if the update hid the entire element.
class MenuItem
implements MenuElement
An icon or label that, when clicked, executes a command.
-
new
MenuItem
(spec:Â MenuItemSpec)
Create a menu item. -
spec
: MenuItemSpec
The spec used to create this item. -
render
(view: EditorView) → {dom: HTMLElement, update: fn(state: EditorState) → boolean}
Renders the icon according to its display spec, and adds an event handler which executes the command when the representation is clicked.
interface MenuItemSpec
The configuration object passed to the MenuItem
constructor.
-
run
(state:Â EditorState, dispatch:Â fn(tr:Â Transaction), view:Â EditorView, event:Â Event)
The function to execute when the menu item is activated. -
select
: ?fn(state: EditorState) → boolean
Optional function that is used to determine whether the item is appropriate at the moment. Deselected items will be hidden. -
enable
: ?fn(state: EditorState) → boolean
Function that is used to determine if the item is enabled. If given and returning false, the item will be given a disabled styling. -
active
: ?fn(state: EditorState) → boolean
A predicate function to determine whether the item is 'active' (for example, the item for toggling the strong mark might be active then the cursor is in strong text). -
render
: ?fn(view: EditorView) → HTMLElement
A function that renders the item. You must provide either this,icon
, orlabel
. -
icon
: ?IconSpec
Describes an icon to show for this item. -
label
: ?string
Makes the item show up as a text label. Mostly useful for items wrapped in a drop-down or similar menu. The object should have alabel
property providing the text to display. -
title
: ?string | fn(state: EditorState) → string
Defines DOM title (mouseover) text for the item. -
class
: ?string
Optionally adds a CSS class to the item's DOM representation. -
css
: ?string
Optionally adds a string of inline CSS to the item's DOM representation. -
type
IconSpec
= {path:Â string, width:Â number, height:Â number} | {text:Â string, css?:Â ?string} | {dom:Â Node}
Specifies an icon. May be either an SVG icon, in which case itspath
property should be an SVG path spec, andwidth
andheight
should provide the viewbox in which that path exists. Alternatively, it may have atext
property specifying a string of text that makes up the icon, with an optionalcss
property giving additional CSS styling for the text. Or it may containdom
property containing a DOM node.
class Dropdown
implements MenuElement
A drop-down menu, displayed as a label with a downwards-pointing
triangle to the right of it.
-
new
Dropdown
(content: readonly MenuElement[] | MenuElement, options: ?Object = {})
Create a dropdown wrapping the elements. -
render
(view: EditorView) → {dom: HTMLElement, update: fn(state: EditorState) → boolean}
Render the dropdown menu and sub-items.
class DropdownSubmenu
implements MenuElement
Represents a submenu wrapping a group of elements that start
hidden and expand to the right when hovered over or tapped.
-
new
DropdownSubmenu
(content: readonly MenuElement[] | MenuElement, options: ?Object = {})
Creates a submenu for the given group of menu elements. The following options are recognized: -
render
(view: EditorView) → {dom: HTMLElement, update: fn(state: EditorState) → boolean}
Renders the submenu. -
menuBar
(options: Object) → Plugin
A plugin that will place a menu bar above the editor. Note that this involves wrapping the editor in an additional<div>
.
This module exports the following pre-built items or item constructors:
-
joinUpItem
: MenuItem
Menu item for thejoinUp
command. -
liftItem
: MenuItem
Menu item for thelift
command. -
selectParentNodeItem
: MenuItem
Menu item for theselectParentNode
command. -
undoItem
: MenuItem
Menu item for theundo
command. -
redoItem
: MenuItem
Menu item for theredo
command. -
wrapItem
(nodeType: NodeType, options: Partial & {attrs?: ?Attrs}) → MenuItem
Build a menu item for wrapping the selection in a given node type. Addsrun
andselect
properties to the ones present inoptions
.options.attrs
may be an object that provides attributes for the wrapping node. -
blockTypeItem
(nodeType: NodeType, options: Partial & {attrs?: ?Attrs}) → MenuItem
Build a menu item for changing the type of the textblock around the selection to the given type. Providesrun
,active
, andselect
properties. Others must be given inoptions
.options.attrs
may be an object to provide the attributes for the textblock node.
To construct your own items, these icons may be useful:
-
icons
: Object
A set of basic editor-related icons. Contains the propertiesjoin
,lift
,selectParentNode
,undo
,redo
,strong
,em
,code
,link
,bulletList
,orderedList
, andblockquote
, each holding an object that can be used as theicon
option toMenuItem
. -
renderGrouped
(view: EditorView, content: readonly readonly MenuElement[][]) → {
  dom: DocumentFragment,
  update: fn(state: EditorState) → boolean
}
Render the given, possibly nested, array of menu elements into a document fragment, placing separators between them (and ensuring no superfluous separators appear when some of the groups turn out to be empty).
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
Found 5/29 approved changesets -- score normalized to 1
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 6 are checked with a SAST tool
Score
3.2
/10
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to prosemirror-menu
prosemirror-example-setup
An example for how to set up a ProseMirror editor
@tiptap/extension-floating-menu
floating-menu extension for tiptap
@tiptap/extension-bubble-menu
bubble-menu extension for tiptap
prosemirror-schema-list
List-related schema elements and commands for ProseMirror