This commit is contained in:
50
node_modules/slate-history/dist/history-editor.d.ts
generated
vendored
Normal file
50
node_modules/slate-history/dist/history-editor.d.ts
generated
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
import { BaseEditor } from 'slate';
|
||||
import { History } from './history';
|
||||
/**
|
||||
* Weakmaps for attaching state to the editor.
|
||||
*/
|
||||
export declare const HISTORY: WeakMap<BaseEditor, History>;
|
||||
export declare const SAVING: WeakMap<BaseEditor, boolean | undefined>;
|
||||
export declare const MERGING: WeakMap<BaseEditor, boolean | undefined>;
|
||||
/**
|
||||
* `HistoryEditor` contains helpers for history-enabled editors.
|
||||
*/
|
||||
export interface HistoryEditor extends BaseEditor {
|
||||
history: History;
|
||||
undo: () => void;
|
||||
redo: () => void;
|
||||
writeHistory: (stack: 'undos' | 'redos', batch: any) => void;
|
||||
}
|
||||
export declare const HistoryEditor: {
|
||||
/**
|
||||
* Check if a value is a `HistoryEditor` object.
|
||||
*/
|
||||
isHistoryEditor(value: any): value is HistoryEditor;
|
||||
/**
|
||||
* Get the merge flag's current value.
|
||||
*/
|
||||
isMerging(editor: HistoryEditor): boolean | undefined;
|
||||
/**
|
||||
* Get the saving flag's current value.
|
||||
*/
|
||||
isSaving(editor: HistoryEditor): boolean | undefined;
|
||||
/**
|
||||
* Redo to the previous saved state.
|
||||
*/
|
||||
redo(editor: HistoryEditor): void;
|
||||
/**
|
||||
* Undo to the previous saved state.
|
||||
*/
|
||||
undo(editor: HistoryEditor): void;
|
||||
/**
|
||||
* Apply a series of changes inside a synchronous `fn`, without merging any of
|
||||
* the new operations into previous save point in the history.
|
||||
*/
|
||||
withoutMerging(editor: HistoryEditor, fn: () => void): void;
|
||||
/**
|
||||
* Apply a series of changes inside a synchronous `fn`, without saving any of
|
||||
* their operations into the history.
|
||||
*/
|
||||
withoutSaving(editor: HistoryEditor, fn: () => void): void;
|
||||
};
|
||||
//# sourceMappingURL=history-editor.d.ts.map
|
||||
1
node_modules/slate-history/dist/history-editor.d.ts.map
generated
vendored
Normal file
1
node_modules/slate-history/dist/history-editor.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"history-editor.d.ts","sourceRoot":"","sources":["packages/slate-history/src/history-editor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAU,MAAM,OAAO,CAAA;AAC1C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAEnC;;GAEG;AAEH,eAAO,MAAM,OAAO,8BAAiC,CAAA;AACrD,eAAO,MAAM,MAAM,0CAA6C,CAAA;AAChE,eAAO,MAAM,OAAO,0CAA6C,CAAA;AAEjE;;GAEG;AAEH,MAAM,WAAW,aAAc,SAAQ,UAAU;IAC/C,OAAO,EAAE,OAAO,CAAA;IAChB,IAAI,EAAE,MAAM,IAAI,CAAA;IAChB,IAAI,EAAE,MAAM,IAAI,CAAA;IAChB,YAAY,EAAE,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,EAAE,KAAK,EAAE,GAAG,KAAK,IAAI,CAAA;CAC7D;AAGD,eAAO,MAAM,aAAa;IACxB;;OAEG;2BAEoB,GAAG;IAI1B;;OAEG;sBAEe,aAAa,GAAG,OAAO,GAAG,SAAS;IAIrD;;OAEG;qBAEc,aAAa,GAAG,OAAO,GAAG,SAAS;IAIpD;;OAEG;iBAEU,aAAa,GAAG,IAAI;IAIjC;;OAEG;iBAEU,aAAa,GAAG,IAAI;IAIjC;;;OAGG;2BAEoB,aAAa,MAAM,MAAM,IAAI,GAAG,IAAI;IAO3D;;;OAGG;0BAEmB,aAAa,MAAM,MAAM,IAAI,GAAG,IAAI;CAM3D,CAAA"}
|
||||
21
node_modules/slate-history/dist/history.d.ts
generated
vendored
Normal file
21
node_modules/slate-history/dist/history.d.ts
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
import { Operation, Range } from 'slate';
|
||||
interface Batch {
|
||||
operations: Operation[];
|
||||
selectionBefore: Range | null;
|
||||
}
|
||||
/**
|
||||
* `History` objects hold all of the operations that are applied to a value, so
|
||||
* they can be undone or redone as necessary.
|
||||
*/
|
||||
export interface History {
|
||||
redos: Batch[];
|
||||
undos: Batch[];
|
||||
}
|
||||
export declare const History: {
|
||||
/**
|
||||
* Check if a value is a `History` object.
|
||||
*/
|
||||
isHistory(value: any): value is History;
|
||||
};
|
||||
export {};
|
||||
//# sourceMappingURL=history.d.ts.map
|
||||
1
node_modules/slate-history/dist/history.d.ts.map
generated
vendored
Normal file
1
node_modules/slate-history/dist/history.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"history.d.ts","sourceRoot":"","sources":["packages/slate-history/src/history.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,OAAO,CAAA;AAExC,UAAU,KAAK;IACb,UAAU,EAAE,SAAS,EAAE,CAAA;IACvB,eAAe,EAAE,KAAK,GAAG,IAAI,CAAA;CAC9B;AAED;;;GAGG;AAEH,MAAM,WAAW,OAAO;IACtB,KAAK,EAAE,KAAK,EAAE,CAAA;IACd,KAAK,EAAE,KAAK,EAAE,CAAA;CACf;AAGD,eAAO,MAAM,OAAO;IAClB;;OAEG;qBAEc,GAAG;CAWrB,CAAA"}
|
||||
4
node_modules/slate-history/dist/index.d.ts
generated
vendored
Normal file
4
node_modules/slate-history/dist/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
export * from './history';
|
||||
export * from './history-editor';
|
||||
export * from './with-history';
|
||||
//# sourceMappingURL=index.d.ts.map
|
||||
1
node_modules/slate-history/dist/index.d.ts.map
generated
vendored
Normal file
1
node_modules/slate-history/dist/index.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["packages/slate-history/src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA;AACzB,cAAc,kBAAkB,CAAA;AAChC,cAAc,gBAAgB,CAAA"}
|
||||
240
node_modules/slate-history/dist/index.es.js
generated
vendored
Normal file
240
node_modules/slate-history/dist/index.es.js
generated
vendored
Normal file
@@ -0,0 +1,240 @@
|
||||
import { isPlainObject } from 'is-plain-object';
|
||||
import { Operation, Editor, Transforms, Path } from 'slate';
|
||||
|
||||
var History = {
|
||||
/**
|
||||
* Check if a value is a `History` object.
|
||||
*/
|
||||
isHistory(value) {
|
||||
return isPlainObject(value) && Array.isArray(value.redos) && Array.isArray(value.undos) && (value.redos.length === 0 || Operation.isOperationList(value.redos[0].operations)) && (value.undos.length === 0 || Operation.isOperationList(value.undos[0].operations));
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Weakmaps for attaching state to the editor.
|
||||
*/
|
||||
|
||||
var HISTORY = new WeakMap();
|
||||
var SAVING = new WeakMap();
|
||||
var MERGING = new WeakMap(); // eslint-disable-next-line no-redeclare
|
||||
|
||||
var HistoryEditor = {
|
||||
/**
|
||||
* Check if a value is a `HistoryEditor` object.
|
||||
*/
|
||||
isHistoryEditor(value) {
|
||||
return History.isHistory(value.history) && Editor.isEditor(value);
|
||||
},
|
||||
|
||||
/**
|
||||
* Get the merge flag's current value.
|
||||
*/
|
||||
isMerging(editor) {
|
||||
return MERGING.get(editor);
|
||||
},
|
||||
|
||||
/**
|
||||
* Get the saving flag's current value.
|
||||
*/
|
||||
isSaving(editor) {
|
||||
return SAVING.get(editor);
|
||||
},
|
||||
|
||||
/**
|
||||
* Redo to the previous saved state.
|
||||
*/
|
||||
redo(editor) {
|
||||
editor.redo();
|
||||
},
|
||||
|
||||
/**
|
||||
* Undo to the previous saved state.
|
||||
*/
|
||||
undo(editor) {
|
||||
editor.undo();
|
||||
},
|
||||
|
||||
/**
|
||||
* Apply a series of changes inside a synchronous `fn`, without merging any of
|
||||
* the new operations into previous save point in the history.
|
||||
*/
|
||||
withoutMerging(editor, fn) {
|
||||
var prev = HistoryEditor.isMerging(editor);
|
||||
MERGING.set(editor, false);
|
||||
fn();
|
||||
MERGING.set(editor, prev);
|
||||
},
|
||||
|
||||
/**
|
||||
* Apply a series of changes inside a synchronous `fn`, without saving any of
|
||||
* their operations into the history.
|
||||
*/
|
||||
withoutSaving(editor, fn) {
|
||||
var prev = HistoryEditor.isSaving(editor);
|
||||
SAVING.set(editor, false);
|
||||
fn();
|
||||
SAVING.set(editor, prev);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* The `withHistory` plugin keeps track of the operation history of a Slate
|
||||
* editor as operations are applied to it, using undo and redo stacks.
|
||||
*
|
||||
* If you are using TypeScript, you must extend Slate's CustomTypes to use
|
||||
* this plugin.
|
||||
*
|
||||
* See https://docs.slatejs.org/concepts/11-typescript to learn how.
|
||||
*/
|
||||
|
||||
var withHistory = editor => {
|
||||
var e = editor;
|
||||
var {
|
||||
apply
|
||||
} = e;
|
||||
e.history = {
|
||||
undos: [],
|
||||
redos: []
|
||||
};
|
||||
|
||||
e.redo = () => {
|
||||
var {
|
||||
history
|
||||
} = e;
|
||||
var {
|
||||
redos
|
||||
} = history;
|
||||
|
||||
if (redos.length > 0) {
|
||||
var batch = redos[redos.length - 1];
|
||||
|
||||
if (batch.selectionBefore) {
|
||||
Transforms.setSelection(e, batch.selectionBefore);
|
||||
}
|
||||
|
||||
HistoryEditor.withoutSaving(e, () => {
|
||||
Editor.withoutNormalizing(e, () => {
|
||||
for (var op of batch.operations) {
|
||||
e.apply(op);
|
||||
}
|
||||
});
|
||||
});
|
||||
history.redos.pop();
|
||||
e.writeHistory('undos', batch);
|
||||
}
|
||||
};
|
||||
|
||||
e.undo = () => {
|
||||
var {
|
||||
history
|
||||
} = e;
|
||||
var {
|
||||
undos
|
||||
} = history;
|
||||
|
||||
if (undos.length > 0) {
|
||||
var batch = undos[undos.length - 1];
|
||||
HistoryEditor.withoutSaving(e, () => {
|
||||
Editor.withoutNormalizing(e, () => {
|
||||
var inverseOps = batch.operations.map(Operation.inverse).reverse();
|
||||
|
||||
for (var op of inverseOps) {
|
||||
e.apply(op);
|
||||
}
|
||||
|
||||
if (batch.selectionBefore) {
|
||||
Transforms.setSelection(e, batch.selectionBefore);
|
||||
}
|
||||
});
|
||||
});
|
||||
e.writeHistory('redos', batch);
|
||||
history.undos.pop();
|
||||
}
|
||||
};
|
||||
|
||||
e.apply = op => {
|
||||
var {
|
||||
operations,
|
||||
history
|
||||
} = e;
|
||||
var {
|
||||
undos
|
||||
} = history;
|
||||
var lastBatch = undos[undos.length - 1];
|
||||
var lastOp = lastBatch && lastBatch.operations[lastBatch.operations.length - 1];
|
||||
var save = HistoryEditor.isSaving(e);
|
||||
var merge = HistoryEditor.isMerging(e);
|
||||
|
||||
if (save == null) {
|
||||
save = shouldSave(op);
|
||||
}
|
||||
|
||||
if (save) {
|
||||
if (merge == null) {
|
||||
if (lastBatch == null) {
|
||||
merge = false;
|
||||
} else if (operations.length !== 0) {
|
||||
merge = true;
|
||||
} else {
|
||||
merge = shouldMerge(op, lastOp);
|
||||
}
|
||||
}
|
||||
|
||||
if (lastBatch && merge) {
|
||||
lastBatch.operations.push(op);
|
||||
} else {
|
||||
var batch = {
|
||||
operations: [op],
|
||||
selectionBefore: e.selection
|
||||
};
|
||||
e.writeHistory('undos', batch);
|
||||
}
|
||||
|
||||
while (undos.length > 100) {
|
||||
undos.shift();
|
||||
}
|
||||
|
||||
history.redos = [];
|
||||
}
|
||||
|
||||
apply(op);
|
||||
};
|
||||
|
||||
e.writeHistory = (stack, batch) => {
|
||||
e.history[stack].push(batch);
|
||||
};
|
||||
|
||||
return e;
|
||||
};
|
||||
/**
|
||||
* Check whether to merge an operation into the previous operation.
|
||||
*/
|
||||
|
||||
var shouldMerge = (op, prev) => {
|
||||
if (prev && op.type === 'insert_text' && prev.type === 'insert_text' && op.offset === prev.offset + prev.text.length && Path.equals(op.path, prev.path)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (prev && op.type === 'remove_text' && prev.type === 'remove_text' && op.offset + op.text.length === prev.offset && Path.equals(op.path, prev.path)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
/**
|
||||
* Check whether an operation needs to be saved to the history.
|
||||
*/
|
||||
|
||||
|
||||
var shouldSave = (op, prev) => {
|
||||
if (op.type === 'set_selection') {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
export { HISTORY, History, HistoryEditor, MERGING, SAVING, withHistory };
|
||||
//# sourceMappingURL=index.es.js.map
|
||||
1
node_modules/slate-history/dist/index.es.js.map
generated
vendored
Normal file
1
node_modules/slate-history/dist/index.es.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
258
node_modules/slate-history/dist/index.js
generated
vendored
Normal file
258
node_modules/slate-history/dist/index.js
generated
vendored
Normal file
@@ -0,0 +1,258 @@
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, '__esModule', { value: true });
|
||||
|
||||
var isPlainObject = require('is-plain-object');
|
||||
var slate = require('slate');
|
||||
|
||||
var History = {
|
||||
/**
|
||||
* Check if a value is a `History` object.
|
||||
*/
|
||||
isHistory: function isHistory(value) {
|
||||
return isPlainObject.isPlainObject(value) && Array.isArray(value.redos) && Array.isArray(value.undos) && (value.redos.length === 0 || slate.Operation.isOperationList(value.redos[0].operations)) && (value.undos.length === 0 || slate.Operation.isOperationList(value.undos[0].operations));
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Weakmaps for attaching state to the editor.
|
||||
*/
|
||||
|
||||
var HISTORY = new WeakMap();
|
||||
var SAVING = new WeakMap();
|
||||
var MERGING = new WeakMap(); // eslint-disable-next-line no-redeclare
|
||||
|
||||
var HistoryEditor = {
|
||||
/**
|
||||
* Check if a value is a `HistoryEditor` object.
|
||||
*/
|
||||
isHistoryEditor: function isHistoryEditor(value) {
|
||||
return History.isHistory(value.history) && slate.Editor.isEditor(value);
|
||||
},
|
||||
|
||||
/**
|
||||
* Get the merge flag's current value.
|
||||
*/
|
||||
isMerging: function isMerging(editor) {
|
||||
return MERGING.get(editor);
|
||||
},
|
||||
|
||||
/**
|
||||
* Get the saving flag's current value.
|
||||
*/
|
||||
isSaving: function isSaving(editor) {
|
||||
return SAVING.get(editor);
|
||||
},
|
||||
|
||||
/**
|
||||
* Redo to the previous saved state.
|
||||
*/
|
||||
redo: function redo(editor) {
|
||||
editor.redo();
|
||||
},
|
||||
|
||||
/**
|
||||
* Undo to the previous saved state.
|
||||
*/
|
||||
undo: function undo(editor) {
|
||||
editor.undo();
|
||||
},
|
||||
|
||||
/**
|
||||
* Apply a series of changes inside a synchronous `fn`, without merging any of
|
||||
* the new operations into previous save point in the history.
|
||||
*/
|
||||
withoutMerging: function withoutMerging(editor, fn) {
|
||||
var prev = HistoryEditor.isMerging(editor);
|
||||
MERGING.set(editor, false);
|
||||
fn();
|
||||
MERGING.set(editor, prev);
|
||||
},
|
||||
|
||||
/**
|
||||
* Apply a series of changes inside a synchronous `fn`, without saving any of
|
||||
* their operations into the history.
|
||||
*/
|
||||
withoutSaving: function withoutSaving(editor, fn) {
|
||||
var prev = HistoryEditor.isSaving(editor);
|
||||
SAVING.set(editor, false);
|
||||
fn();
|
||||
SAVING.set(editor, prev);
|
||||
}
|
||||
};
|
||||
|
||||
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
|
||||
|
||||
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
||||
|
||||
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
||||
/**
|
||||
* The `withHistory` plugin keeps track of the operation history of a Slate
|
||||
* editor as operations are applied to it, using undo and redo stacks.
|
||||
*
|
||||
* If you are using TypeScript, you must extend Slate's CustomTypes to use
|
||||
* this plugin.
|
||||
*
|
||||
* See https://docs.slatejs.org/concepts/11-typescript to learn how.
|
||||
*/
|
||||
|
||||
var withHistory = function withHistory(editor) {
|
||||
var e = editor;
|
||||
var apply = e.apply;
|
||||
e.history = {
|
||||
undos: [],
|
||||
redos: []
|
||||
};
|
||||
|
||||
e.redo = function () {
|
||||
var history = e.history;
|
||||
var redos = history.redos;
|
||||
|
||||
if (redos.length > 0) {
|
||||
var batch = redos[redos.length - 1];
|
||||
|
||||
if (batch.selectionBefore) {
|
||||
slate.Transforms.setSelection(e, batch.selectionBefore);
|
||||
}
|
||||
|
||||
HistoryEditor.withoutSaving(e, function () {
|
||||
slate.Editor.withoutNormalizing(e, function () {
|
||||
var _iterator = _createForOfIteratorHelper(batch.operations),
|
||||
_step;
|
||||
|
||||
try {
|
||||
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
||||
var op = _step.value;
|
||||
e.apply(op);
|
||||
}
|
||||
} catch (err) {
|
||||
_iterator.e(err);
|
||||
} finally {
|
||||
_iterator.f();
|
||||
}
|
||||
});
|
||||
});
|
||||
history.redos.pop();
|
||||
e.writeHistory('undos', batch);
|
||||
}
|
||||
};
|
||||
|
||||
e.undo = function () {
|
||||
var history = e.history;
|
||||
var undos = history.undos;
|
||||
|
||||
if (undos.length > 0) {
|
||||
var batch = undos[undos.length - 1];
|
||||
HistoryEditor.withoutSaving(e, function () {
|
||||
slate.Editor.withoutNormalizing(e, function () {
|
||||
var inverseOps = batch.operations.map(slate.Operation.inverse).reverse();
|
||||
|
||||
var _iterator2 = _createForOfIteratorHelper(inverseOps),
|
||||
_step2;
|
||||
|
||||
try {
|
||||
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
||||
var op = _step2.value;
|
||||
e.apply(op);
|
||||
}
|
||||
} catch (err) {
|
||||
_iterator2.e(err);
|
||||
} finally {
|
||||
_iterator2.f();
|
||||
}
|
||||
|
||||
if (batch.selectionBefore) {
|
||||
slate.Transforms.setSelection(e, batch.selectionBefore);
|
||||
}
|
||||
});
|
||||
});
|
||||
e.writeHistory('redos', batch);
|
||||
history.undos.pop();
|
||||
}
|
||||
};
|
||||
|
||||
e.apply = function (op) {
|
||||
var operations = e.operations,
|
||||
history = e.history;
|
||||
var undos = history.undos;
|
||||
var lastBatch = undos[undos.length - 1];
|
||||
var lastOp = lastBatch && lastBatch.operations[lastBatch.operations.length - 1];
|
||||
var save = HistoryEditor.isSaving(e);
|
||||
var merge = HistoryEditor.isMerging(e);
|
||||
|
||||
if (save == null) {
|
||||
save = shouldSave(op);
|
||||
}
|
||||
|
||||
if (save) {
|
||||
if (merge == null) {
|
||||
if (lastBatch == null) {
|
||||
merge = false;
|
||||
} else if (operations.length !== 0) {
|
||||
merge = true;
|
||||
} else {
|
||||
merge = shouldMerge(op, lastOp);
|
||||
}
|
||||
}
|
||||
|
||||
if (lastBatch && merge) {
|
||||
lastBatch.operations.push(op);
|
||||
} else {
|
||||
var batch = {
|
||||
operations: [op],
|
||||
selectionBefore: e.selection
|
||||
};
|
||||
e.writeHistory('undos', batch);
|
||||
}
|
||||
|
||||
while (undos.length > 100) {
|
||||
undos.shift();
|
||||
}
|
||||
|
||||
history.redos = [];
|
||||
}
|
||||
|
||||
apply(op);
|
||||
};
|
||||
|
||||
e.writeHistory = function (stack, batch) {
|
||||
e.history[stack].push(batch);
|
||||
};
|
||||
|
||||
return e;
|
||||
};
|
||||
/**
|
||||
* Check whether to merge an operation into the previous operation.
|
||||
*/
|
||||
|
||||
var shouldMerge = function shouldMerge(op, prev) {
|
||||
if (prev && op.type === 'insert_text' && prev.type === 'insert_text' && op.offset === prev.offset + prev.text.length && slate.Path.equals(op.path, prev.path)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (prev && op.type === 'remove_text' && prev.type === 'remove_text' && op.offset + op.text.length === prev.offset && slate.Path.equals(op.path, prev.path)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
/**
|
||||
* Check whether an operation needs to be saved to the history.
|
||||
*/
|
||||
|
||||
|
||||
var shouldSave = function shouldSave(op, prev) {
|
||||
if (op.type === 'set_selection') {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
exports.HISTORY = HISTORY;
|
||||
exports.History = History;
|
||||
exports.HistoryEditor = HistoryEditor;
|
||||
exports.MERGING = MERGING;
|
||||
exports.SAVING = SAVING;
|
||||
exports.withHistory = withHistory;
|
||||
//# sourceMappingURL=index.js.map
|
||||
1
node_modules/slate-history/dist/index.js.map
generated
vendored
Normal file
1
node_modules/slate-history/dist/index.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
293
node_modules/slate-history/dist/slate-history.js
generated
vendored
Normal file
293
node_modules/slate-history/dist/slate-history.js
generated
vendored
Normal file
@@ -0,0 +1,293 @@
|
||||
(function (global, factory) {
|
||||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('slate')) :
|
||||
typeof define === 'function' && define.amd ? define(['exports', 'slate'], factory) :
|
||||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.SlateHistory = {}, global.Slate));
|
||||
}(this, (function (exports, slate) { 'use strict';
|
||||
|
||||
/*!
|
||||
* is-plain-object <https://github.com/jonschlinkert/is-plain-object>
|
||||
*
|
||||
* Copyright (c) 2014-2017, Jon Schlinkert.
|
||||
* Released under the MIT License.
|
||||
*/
|
||||
|
||||
function isObject(o) {
|
||||
return Object.prototype.toString.call(o) === '[object Object]';
|
||||
}
|
||||
|
||||
function isPlainObject(o) {
|
||||
var ctor,prot;
|
||||
|
||||
if (isObject(o) === false) return false;
|
||||
|
||||
// If has modified constructor
|
||||
ctor = o.constructor;
|
||||
if (ctor === undefined) return true;
|
||||
|
||||
// If has modified prototype
|
||||
prot = ctor.prototype;
|
||||
if (isObject(prot) === false) return false;
|
||||
|
||||
// If constructor does not have an Object-specific method
|
||||
if (prot.hasOwnProperty('isPrototypeOf') === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Most likely a plain Object
|
||||
return true;
|
||||
}
|
||||
|
||||
var History = {
|
||||
/**
|
||||
* Check if a value is a `History` object.
|
||||
*/
|
||||
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].operations)) && (value.undos.length === 0 || slate.Operation.isOperationList(value.undos[0].operations));
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Weakmaps for attaching state to the editor.
|
||||
*/
|
||||
|
||||
var HISTORY = new WeakMap();
|
||||
var SAVING = new WeakMap();
|
||||
var MERGING = new WeakMap(); // eslint-disable-next-line no-redeclare
|
||||
|
||||
var HistoryEditor = {
|
||||
/**
|
||||
* Check if a value is a `HistoryEditor` object.
|
||||
*/
|
||||
isHistoryEditor: function isHistoryEditor(value) {
|
||||
return History.isHistory(value.history) && slate.Editor.isEditor(value);
|
||||
},
|
||||
|
||||
/**
|
||||
* Get the merge flag's current value.
|
||||
*/
|
||||
isMerging: function isMerging(editor) {
|
||||
return MERGING.get(editor);
|
||||
},
|
||||
|
||||
/**
|
||||
* Get the saving flag's current value.
|
||||
*/
|
||||
isSaving: function isSaving(editor) {
|
||||
return SAVING.get(editor);
|
||||
},
|
||||
|
||||
/**
|
||||
* Redo to the previous saved state.
|
||||
*/
|
||||
redo: function redo(editor) {
|
||||
editor.redo();
|
||||
},
|
||||
|
||||
/**
|
||||
* Undo to the previous saved state.
|
||||
*/
|
||||
undo: function undo(editor) {
|
||||
editor.undo();
|
||||
},
|
||||
|
||||
/**
|
||||
* Apply a series of changes inside a synchronous `fn`, without merging any of
|
||||
* the new operations into previous save point in the history.
|
||||
*/
|
||||
withoutMerging: function withoutMerging(editor, fn) {
|
||||
var prev = HistoryEditor.isMerging(editor);
|
||||
MERGING.set(editor, false);
|
||||
fn();
|
||||
MERGING.set(editor, prev);
|
||||
},
|
||||
|
||||
/**
|
||||
* Apply a series of changes inside a synchronous `fn`, without saving any of
|
||||
* their operations into the history.
|
||||
*/
|
||||
withoutSaving: function withoutSaving(editor, fn) {
|
||||
var prev = HistoryEditor.isSaving(editor);
|
||||
SAVING.set(editor, false);
|
||||
fn();
|
||||
SAVING.set(editor, prev);
|
||||
}
|
||||
};
|
||||
|
||||
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
|
||||
|
||||
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
||||
|
||||
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
||||
/**
|
||||
* The `withHistory` plugin keeps track of the operation history of a Slate
|
||||
* editor as operations are applied to it, using undo and redo stacks.
|
||||
*
|
||||
* If you are using TypeScript, you must extend Slate's CustomTypes to use
|
||||
* this plugin.
|
||||
*
|
||||
* See https://docs.slatejs.org/concepts/11-typescript to learn how.
|
||||
*/
|
||||
|
||||
var withHistory = function withHistory(editor) {
|
||||
var e = editor;
|
||||
var apply = e.apply;
|
||||
e.history = {
|
||||
undos: [],
|
||||
redos: []
|
||||
};
|
||||
|
||||
e.redo = function () {
|
||||
var history = e.history;
|
||||
var redos = history.redos;
|
||||
|
||||
if (redos.length > 0) {
|
||||
var batch = redos[redos.length - 1];
|
||||
|
||||
if (batch.selectionBefore) {
|
||||
slate.Transforms.setSelection(e, batch.selectionBefore);
|
||||
}
|
||||
|
||||
HistoryEditor.withoutSaving(e, function () {
|
||||
slate.Editor.withoutNormalizing(e, function () {
|
||||
var _iterator = _createForOfIteratorHelper(batch.operations),
|
||||
_step;
|
||||
|
||||
try {
|
||||
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
||||
var op = _step.value;
|
||||
e.apply(op);
|
||||
}
|
||||
} catch (err) {
|
||||
_iterator.e(err);
|
||||
} finally {
|
||||
_iterator.f();
|
||||
}
|
||||
});
|
||||
});
|
||||
history.redos.pop();
|
||||
e.writeHistory('undos', batch);
|
||||
}
|
||||
};
|
||||
|
||||
e.undo = function () {
|
||||
var history = e.history;
|
||||
var undos = history.undos;
|
||||
|
||||
if (undos.length > 0) {
|
||||
var batch = undos[undos.length - 1];
|
||||
HistoryEditor.withoutSaving(e, function () {
|
||||
slate.Editor.withoutNormalizing(e, function () {
|
||||
var inverseOps = batch.operations.map(slate.Operation.inverse).reverse();
|
||||
|
||||
var _iterator2 = _createForOfIteratorHelper(inverseOps),
|
||||
_step2;
|
||||
|
||||
try {
|
||||
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
||||
var op = _step2.value;
|
||||
e.apply(op);
|
||||
}
|
||||
} catch (err) {
|
||||
_iterator2.e(err);
|
||||
} finally {
|
||||
_iterator2.f();
|
||||
}
|
||||
|
||||
if (batch.selectionBefore) {
|
||||
slate.Transforms.setSelection(e, batch.selectionBefore);
|
||||
}
|
||||
});
|
||||
});
|
||||
e.writeHistory('redos', batch);
|
||||
history.undos.pop();
|
||||
}
|
||||
};
|
||||
|
||||
e.apply = function (op) {
|
||||
var operations = e.operations,
|
||||
history = e.history;
|
||||
var undos = history.undos;
|
||||
var lastBatch = undos[undos.length - 1];
|
||||
var lastOp = lastBatch && lastBatch.operations[lastBatch.operations.length - 1];
|
||||
var save = HistoryEditor.isSaving(e);
|
||||
var merge = HistoryEditor.isMerging(e);
|
||||
|
||||
if (save == null) {
|
||||
save = shouldSave(op);
|
||||
}
|
||||
|
||||
if (save) {
|
||||
if (merge == null) {
|
||||
if (lastBatch == null) {
|
||||
merge = false;
|
||||
} else if (operations.length !== 0) {
|
||||
merge = true;
|
||||
} else {
|
||||
merge = shouldMerge(op, lastOp);
|
||||
}
|
||||
}
|
||||
|
||||
if (lastBatch && merge) {
|
||||
lastBatch.operations.push(op);
|
||||
} else {
|
||||
var batch = {
|
||||
operations: [op],
|
||||
selectionBefore: e.selection
|
||||
};
|
||||
e.writeHistory('undos', batch);
|
||||
}
|
||||
|
||||
while (undos.length > 100) {
|
||||
undos.shift();
|
||||
}
|
||||
|
||||
history.redos = [];
|
||||
}
|
||||
|
||||
apply(op);
|
||||
};
|
||||
|
||||
e.writeHistory = function (stack, batch) {
|
||||
e.history[stack].push(batch);
|
||||
};
|
||||
|
||||
return e;
|
||||
};
|
||||
/**
|
||||
* Check whether to merge an operation into the previous operation.
|
||||
*/
|
||||
|
||||
var shouldMerge = function shouldMerge(op, prev) {
|
||||
if (prev && op.type === 'insert_text' && prev.type === 'insert_text' && op.offset === prev.offset + prev.text.length && slate.Path.equals(op.path, prev.path)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (prev && op.type === 'remove_text' && prev.type === 'remove_text' && op.offset + op.text.length === prev.offset && slate.Path.equals(op.path, prev.path)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
/**
|
||||
* Check whether an operation needs to be saved to the history.
|
||||
*/
|
||||
|
||||
|
||||
var shouldSave = function shouldSave(op, prev) {
|
||||
if (op.type === 'set_selection') {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
exports.HISTORY = HISTORY;
|
||||
exports.History = History;
|
||||
exports.HistoryEditor = HistoryEditor;
|
||||
exports.MERGING = MERGING;
|
||||
exports.SAVING = SAVING;
|
||||
exports.withHistory = withHistory;
|
||||
|
||||
Object.defineProperty(exports, '__esModule', { value: true });
|
||||
|
||||
})));
|
||||
7
node_modules/slate-history/dist/slate-history.min.js
generated
vendored
Normal file
7
node_modules/slate-history/dist/slate-history.min.js
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("slate")):"function"==typeof define&&define.amd?define(["exports","slate"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).SlateHistory={},t.Slate)}(this,(function(t,e){"use strict";
|
||||
/*!
|
||||
* is-plain-object <https://github.com/jonschlinkert/is-plain-object>
|
||||
*
|
||||
* Copyright (c) 2014-2017, Jon Schlinkert.
|
||||
* Released under the MIT License.
|
||||
*/function n(t){return"[object Object]"===Object.prototype.toString.call(t)}var r={isHistory:function(t){return!1!==n(r=t)&&(void 0===(o=r.constructor)||!1!==n(i=o.prototype)&&!1!==i.hasOwnProperty("isPrototypeOf"))&&Array.isArray(t.redos)&&Array.isArray(t.undos)&&(0===t.redos.length||e.Operation.isOperationList(t.redos[0].operations))&&(0===t.undos.length||e.Operation.isOperationList(t.undos[0].operations));var r,o,i}},o=new WeakMap,i=new WeakMap,s=new WeakMap,a={isHistoryEditor:function(t){return r.isHistory(t.history)&&e.Editor.isEditor(t)},isMerging:function(t){return s.get(t)},isSaving:function(t){return i.get(t)},redo:function(t){t.redo()},undo:function(t){t.undo()},withoutMerging:function(t,e){var n=a.isMerging(t);s.set(t,!1),e(),s.set(t,n)},withoutSaving:function(t,e){var n=a.isSaving(t);i.set(t,!1),e(),i.set(t,n)}};function u(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!n){if(Array.isArray(t)||(n=function(t,e){if(!t)return;if("string"==typeof t)return f(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);"Object"===n&&t.constructor&&(n=t.constructor.name);if("Map"===n||"Set"===n)return Array.from(t);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return f(t,e)}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var r=0,o=function(){};return{s:o,n:function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}},e:function(t){throw t},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,s=!0,a=!1;return{s:function(){n=n.call(t)},n:function(){var t=n.next();return s=t.done,t},e:function(t){a=!0,i=t},f:function(){try{s||null==n.return||n.return()}finally{if(a)throw i}}}}function f(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}var l=function(t,n){return!(!n||"insert_text"!==t.type||"insert_text"!==n.type||t.offset!==n.offset+n.text.length||!e.Path.equals(t.path,n.path))||!(!n||"remove_text"!==t.type||"remove_text"!==n.type||t.offset+t.text.length!==n.offset||!e.Path.equals(t.path,n.path))},c=function(t,e){return"set_selection"!==t.type};t.HISTORY=o,t.History=r,t.HistoryEditor=a,t.MERGING=s,t.SAVING=i,t.withHistory=function(t){var n=t,r=n.apply;return n.history={undos:[],redos:[]},n.redo=function(){var t=n.history,r=t.redos;if(r.length>0){var o=r[r.length-1];o.selectionBefore&&e.Transforms.setSelection(n,o.selectionBefore),a.withoutSaving(n,(function(){e.Editor.withoutNormalizing(n,(function(){var t,e=u(o.operations);try{for(e.s();!(t=e.n()).done;){var r=t.value;n.apply(r)}}catch(t){e.e(t)}finally{e.f()}}))})),t.redos.pop(),n.writeHistory("undos",o)}},n.undo=function(){var t=n.history,r=t.undos;if(r.length>0){var o=r[r.length-1];a.withoutSaving(n,(function(){e.Editor.withoutNormalizing(n,(function(){var t,r=u(o.operations.map(e.Operation.inverse).reverse());try{for(r.s();!(t=r.n()).done;){var i=t.value;n.apply(i)}}catch(t){r.e(t)}finally{r.f()}o.selectionBefore&&e.Transforms.setSelection(n,o.selectionBefore)}))})),n.writeHistory("redos",o),t.undos.pop()}},n.apply=function(t){var e=n.operations,o=n.history,i=o.undos,s=i[i.length-1],u=s&&s.operations[s.operations.length-1],f=a.isSaving(n),p=a.isMerging(n);if(null==f&&(f=c(t)),f){if(null==p&&(p=null!=s&&(0!==e.length||l(t,u))),s&&p)s.operations.push(t);else{var y={operations:[t],selectionBefore:n.selection};n.writeHistory("undos",y)}for(;i.length>100;)i.shift();o.redos=[]}r(t)},n.writeHistory=function(t,e){n.history[t].push(e)},n},Object.defineProperty(t,"__esModule",{value:!0})}));
|
||||
12
node_modules/slate-history/dist/with-history.d.ts
generated
vendored
Normal file
12
node_modules/slate-history/dist/with-history.d.ts
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
import { HistoryEditor } from './history-editor';
|
||||
/**
|
||||
* The `withHistory` plugin keeps track of the operation history of a Slate
|
||||
* editor as operations are applied to it, using undo and redo stacks.
|
||||
*
|
||||
* If you are using TypeScript, you must extend Slate's CustomTypes to use
|
||||
* this plugin.
|
||||
*
|
||||
* See https://docs.slatejs.org/concepts/11-typescript to learn how.
|
||||
*/
|
||||
export declare const withHistory: <T extends import("slate").BaseEditor>(editor: T) => T & HistoryEditor;
|
||||
//# sourceMappingURL=with-history.d.ts.map
|
||||
1
node_modules/slate-history/dist/with-history.d.ts.map
generated
vendored
Normal file
1
node_modules/slate-history/dist/with-history.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"with-history.d.ts","sourceRoot":"","sources":["packages/slate-history/src/with-history.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAEhD;;;;;;;;GAQG;AAEH,eAAO,MAAM,WAAW,wEAuGvB,CAAA"}
|
||||
Reference in New Issue
Block a user