slate-history
Advanced tools
Comparing version 0.58.0 to 0.58.1
@@ -14,6 +14,5 @@ 'use strict'; | ||
*/ | ||
isHistory(value) { | ||
isHistory: function isHistory(value) { | ||
return isPlainObject(value) && Array.isArray(value.redos) && Array.isArray(value.undos) && (value.redos.length === 0 || slate.Operation.isOperationList(value.redos[0])) && (value.undos.length === 0 || slate.Operation.isOperationList(value.undos[0])); | ||
} | ||
}; | ||
@@ -32,3 +31,3 @@ | ||
*/ | ||
isHistoryEditor(value) { | ||
isHistoryEditor: function isHistoryEditor(value) { | ||
return slate.Editor.isEditor(value) && History.isHistory(value.history); | ||
@@ -40,3 +39,3 @@ }, | ||
*/ | ||
isMerging(editor) { | ||
isMerging: function isMerging(editor) { | ||
return MERGING.get(editor); | ||
@@ -48,3 +47,3 @@ }, | ||
*/ | ||
isSaving(editor) { | ||
isSaving: function isSaving(editor) { | ||
return SAVING.get(editor); | ||
@@ -56,3 +55,3 @@ }, | ||
*/ | ||
redo(editor) { | ||
redo: function redo(editor) { | ||
editor.redo(); | ||
@@ -64,3 +63,3 @@ }, | ||
*/ | ||
undo(editor) { | ||
undo: function undo(editor) { | ||
editor.undo(); | ||
@@ -73,3 +72,3 @@ }, | ||
*/ | ||
withoutMerging(editor, fn) { | ||
withoutMerging: function withoutMerging(editor, fn) { | ||
var prev = HistoryEditor.isMerging(editor); | ||
@@ -85,3 +84,3 @@ MERGING.set(editor, false); | ||
*/ | ||
withoutSaving(editor, fn) { | ||
withoutSaving: function withoutSaving(editor, fn) { | ||
var prev = HistoryEditor.isSaving(editor); | ||
@@ -92,3 +91,2 @@ SAVING.set(editor, false); | ||
} | ||
}; | ||
@@ -101,7 +99,5 @@ | ||
var withHistory = editor => { | ||
var withHistory = function withHistory(editor) { | ||
var e = editor; | ||
var { | ||
apply | ||
} = e; | ||
var apply = e.apply; | ||
e.history = { | ||
@@ -112,16 +108,32 @@ undos: [], | ||
e.redo = () => { | ||
var { | ||
history | ||
} = e; | ||
var { | ||
redos | ||
} = history; | ||
e.redo = function () { | ||
var history = e.history; | ||
var redos = history.redos; | ||
if (redos.length > 0) { | ||
var batch = redos[redos.length - 1]; | ||
HistoryEditor.withoutSaving(e, () => { | ||
slate.Editor.withoutNormalizing(e, () => { | ||
for (var op of batch) { | ||
e.apply(op); | ||
HistoryEditor.withoutSaving(e, function () { | ||
slate.Editor.withoutNormalizing(e, function () { | ||
var _iteratorNormalCompletion = true; | ||
var _didIteratorError = false; | ||
var _iteratorError = undefined; | ||
try { | ||
for (var _iterator = batch[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
var op = _step.value; | ||
e.apply(op); | ||
} | ||
} catch (err) { | ||
_didIteratorError = true; | ||
_iteratorError = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion && _iterator["return"] != null) { | ||
_iterator["return"](); | ||
} | ||
} finally { | ||
if (_didIteratorError) { | ||
throw _iteratorError; | ||
} | ||
} | ||
} | ||
@@ -135,23 +147,39 @@ }); | ||
e.undo = () => { | ||
var { | ||
history | ||
} = e; | ||
var { | ||
undos | ||
} = history; | ||
e.undo = function () { | ||
var history = e.history; | ||
var undos = history.undos; | ||
if (undos.length > 0) { | ||
var batch = undos[undos.length - 1]; | ||
HistoryEditor.withoutSaving(e, () => { | ||
slate.Editor.withoutNormalizing(e, () => { | ||
HistoryEditor.withoutSaving(e, function () { | ||
slate.Editor.withoutNormalizing(e, function () { | ||
var inverseOps = batch.map(slate.Operation.inverse).reverse(); | ||
var _iteratorNormalCompletion2 = true; | ||
var _didIteratorError2 = false; | ||
var _iteratorError2 = undefined; | ||
for (var op of inverseOps) { | ||
// If the final operation is deselecting the editor, skip it. This is | ||
if (op === inverseOps[inverseOps.length - 1] && op.type === 'set_selection' && op.newProperties == null) { | ||
continue; | ||
} else { | ||
e.apply(op); | ||
try { | ||
for (var _iterator2 = inverseOps[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { | ||
var op = _step2.value; | ||
// If the final operation is deselecting the editor, skip it. This is | ||
if (op === inverseOps[inverseOps.length - 1] && op.type === 'set_selection' && op.newProperties == null) { | ||
continue; | ||
} else { | ||
e.apply(op); | ||
} | ||
} | ||
} catch (err) { | ||
_didIteratorError2 = true; | ||
_iteratorError2 = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion2 && _iterator2["return"] != null) { | ||
_iterator2["return"](); | ||
} | ||
} finally { | ||
if (_didIteratorError2) { | ||
throw _iteratorError2; | ||
} | ||
} | ||
} | ||
@@ -165,10 +193,6 @@ }); | ||
e.apply = op => { | ||
var { | ||
operations, | ||
history | ||
} = e; | ||
var { | ||
undos | ||
} = history; | ||
e.apply = function (op) { | ||
var operations = e.operations, | ||
history = e.history; | ||
var undos = history.undos; | ||
var lastBatch = undos[undos.length - 1]; | ||
@@ -224,3 +248,3 @@ var lastOp = lastBatch && lastBatch[lastBatch.length - 1]; | ||
var shouldMerge = (op, prev) => { | ||
var shouldMerge = function shouldMerge(op, prev) { | ||
if (op.type === 'set_selection') { | ||
@@ -245,3 +269,3 @@ return true; | ||
var shouldSave = (op, prev) => { | ||
var shouldSave = function shouldSave(op, prev) { | ||
if (op.type === 'set_selection' && op.newProperties == null) { | ||
@@ -258,3 +282,3 @@ return false; | ||
var shouldOverwrite = (op, prev) => { | ||
var shouldOverwrite = function shouldOverwrite(op, prev) { | ||
if (prev && op.type === 'set_selection' && prev.type === 'set_selection') { | ||
@@ -271,3 +295,3 @@ return true; | ||
var shouldClear = op => { | ||
var shouldClear = function shouldClear(op) { | ||
if (op.type === 'set_selection') { | ||
@@ -274,0 +298,0 @@ return false; |
{ | ||
"name": "slate-history", | ||
"description": "An operation-based history implementation for Slate editors.", | ||
"version": "0.58.0", | ||
"version": "0.58.1", | ||
"license": "MIT", | ||
@@ -21,4 +21,4 @@ "repository": "git://github.com/ianstormtaylor/slate.git", | ||
"devDependencies": { | ||
"slate": "^0.58.0", | ||
"slate-hyperscript": "^0.58.0" | ||
"slate": "^0.58.1", | ||
"slate-hyperscript": "^0.58.1" | ||
}, | ||
@@ -41,3 +41,3 @@ "peerDependencies": { | ||
], | ||
"gitHead": "8737f0411a0a151859044e3f858cdbfe9e3f8cff" | ||
"gitHead": "aabb9b50bd390e3afb638ee2170c3c15d583960c" | ||
} |
Sorry, the diff of this file is not supported yet
57149
848