Socket
Socket
Sign inDemoInstall

@codemirror/history

Package Overview
Dependencies
6
Maintainers
2
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.18.0 to 0.18.1

10

CHANGELOG.md

@@ -0,3 +1,13 @@

## 0.18.1 (2021-03-23)
### New features
The state field used by the history is now public, and has `toJSON` and `fromJSON` functions for serialization.
## 0.18.0 (2021-03-03)
### Breaking changes
Update dependencies to 0.18.
## 0.17.2 (2021-01-19)

@@ -4,0 +14,0 @@

64

dist/index.d.ts

@@ -1,19 +0,79 @@

import { AnnotationType, Facet, Transaction, StateEffect, Extension, StateCommand, EditorState } from '@codemirror/state';
import { AnnotationType, Facet, Transaction, StateEffect, Extension, StateField, StateCommand, EditorState } from '@codemirror/state';
import { KeyBinding } from '@codemirror/view';
/**
Transaction annotation that will prevent that transaction from
being combined with other transactions in the undo history. Given
`"before"`, it'll prevent merging with previous transactions. With
`"after"`, subsequent transactions won't be combined with this
one. With `"full"`, the transaction is isolated on both sides.
*/
declare const isolateHistory: AnnotationType<"before" | "after" | "full">;
/**
This facet provides a way to register functions that, given a
transaction, provide a set of effects that the history should
store when inverting the transaction. This can be used to
integrate some kinds of effects in the history, so that they can
be undone (and redone again).
*/
declare const invertedEffects: Facet<(tr: Transaction) => readonly StateEffect<any>[], readonly ((tr: Transaction) => readonly StateEffect<any>[])[]>;
interface HistoryConfig {
/**
The minimum depth (amount of events) to store. Defaults to 100.
*/
minDepth?: number;
/**
The maximum time (in milliseconds) that adjacent events can be
apart and still be grouped together. Defaults to 500.
*/
newGroupDelay?: number;
}
/**
Create a history extension with the given configuration.
*/
declare function history(config?: HistoryConfig): Extension;
/**
The state field used to store the history data. Should probably
only be used when you want to
[serialize](https://codemirror.net/6/docs/ref/#state.EditorState.toJSON) or
[deserialize](https://codemirror.net/6/docs/ref/#state.EditorState^fromJSON) state objects in a way
that preserves history.
*/
declare const historyField: StateField<unknown>;
/**
Undo a single group of history events. Returns false if no group
was available.
*/
declare const undo: StateCommand;
/**
Redo a group of history events. Returns false if no group was
available.
*/
declare const redo: StateCommand;
/**
Undo a selection change.
*/
declare const undoSelection: StateCommand;
/**
Redo a selection change.
*/
declare const redoSelection: StateCommand;
/**
The amount of undoable change events available in a given state.
*/
declare const undoDepth: (state: EditorState) => number;
/**
The amount of redoable change events available in a given state.
*/
declare const redoDepth: (state: EditorState) => number;
/**
Default key bindings for the undo history.
- Mod-z: [`undo`](https://codemirror.net/6/docs/ref/#history.undo).
- Mod-y (Mod-Shift-z on macOS): [`redo`](https://codemirror.net/6/docs/ref/#history.redo).
- Mod-u: [`undoSelection`](https://codemirror.net/6/docs/ref/#history.undoSelection).
- Alt-u (Mod-Shift-u on macOS): [`redoSelection`](https://codemirror.net/6/docs/ref/#history.redoSelection).
*/
declare const historyKeymap: readonly KeyBinding[];
export { history, historyKeymap, invertedEffects, isolateHistory, redo, redoDepth, redoSelection, undo, undoDepth, undoSelection };
export { history, historyField, historyKeymap, invertedEffects, isolateHistory, redo, redoDepth, redoSelection, undo, undoDepth, undoSelection };

108

dist/index.js

@@ -1,16 +0,20 @@

import { Annotation, Facet, combineConfig, StateField, Transaction, StateEffect } from '@codemirror/state';
import { Annotation, Facet, combineConfig, StateField, Transaction, ChangeSet, ChangeDesc, EditorSelection, StateEffect } from '@codemirror/state';
import { EditorView } from '@codemirror/view';
const fromHistory = Annotation.define();
/// Transaction annotation that will prevent that transaction from
/// being combined with other transactions in the undo history. Given
/// `"before"`, it'll prevent merging with previous transactions. With
/// `"after"`, subsequent transactions won't be combined with this
/// one. With `"full"`, the transaction is isolated on both sides.
/**
Transaction annotation that will prevent that transaction from
being combined with other transactions in the undo history. Given
`"before"`, it'll prevent merging with previous transactions. With
`"after"`, subsequent transactions won't be combined with this
one. With `"full"`, the transaction is isolated on both sides.
*/
const isolateHistory = Annotation.define();
/// This facet provides a way to register functions that, given a
/// transaction, provide a set of effects that the history should
/// store when inverting the transaction. This can be used to
/// integrate some kinds of effects in the history, so that they can
/// be undone (and redone again).
/**
This facet provides a way to register functions that, given a
transaction, provide a set of effects that the history should
store when inverting the transaction. This can be used to
integrate some kinds of effects in the history, so that they can
be undone (and redone again).
*/
const invertedEffects = Facet.define();

