Socket
Socket
Sign inDemoInstall

prosemirror-history

Package Overview
Dependencies
Maintainers
1
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

prosemirror-history - npm Package Compare versions

Comparing version 1.3.2 to 1.4.0

6

CHANGELOG.md

@@ -0,1 +1,7 @@

## 1.4.0 (2024-03-21)
### New features
Add `undoNoScroll`/`redoNoScroll` commands.
## 1.3.2 (2023-05-17)

@@ -2,0 +8,0 @@

12

dist/index.d.ts

@@ -41,2 +41,12 @@ import { Transaction, Plugin, Command, EditorState } from 'prosemirror-state';

/**
A command function that undoes the last change. Don't scroll the
selection into view.
*/
declare const undoNoScroll: Command;
/**
A command function that redoes the last undone change. Don't
scroll the selection into view.
*/
declare const redoNoScroll: Command;
/**
The amount of undoable events available in a given state.

@@ -50,2 +60,2 @@ */

export { closeHistory, history, redo, redoDepth, undo, undoDepth };
export { closeHistory, history, redo, redoDepth, redoNoScroll, undo, undoDepth, undoNoScroll };

49

dist/index.js

@@ -323,3 +323,3 @@ import RopeSequence from 'rope-sequence';

// onto the other branch.
function histTransaction(history, state, dispatch, redo) {
function histTransaction(history, state, redo) {
let preserveItems = mustPreserveItems(state);

@@ -329,7 +329,7 @@ let histOptions = historyKey.get(state).spec.config;

if (!pop)
return;
return null;
let selection = pop.selection.resolve(pop.transform.doc);
let added = (redo ? history.done : history.undone).addTransform(pop.transform, state.selection.getBookmark(), histOptions, preserveItems);
let newHist = new HistoryState(redo ? added : pop.remaining, redo ? pop.remaining : added, null, 0, -1);
dispatch(pop.transform.setSelection(selection).setMeta(historyKey, { redo, historyState: newHist }).scrollIntoView());
return pop.transform.setSelection(selection).setMeta(historyKey, { redo, historyState: newHist });
}

@@ -401,25 +401,34 @@ let cachedPreserveItems = false, cachedPreserveItemsPlugins = null;

}
function buildCommand(redo, scroll) {
return (state, dispatch) => {
let hist = historyKey.getState(state);
if (!hist || (redo ? hist.undone : hist.done).eventCount == 0)
return false;
if (dispatch) {
let tr = histTransaction(hist, state, redo);
if (tr)
dispatch(scroll ? tr.scrollIntoView() : tr);
}
return true;
};
}
/**
A command function that undoes the last change, if any.
*/
const undo = (state, dispatch) => {
let hist = historyKey.getState(state);
if (!hist || hist.done.eventCount == 0)
return false;
if (dispatch)
histTransaction(hist, state, dispatch, false);
return true;
};
const undo = buildCommand(false, true);
/**
A command function that redoes the last undone change, if any.
*/
const redo = (state, dispatch) => {
let hist = historyKey.getState(state);
if (!hist || hist.undone.eventCount == 0)
return false;
if (dispatch)
histTransaction(hist, state, dispatch, true);
return true;
};
const redo = buildCommand(true, true);
/**
A command function that undoes the last change. Don't scroll the
selection into view.
*/
const undoNoScroll = buildCommand(false, false);
/**
A command function that redoes the last undone change. Don't
scroll the selection into view.
*/
const redoNoScroll = buildCommand(true, false);
/**
The amount of undoable events available in a given state.

@@ -439,2 +448,2 @@ */

export { closeHistory, history, redo, redoDepth, undo, undoDepth };
export { closeHistory, history, redo, redoDepth, redoNoScroll, undo, undoDepth, undoNoScroll };
{
"name": "prosemirror-history",
"version": "1.3.2",
"version": "1.4.0",
"description": "Undo history for ProseMirror",

@@ -5,0 +5,0 @@ "type": "module",

@@ -330,7 +330,7 @@ import RopeSequence from "rope-sequence"

// onto the other branch.
function histTransaction(history: HistoryState, state: EditorState, dispatch: (tr: Transaction) => void, redo: boolean) {
function histTransaction(history: HistoryState, state: EditorState, redo: boolean): Transaction | null {
let preserveItems = mustPreserveItems(state)
let histOptions = (historyKey.get(state)!.spec as any).config as Required<HistoryOptions>
let pop = (redo ? history.undone : history.done).popEvent(state, preserveItems)
if (!pop) return
if (!pop) return null

@@ -342,3 +342,3 @@ let selection = pop.selection!.resolve(pop.transform.doc)

let newHist = new HistoryState(redo ? added : pop.remaining, redo ? pop.remaining : added, null, 0, -1)
dispatch(pop.transform.setSelection(selection).setMeta(historyKey, {redo, historyState: newHist}).scrollIntoView())
return pop.transform.setSelection(selection).setMeta(historyKey, {redo, historyState: newHist})
}

@@ -424,18 +424,28 @@

/// A command function that undoes the last change, if any.
export const undo: Command = (state, dispatch) => {
let hist = historyKey.getState(state)
if (!hist || hist.done.eventCount == 0) return false
if (dispatch) histTransaction(hist, state, dispatch, false)
return true
function buildCommand(redo: boolean, scroll: boolean): Command {
return (state, dispatch) => {
let hist = historyKey.getState(state)
if (!hist || (redo ? hist.undone : hist.done).eventCount == 0) return false
if (dispatch) {
let tr = histTransaction(hist, state, redo)
if (tr) dispatch(scroll ? tr.scrollIntoView() : tr)
}
return true
}
}
/// A command function that undoes the last change, if any.
export const undo = buildCommand(false, true)
/// A command function that redoes the last undone change, if any.
export const redo: Command = (state, dispatch) => {
let hist = historyKey.getState(state)
if (!hist || hist.undone.eventCount == 0) return false
if (dispatch) histTransaction(hist, state, dispatch, true)
return true
}
export const redo = buildCommand(true, true)
/// A command function that undoes the last change. Don't scroll the
/// selection into view.
export const undoNoScroll = buildCommand(false, false)
/// A command function that redoes the last undone change. Don't
/// scroll the selection into view.
export const redoNoScroll = buildCommand(true, false)
/// The amount of undoable events available in a given state.

@@ -442,0 +452,0 @@ export function undoDepth(state: EditorState) {

@@ -13,2 +13,6 @@ An implementation of an undo/redo history for ProseMirror. This

@undoNoScroll
@redoNoScroll
@undoDepth

@@ -15,0 +19,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc