@remirror/pm
- Version 3.0.1
- Published
- 1.2 MB
- 19 dependencies
- MIT license
Install
npm i @remirror/pmyarn add @remirror/pmpnpm add @remirror/pmOverview
A bundled library containing all the core prosemirror libraries required for using remirror
Index
Functions
function chainableEditorState
chainableEditorState: (tr: Transaction, state: EditorState) => EditorState;Creates a fake state that can be used on ProseMirror library commands to make them chainable. The provided Transaction
trcan be a shared one.Parameter tr
the chainable transaction that should be amended.
Parameter state
the state of the editor (available via
view.state).This should not be used other than for passing to
prosemirror-*library commands.
function chainCommands
chainCommands: <Extra extends object = object>( ...commands: Array<CommandFunction<Extra>>) => CommandFunction<Extra>;Similar to the chainCommands from the
prosemirror-commandslibrary. Allows multiple commands to be chained together and runs until one of them returns true.
function convertCommand
convertCommand: <Extra extends object = object>( commandFunction: ProsemirrorCommandFunction) => CommandFunction<Extra>;Wraps the default [[ProsemirrorCommandFunction]] and makes it compatible with the default **remirror** [[CommandFunction]] call signature.
It extracts all the public APIs of the state object and assigns the chainable transaction to the
state.trproperty to support chaining.
function nonChainable
nonChainable: <Extra extends object = object>( commandFunction: CommandFunction<Extra>) => NonChainableCommandFunction<Extra>;Marks a command function as non chainable. It will throw an error when chaining is attempted.
Remarks
const command = nonChainable(({ state, dispatch }) => {...});
Interfaces
interface CommandFunctionProps
interface CommandFunctionProps {}A parameter builder interface for the remirror
CommandFunction.
property dispatch
dispatch?: DispatchFunction;The dispatch function which causes the command to be performed.
Remarks
dispatchcan beundefined. When nodispatchcallback is provided the command should perform a 'dry run', determining whether the command is applicable (return true), but not actually performing the action.
property state
state: EditorState;A snapshot of the ProseMirror editor state.
property tr
tr: Transaction;The shared ProseMirror Transaction.
property view
view?: EditorView;An instance of the ProseMirror editor
view.
Type Aliases
type CommandFunction
type CommandFunction<ExtraProps extends object = object> = ( params: CommandFunctionProps & ExtraProps) => boolean;A command method for running commands in your editor.
Remarks
This groups all the prosemirror command arguments into a single parameter.
tldr; When
dispatch=undefinedmake sure the command function is **idempotent**.One thing to be aware of is that when creating a command function the
trshould only be updated when thedispatchmethod is available. This is because by convention calling the command function withdispatch=undefinedis used to check if the function returnstrue, an indicator that it is enabled, or returnsfalseto indicate it is not enabled.If the transaction has been updated outside of the
dispatch=truecondition then running the command again will result in multiple transaction updates and unpredictable behavior.See Also
type DispatchFunction
type DispatchFunction = (tr: Transaction) => void;Used to apply the Prosemirror transaction to the current EditorState.
type NonChainableCommandFunction
type NonChainableCommandFunction<Extra extends object = object> = Brand< CommandFunction<Extra>, 'non-chainable'>;Brands a command as non chainable so that it can be excluded from the inferred chainable commands.
type ProsemirrorCommandFunction
type ProsemirrorCommandFunction = ( state: EditorState, dispatch: DispatchFunction | undefined, view: EditorView | undefined) => boolean;This is the type signature for commands within the prosemirror editor.
Remarks
A command function takes an editor state and optionally a dispatch function that it can use to dispatch a transaction. It should return a boolean that indicates whether it could perform any action.
When no dispatch callback is passed, the command should do a 'dry run', determining whether it is applicable, but not actually performing any action.
Package Files (2)
Dependencies (19)
- @babel/runtime
- @remirror/core-constants
- @remirror/core-helpers
- prosemirror-collab
- prosemirror-commands
- prosemirror-dropcursor
- prosemirror-gapcursor
- prosemirror-history
- prosemirror-inputrules
- prosemirror-keymap
- prosemirror-model
- prosemirror-paste-rules
- prosemirror-schema-list
- prosemirror-state
- prosemirror-suggest
- prosemirror-tables
- prosemirror-trailing-node
- prosemirror-transform
- prosemirror-view
Dev Dependencies (1)
Peer Dependencies (0)
No peer dependencies.
Badge
To add a badge like this oneto your package's README, use the codes available below.
You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@remirror/pm.
- Markdown[](https://www.jsdocs.io/package/@remirror/pm)
- HTML<a href="https://www.jsdocs.io/package/@remirror/pm"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
Package analyzed in 3980 ms. - Missing or incorrect documentation? Open an issue for this package.