@@ -25,3 +29,3 @@ const historyConfig = Facet.define({

});
const historyField = StateField.define({
const historyField_ = StateField.define({
create() {

@@ -56,8 +60,16 @@ return HistoryState.empty;

return state;
},
toJSON(value) {
return { done: value.done.map(e => e.toJSON()), undone: value.undone.map(e => e.toJSON()) };
},
fromJSON(json) {
return new HistoryState(json.done.map(HistEvent.fromJSON), json.undone.map(HistEvent.fromJSON));
}
});
/// Create a history extension with the given configuration.
/**
Create a history extension with the given configuration.
*/
function history(config = {}) {
return [
historyField,
historyField_,
historyConfig.of(config),

@@ -75,5 +87,13 @@ EditorView.domEventHandlers({

}
/**
The state field used to store the history data. Should probably
only be used when you want to
[serialize](https://codemirror.net/6/docs/ref/#state.EditorState.toJSON) or
[deserialize](https://codemirror.net/6/docs/ref/#state.EditorState^fromJSON) state objects in a way
that preserves history.
*/
const historyField = historyField_;
function cmd(side, selection) {
return function ({ state, dispatch }) {
let historyState = state.field(historyField, false);
let historyState = state.field(historyField_, false);
if (!historyState)

@@ -88,15 +108,23 @@ return false;

}
/// Undo a single group of history events. Returns false if no group
/// was available.
/**
Undo a single group of history events. Returns false if no group
was available.
*/
const undo = cmd(0 /* Done */, false);
/// Redo a group of history events. Returns false if no group was
/// available.
/**
Redo a group of history events. Returns false if no group was
available.
*/
const redo = cmd(1 /* Undone */, false);
/// Undo a selection change.
/**
Undo a selection change.
*/
const undoSelection = cmd(0 /* Done */, true);
/// Redo a selection change.
/**
Redo a selection change.
*/
const redoSelection = cmd(1 /* Undone */, true);
function depth(side) {
return function (state) {
let histState = state.field(historyField, false);
let histState = state.field(historyField_, false);
if (!histState)

@@ -108,5 +136,9 @@ return 0;

}
/// The amount of undoable change events available in a given state.
/**
The amount of undoable change events available in a given state.
*/
const undoDepth = depth(0 /* Done */);
/// The amount of redoable change events available in a given state.
/**
The amount of redoable change events available in a given state.
*/
const redoDepth = depth(1 /* Undone */);

@@ -139,2 +171,14 @@ // History events store groups of changes or effects that need to be

}
toJSON() {
var _a, _b, _c;
return {
changes: (_a = this.changes) === null || _a === void 0 ? void 0 : _a.toJSON(),
mapped: (_b = this.mapped) === null || _b === void 0 ? void 0 : _b.toJSON(),
startSelection: (_c = this.startSelection) === null || _c === void 0 ? void 0 : _c.toJSON(),
selectionsAfter: this.selectionsAfter.map(s => s.toJSON())
};
}
static fromJSON(json) {
return new HistEvent(json.changes && ChangeSet.fromJSON(json.changes), [], json.mapped && ChangeDesc.fromJSON(json.mapped), json.startSelection && EditorSelection.fromJSON(json.startSelection), json.selectionsAfter.map(EditorSelection.fromJSON));
}
// This does not check `addToHistory` and such, it assumes the

@@ -301,8 +345,10 @@ // transaction needs to be converted to an item. Returns null when

HistoryState.empty = new HistoryState(none, none);
/// Default key bindings for the undo history.
///
/// - Mod-z: [`undo`](#history.undo).
/// - Mod-y (Mod-Shift-z on macOS): [`redo`](#history.redo).
/// - Mod-u: [`undoSelection`](#history.undoSelection).
/// - Alt-u (Mod-Shift-u on macOS): [`redoSelection`](#history.redoSelection).
/**
Default key bindings for the undo history.
- Mod-z: [`undo`](https://codemirror.net/6/docs/ref/#history.undo).
- Mod-y (Mod-Shift-z on macOS): [`redo`](https://codemirror.net/6/docs/ref/#history.redo).
- Mod-u: [`undoSelection`](https://codemirror.net/6/docs/ref/#history.undoSelection).
- Alt-u (Mod-Shift-u on macOS): [`redoSelection`](https://codemirror.net/6/docs/ref/#history.redoSelection).
*/
const historyKeymap = [

@@ -315,2 +361,2 @@ { key: "Mod-z", run: undo, preventDefault: true },

export { history, historyKeymap, invertedEffects, isolateHistory, redo, redoDepth, redoSelection, undo, undoDepth, undoSelection };
export { history, historyField, historyKeymap, invertedEffects, isolateHistory, redo, redoDepth, redoSelection, undo, undoDepth, undoSelection };
{
"name": "@codemirror/history",
"version": "0.18.0",
"version": "0.18.1",
"description": "Undo/redo history for the CodeMirror code editor",
"scripts": {
"test": "mocha test/test-*.js",
"prepare": "tsc -p tsconfig.local.json && rollup -c"
"prepare": "cm-buildhelper src/history.ts"
},

@@ -29,9 +29,7 @@ "keywords": [

"dependencies": {
"@codemirror/state": "^0.18.0",
"@codemirror/state": "^0.18.3",
"@codemirror/view": "^0.18.0"
},
"devDependencies": {
"rollup": "^2.35.1",
"rollup-plugin-dts": "^2.0.1",
"typescript": "^4.1.3",
"@codemirror/buildhelper": "^0.1.0",
"@types/mocha": "^5.2.0",

@@ -38,0 +36,0 @@ "ist": "^1.1.6",

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc