API reference
prosemirror-flat-list
Section titled “prosemirror-flat-list”Functions
Section titled “Functions”findListsRange()
Section titled “findListsRange()”-
function findListsRange($from:ResolvedPos,$to:ResolvedPos):NodeRange|null -
Returns a minimal block range that includes the given two positions and represents one or multiple sibling list nodes.
isListNode()
Section titled “isListNode()”-
function isListNode(node: |Node|null|undefined):boolean
isListType()
Section titled “isListType()”-
function isListType(type:NodeType):boolean
joinListElements()
Section titled “joinListElements()”-
function joinListElements<T>(parent:T):T -
Merge adjacent
- elements or adjacent
- elements into a single list element.
migrateDocJSON()
Section titled “migrateDocJSON()”-
function migrateDocJSON(docJSON:ProsemirrorNodeJSON):ProsemirrorNodeJSON|null -
Migrate a ProseMirror document JSON object from the old list structure to the new. A new document JSON object is returned if the document is updated, otherwise
nullis returned.
Commands
Section titled “Commands”DedentListOptions
Section titled “DedentListOptions”Properties
Section titled “Properties”| Property | Type | Default value | Description |
|---|---|---|---|
from? | number | state.selection.from | A optional from position to indent. |
to? | number | state.selection.to | A optional to position to indent. |
IndentListOptions
Section titled “IndentListOptions”Properties
Section titled “Properties”| Property | Type | Default value | Description |
|---|---|---|---|
from? | number | state.selection.from | A optional from position to indent. |
to? | number | state.selection.to | A optional to position to indent. |
ToggleCollapsedOptions
Section titled “ToggleCollapsedOptions”Properties
Section titled “Properties”| Property | Type | Description |
|---|---|---|
collapsed? | boolean | If this value exists, the command will set the collapsed attribute to this value instead of toggle it. |
isToggleable? | (node: Node) => boolean | An optional function to accept a list node and return whether or not this node can toggle its collapsed attribute. |
UnwrapListOptions
Section titled “UnwrapListOptions”Properties
Section titled “Properties”| Property | Type | Description |
|---|---|---|
kind? | string | If given, only this kind of list will be unwrap. |
WrapInListGetAttrs
Section titled “WrapInListGetAttrs”-
type WrapInListGetAttrs<T> = |T| (range:NodeRange) =>T|null -
The list node attributes or a callback function to take the current selection block range and return list node attributes. If this callback function returns null, the command won’t do anything.
backspaceCommand
Section titled “backspaceCommand”-
const backspaceCommand:Command -
Keybinding for
Backspace. It’s chained with following commands:
deleteCommand
Section titled “deleteCommand”-
const deleteCommand:Command -
Keybinding for
Delete. It’s chained with following commands:
enterCommand
Section titled “enterCommand”-
const enterCommand:Command -
Keybinding for
Enter. It’s chained with following commands:
joinCollapsedListBackward
Section titled “joinCollapsedListBackward”-
const joinCollapsedListBackward:Command -
If the selection is empty and at the start of a block, and there is a collapsed list node right before the cursor, move current block and append it to the first child of the collapsed list node (i.e. skip the hidden content).
joinListUp
Section titled “joinListUp”-
const joinListUp:Command -
If the text cursor is at the start of the first child of a list node, lift all content inside the list. If the text cursor is at the start of the last child of a list node, lift this child.
listKeymap
Section titled “listKeymap”-
const listKeymap: {Backspace:Command;Delete:Command;Enter:Command;Mod-[:Command;Mod-]:Command; } -
Returns an object containing the keymap for the list commands.
Enter: See enterCommand.Backspace: See backspaceCommand.Delete: See deleteCommand.Mod-[: Decrease indentation. See createDedentListCommand.Mod-]: Increase indentation. See createIndentListCommand.
protectCollapsed
Section titled “protectCollapsed”-
const protectCollapsed:Command -
This command will protect the collapsed items from being deleted.
If current selection contains a collapsed item, we don’t want the user to delete this selection by pressing Backspace or Delete, because this could be unintentional.
In such case, we will stop the delete action and expand the collapsed items instead. Therefore the user can clearly know what content he is trying to delete.
createDedentListCommand()
Section titled “createDedentListCommand()”-
function createDedentListCommand(options?:DedentListOptions):Command -
Returns a command function that decreases the indentation of selected list nodes.
createIndentListCommand()
Section titled “createIndentListCommand()”-
function createIndentListCommand(options?:IndentListOptions):Command -
Returns a command function that increases the indentation of selected list nodes.
createMoveListCommand()
Section titled “createMoveListCommand()”-
function createMoveListCommand(direction:"up"|"down"):Command -
Returns a command function that moves up or down selected list nodes.
createSplitListCommand()
Section titled “createSplitListCommand()”-
function createSplitListCommand():Command -
Returns a command that split the current list node.
createToggleCollapsedCommand()
Section titled “createToggleCollapsedCommand()”-
function createToggleCollapsedCommand(options:ToggleCollapsedOptions):Command -
Return a command function that toggle the
collapsedattribute of the list node.
createToggleListCommand()
Section titled “createToggleListCommand()”-
function createToggleListCommand<T>(attrs:T):Command -
Returns a command function that wraps the selection in a list with the given type and attributes, or change the list kind if the selection is already in another kind of list, or unwrap the selected list if otherwise.
createUnwrapListCommand()
Section titled “createUnwrapListCommand()”-
function createUnwrapListCommand(options?:UnwrapListOptions):Command -
Returns a command function that unwraps the list around the selection.
createWrapInListCommand()
Section titled “createWrapInListCommand()”-
function createWrapInListCommand<T>(getAttrs:WrapInListGetAttrs<T>):Command -
Returns a command function that wraps the selection in a list with the given type and attributes.
Input Rules
Section titled “Input Rules”ListInputRuleAttributesGetter()
Section titled “ListInputRuleAttributesGetter()”-
type ListInputRuleAttributesGetter<T> = (options: {attributes?:T;match:RegExpMatchArray; }) =>T -
A callback function to get the attributes for a list input rule.
listInputRules
Section titled “listInputRules”-
const listInputRules:InputRule[] -
All input rules for lists.
wrappingListInputRule()
Section titled “wrappingListInputRule()”-
function wrappingListInputRule<T>(regexp:RegExp,getAttrs: |T|ListInputRuleAttributesGetter<T>):InputRule -
Build an input rule for automatically wrapping a textblock into a list node when a given string is typed.
Plugins
Section titled “Plugins”ListDOMSerializer
Section titled “ListDOMSerializer”A custom DOM serializer class that can serialize flat list nodes into native
HTML list elements (i.e. <ul> and <ol>).
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”-
new ListDOMSerializer(nodes: { [node:string]: (node:Node) =>DOMOutputSpec; },marks: { [mark:string]: (mark:Mark,inline:boolean) =>DOMOutputSpec; }):ListDOMSerializer -
Create a serializer.
nodesshould map node names to functions that take a node and return a description of the corresponding DOM.marksdoes the same for mark names, but also gets an argument that tells it whether the mark’s content is block or inline content (for typical use, it’ll always be inline). A mark serializer may benullto indicate that marks of that type should not be serialized.
Methods
Section titled “Methods”-
serializeFragment(fragment:Fragment,options?: {document?:Document; },target?: |HTMLElement|DocumentFragment): |HTMLElement|DocumentFragment -
Serialize the content of this fragment to a DOM fragment. When not in the browser, the
documentoption, containing a DOM document, should be passed so that the serializer can create nodes.
-
static fromSchema(schema:Schema):ListDOMSerializer -
Build a serializer using the
toDOMproperties in a schema’s node and mark specs.
-
static nodesFromSchema(schema:Schema): { [node:string]: (node:Node) =>DOMOutputSpec; } -
Gather the serializers in a schema’s node specs into an object. This can be useful as a base to build a custom serializer from.
createListNodeView
Section titled “createListNodeView”-
A simple node view that is used to render the list node. It ensures that the list node get updated when its marker styling should changes.
createListClipboardPlugin()
Section titled “createListClipboardPlugin()”-
function createListClipboardPlugin(schema:Schema):Plugin -
Serialize list nodes into native HTML list elements (i.e.
<ul>,<ol>) to clipboard. See ListDOMSerializer.
createListEventPlugin()
Section titled “createListEventPlugin()”-
function createListEventPlugin():Plugin -
Handle DOM events for list.
createListPlugins()
Section titled “createListPlugins()”-
function createListPlugins(options: {schema:Schema; }):Plugin<any>[] -
This function returns an array of plugins that are required for list to work.
The plugins are shown below. You can pick and choose which plugins you want to use if you want to customize some behavior.
createListRenderingPlugin()
Section titled “createListRenderingPlugin()”-
function createListRenderingPlugin():Plugin -
Handle the list node rendering.
createSafariInputMethodWorkaroundPlugin()
Section titled “createSafariInputMethodWorkaroundPlugin()”-
function createSafariInputMethodWorkaroundPlugin():Plugin -
Return a plugin as a workaround for a bug in Safari that causes the composition based IME to remove the empty HTML element with CSS
position: relative.See also https://github.com/ProseMirror/prosemirror/issues/934
Schema
Section titled “Schema”ListAttributes
Section titled “ListAttributes”Properties
Section titled “Properties”| Property | Type |
|---|---|
checked? | boolean |
collapsed? | boolean |
kind? | string |
order? | number | null |
ListToDOMOptions
Section titled “ListToDOMOptions”Properties
Section titled “Properties”| Property | Type | Default value | Description |
|---|---|---|---|
getAttributes? | (node: Node) => Record<string, string | undefined> | undefined | An optional function to get the attributes added to HTML element. |
getMarkers? | (node: Node) => | DOMOutputSpec[] | null | undefined | An optional function to get elements inside <div class="list-marker">. Return null to hide the marker. |
nativeList? | boolean | false | If true, the list will be rendered as a native <ul> or <ol> element. You might want to use joinListElements to join the list elements afterward. |
node | Node | undefined | The list node to be rendered. |
ProsemirrorNodeJSON
Section titled “ProsemirrorNodeJSON”Properties
Section titled “Properties”| Property | Type |
|---|---|
attrs? | Attrs |
content? | ProsemirrorNodeJSON[] |
marks? | ( | string | { attrs?: Attrs; type: string; })[] |
text? | string |
type | string |
ListKind
Section titled “ListKind”-
type ListKind ="bullet"|"ordered"|"task"|"toggle" -
All default list node kinds.
createListSpec()
Section titled “createListSpec()”-
function createListSpec():NodeSpec -
Return the spec for list node.
createParseDomRules()
Section titled “createParseDomRules()”-
function createParseDomRules(): readonlyTagParseRule[] -
Returns a set of rules for parsing HTML into ProseMirror list nodes.
listToDOM()
Section titled “listToDOM()”-
function listToDOM(options:ListToDOMOptions):DOMOutputSpec -
Renders a list node to DOM output spec.