Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

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 0.23.0 to 0.24.0

49

dist/history.js

@@ -95,5 +95,5 @@ 'use strict';

// Create a new branch with the given transform added.
Branch.prototype.addTransform = function addTransform (transform, selection, histOptions) {
Branch.prototype.addTransform = function addTransform (transform, selection, histOptions, preserveItems) {
var newItems = [], eventCount = this.eventCount + (selection ? 1 : 0);
var oldItems = this.items, lastItem = !histOptions.preserveItems && oldItems.length ? oldItems.get(oldItems.length - 1) : null;
var oldItems = this.items, lastItem = !preserveItems && oldItems.length ? oldItems.get(oldItems.length - 1) : null;

@@ -110,3 +110,3 @@ for (var i = 0; i < transform.steps.length; i++) {

selection = null;
if (!histOptions.preserveItems) { lastItem = item; }
if (!preserveItems) { lastItem = item; }
}

@@ -258,5 +258,5 @@ var overflow = eventCount - histOptions.depth;

// : (EditorState, Transform, Selection, Object)
// : (EditorState, EditorState, Selection, Object)
// Record a transformation in undo history.
function applyTransaction(history, selection, tr, options) {
function applyTransaction(history, state, tr, options) {
var newState = tr.getMeta(historyKey), rebased;

@@ -274,3 +274,4 @@ if (newState) { return newState }

!appended && !isAdjacentToLastStep(tr, history.prevMap, history.done);
return new HistoryState(history.done.addTransform(tr, newGroup ? selection.getBookmark() : null, options),
return new HistoryState(history.done.addTransform(tr, newGroup ? state.selection.getBookmark() : null,
options, mustPreserveItems(state)),
Branch.empty, tr.mapping.maps[tr.steps.length - 1], tr.time)

@@ -315,9 +316,9 @@ } else if (rebased = tr.getMeta("rebased")) {

function histTransaction(history, state, dispatch, redo) {
var histOptions = historyKey.get(state).spec.config;
var pop = (redo ? history.undone : history.done).popEvent(state, histOptions.preserveItems);
var preserveItems = mustPreserveItems(state), histOptions = historyKey.get(state).spec.config;
var pop = (redo ? history.undone : history.done).popEvent(state, preserveItems);
if (!pop) { return }
var selectionBefore = state.selection;
var selection = pop.selection.resolve(pop.transform.doc);
var added = (redo ? history.done : history.undone).addTransform(pop.transform, selectionBefore.getBookmark(), histOptions);
var added = (redo ? history.done : history.undone).addTransform(pop.transform, state.selection.getBookmark(),
histOptions, preserveItems);

@@ -328,2 +329,21 @@ var newHist = new HistoryState(redo ? added : pop.remaining, redo ? pop.remaining : added, null, 0);

var cachedPreserveItems = false;
var cachedPreserveItemsPlugins = null;
// Check whether any plugin in the given state has a
// `historyPreserveItems` property in its spec, in which case we must
// preserve steps exactly as they came in, so that they can be
// rebased.
function mustPreserveItems(state) {
var plugins = state.plugins;
if (cachedPreserveItemsPlugins != plugins) {
cachedPreserveItems = false;
cachedPreserveItemsPlugins = plugins;
for (var i = 0; i < plugins.length; i++) { if (plugins[i].spec.historyPreserveItems) {
cachedPreserveItems = true;
break
} }
}
return cachedPreserveItems
}
// :: (Transaction) → Transaction

@@ -360,11 +380,4 @@ // Set a flag on the given transaction that will prevent further steps

// aren't adjacent, a new group is always started.
//
// preserveItems:: ?bool
// Whether to preserve the steps exactly as they came in. **Must**
// be true when using the history together with the collaborative
// editing plugin, to allow syncing the history when concurrent
// changes come in. Defaults to false.
function history(config) {
config = {depth: config && config.depth || 100,
preserveItems: !!(config && config.preserveItems),
newGroupDelay: config && config.newGroupDelay || 500};

@@ -379,3 +392,3 @@ return new prosemirrorState.Plugin({

apply: function apply(tr, hist, state) {
return applyTransaction(hist, state.selection, tr, config)
return applyTransaction(hist, state, tr, config)
}

@@ -382,0 +395,0 @@ },

{
"name": "prosemirror-history",
"version": "0.23.0",
"version": "0.24.0",
"description": "Undo history for ProseMirror",

@@ -19,4 +19,4 @@ "main": "dist/history.js",

"dependencies": {
"prosemirror-state": "^0.23.0",
"prosemirror-transform": "^0.23.0",
"prosemirror-state": "^0.24.0",
"prosemirror-transform": "^0.24.0",
"rope-sequence": "^1.2.0"

@@ -27,4 +27,4 @@ },

"mocha": "^3.0.2",
"prosemirror-model": "^0.23.0",
"prosemirror-test-builder": "^0.23.0",
"prosemirror-model": "^0.24.0",
"prosemirror-test-builder": "^0.24.0",
"rollup": "^0.49.0",

@@ -31,0 +31,0 @@ "rollup-plugin-buble": "^0.15.0"

@@ -88,5 +88,5 @@ import RopeSequence from "rope-sequence"

// Create a new branch with the given transform added.
addTransform(transform, selection, histOptions) {
addTransform(transform, selection, histOptions, preserveItems) {
let newItems = [], eventCount = this.eventCount + (selection ? 1 : 0)
let oldItems = this.items, lastItem = !histOptions.preserveItems && oldItems.length ? oldItems.get(oldItems.length - 1) : null
let oldItems = this.items, lastItem = !preserveItems && oldItems.length ? oldItems.get(oldItems.length - 1) : null

@@ -103,3 +103,3 @@ for (let i = 0; i < transform.steps.length; i++) {

selection = null
if (!histOptions.preserveItems) lastItem = item
if (!preserveItems) lastItem = item
}

@@ -254,5 +254,5 @@ let overflow = eventCount - histOptions.depth

// : (EditorState, Transform, Selection, Object)
// : (EditorState, EditorState, Selection, Object)
// Record a transformation in undo history.
function applyTransaction(history, selection, tr, options) {
function applyTransaction(history, state, tr, options) {
let newState = tr.getMeta(historyKey), rebased

@@ -270,3 +270,4 @@ if (newState) return newState

!appended && !isAdjacentToLastStep(tr, history.prevMap, history.done)
return new HistoryState(history.done.addTransform(tr, newGroup ? selection.getBookmark() : null, options),
return new HistoryState(history.done.addTransform(tr, newGroup ? state.selection.getBookmark() : null,
options, mustPreserveItems(state)),
Branch.empty, tr.mapping.maps[tr.steps.length - 1], tr.time)

@@ -311,9 +312,9 @@ } else if (rebased = tr.getMeta("rebased")) {

function histTransaction(history, state, dispatch, redo) {
let histOptions = historyKey.get(state).spec.config
let pop = (redo ? history.undone : history.done).popEvent(state, histOptions.preserveItems)
let preserveItems = mustPreserveItems(state), histOptions = historyKey.get(state).spec.config
let pop = (redo ? history.undone : history.done).popEvent(state, preserveItems)
if (!pop) return
let selectionBefore = state.selection
let selection = pop.selection.resolve(pop.transform.doc)
let added = (redo ? history.done : history.undone).addTransform(pop.transform, selectionBefore.getBookmark(), histOptions)
let added = (redo ? history.done : history.undone).addTransform(pop.transform, state.selection.getBookmark(),
histOptions, preserveItems)

@@ -324,2 +325,20 @@ let newHist = new HistoryState(redo ? added : pop.remaining, redo ? pop.remaining : added, null, 0)

let cachedPreserveItems = false, cachedPreserveItemsPlugins = null
// Check whether any plugin in the given state has a
// `historyPreserveItems` property in its spec, in which case we must
// preserve steps exactly as they came in, so that they can be
// rebased.
function mustPreserveItems(state) {
let plugins = state.plugins
if (cachedPreserveItemsPlugins != plugins) {
cachedPreserveItems = false
cachedPreserveItemsPlugins = plugins
for (let i = 0; i < plugins.length; i++) if (plugins[i].spec.historyPreserveItems) {
cachedPreserveItems = true
break
}
}
return cachedPreserveItems
}
// :: (Transaction) → Transaction

@@ -356,11 +375,4 @@ // Set a flag on the given transaction that will prevent further steps

// aren't adjacent, a new group is always started.
//
// preserveItems:: ?bool
// Whether to preserve the steps exactly as they came in. **Must**
// be true when using the history together with the collaborative
// editing plugin, to allow syncing the history when concurrent
// changes come in. Defaults to false.
export function history(config) {
config = {depth: config && config.depth || 100,
preserveItems: !!(config && config.preserveItems),
newGroupDelay: config && config.newGroupDelay || 500}

@@ -375,3 +387,3 @@ return new Plugin({

apply(tr, hist, state) {
return applyTransaction(hist, state.selection, tr, config)
return applyTransaction(hist, state, tr, config)
}

@@ -378,0 +390,0 @@ },

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