0.8.54 • Published 3 years ago

@naetverkjs/history v0.8.54

Weekly downloads
15
License
MIT
Repository
github
Last release
3 years ago

history-plugin

This Plugin is based on the retejs/history-plugin

Plugin that adds the ability to revert actions

Installation

Import

import { HistoryPlugin } from '@naetverkjs/history';

editor.use(HistoryPlugin);

Configuration

editor.use(HistoryPlugin, { keyboard: true });

Available commands

editor.trigger('undo');
editor.trigger('redo');

Custom History Actions

import { Action } from '@naetverkjs/history';

export class YourAction extends HistoryAction {
  constructor() {
    super();
  }
  undo() {
    ///
  }
  redo() {
    ///
  }
}

editor.trigger('addhistory', new YourAction());

Example: Add text field changes to history

class FieldChangeAction extends HistoryPlugin.HistoryAction {
  constructor(prev, next, set) {
    super();
    this.prev = prev;
    this.next = next;
    this.set = set;
  }
  undo() {
    this.set(this.prev);
  }
  redo() {
    this.set(this.next);
  }
}

// inside a "change" method of your Control (called by user action)
// this.value - value before changing
// next - new value
// (v) => this.set(v) - change value of Field by undo/redo
this.emitter.trigger(
  'addhistory',
  new FieldChangeAction(this.value, next, (v) => this.set(v))
);
0.8.54

3 years ago

0.8.52

3 years ago

0.8.53

3 years ago

0.8.5

3 years ago

0.8.42

3 years ago

0.8.5-beta.1

4 years ago

0.8.4

4 years ago

0.8.5-beta.0

4 years ago

0.8.3

4 years ago