• Stars
    star
    147
  • Rank 251,347 (Top 5 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 5 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Fabric.js history plugin

fabric-history

npm npm

Fabric.js history implementation

Setup

Node projects

npm i fabric-history
import 'fabric-history';

HTML

<script src="https://raw.githubusercontent.com/lyzerk/fabric-history/master/src/index.js"></script>

Usage

Following commands will undo and redo the canvas.

canvas.undo();

canvas.redo();

Example (only for demo purposes)

<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Fabric with history</title>
</head>
<body>
  <canvas style="border:1px solid black;" width="800" height="400"></canvas>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/fabric.js/3.4.0/fabric.min.js"></script>
  <script src="https://alimozdemir.com/fabric-history/src/index.js"></script>

  <script>
    const canvas = new fabric.Canvas(document.querySelector('canvas'), {
      isDrawingMode: true
    })

    document.addEventListener('keyup', ({ keyCode, ctrlKey } = event) => {
      // Check Ctrl key is pressed.
      if (!ctrlKey) {
        return
      }

      // Check pressed button is Z - Ctrl+Z.
      if (keyCode === 90) {
        canvas.undo()
      }

      // Check pressed button is Y - Ctrl+Y.
      if (keyCode === 89) {
        canvas.redo()
      }
    })
    </script>
</body>
</html>

You can find an advanced example on demo folder.

Events

  • history:append
    • Fired when a history appended to stack
  • history:undo
    • Fired when an undo process is happening
  • history:redo
    • Fired when a redo process is happening
  • history:clear
    • Fired when whole history cleared

Callbacks

canvas.undo(function() { 
  console.log('post undo');
});

canvas.redo(function() { 
  console.log('post redo');
});

Functions

  • undo
  • redo
  • clearHistory

More Repositories

1

PromptCLI

Interactive command line interface library
C#
33
star
2

medium

Medium's story work repository
JavaScript
31
star
3

DataSuit

netstandard2.0 random data generator
C#
16
star
4

Hangfire.Docker

An experimental hangfire docker project with multiple servers (workers)
C#
16
star
5

vscode-linecounter

Line counter for visual studio code
TypeScript
11
star
6

DDown

a dotnet core downloader API
C#
8
star
7

Grand.Plugin.Payments.Iyzico

GrandNode Iyzico implementation
C#
6
star
8

ChannelX

ChannelX: Transient Shared Communication Channels
C#
6
star
9

fla-pda

Push Down Automata implementation
C
4
star
10

Triggr

Lightweight source code monitoring tool
C#
3
star
11

fabric-diagram

Useful fabrics objects and functions
JavaScript
1
star
12

FLA_cyk

Formal Languages and Automata Cyk Algorithm basic implementation
C++
1
star
13

paramsBenchmark

C# params keyword benchmark repository
HTML
1
star
14

mvcf

1
star
15

SimpleScheduler

A simple scheduler with dotnet core
C#
1
star
16

POCCHW3

Principle of Computer Communications Homework 3
C
1
star
17

parallelFileReadingBenchmark

Benchmark dotnet parallel file reading
C#
1
star
18

messenger_app

A basic implementation of a messenger app with backend and frontend
C#
1
star
19

lyzerk.github.io

personal website
HTML
1
star
20

Hangfire.ThemeEngine

A theme engine for hangfire. It includes more than one themes.
C#
1
star
21

used_things

Used technologies, frameworks and libraries while doing somethings
1
star
22

aoa-parsing

Analysis of Algorithms II, 2016-2017 Spring Semester Project 2. Parsing Tree.
C++
1
star
23

CATest

codeaware tests
Java
1
star
24

Xamarin.UWP.DeepLinkSample

Deep link sample on xamarin uwp
C#
1
star