Skip to content

Commit

Permalink
[#185] Added canvas onLoad props
Browse files Browse the repository at this point in the history
  • Loading branch information
salgum1114 committed May 25, 2020
1 parent b1b0d97 commit 93adf82
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-design-editor",
"version": "0.0.26",
"version": "0.0.27",
"description": "Design Editor Tools with React.js + ant.design + fabric.js",
"main": "dist/react-design-editor.min.js",
"typings": "lib/index.d.ts",
Expand Down
3 changes: 1 addition & 2 deletions src/components/canvas/Canvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import { v4 } from 'uuid';
import ResizeObserver from 'resize-observer-polyfill';
import union from 'lodash/union';

import { Handler } from './handlers';
import { HandlerOptions } from './handlers/Handler';
import Handler, { HandlerOptions } from './handlers/Handler';
import { FabricCanvas } from './utils';

import '../../styles/core/canvas.less';
Expand Down
19 changes: 19 additions & 0 deletions src/components/canvas/handlers/Handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,17 @@ export interface HandlerOptions {

/**
* When has been added object in Canvas, Called function
*
*/
onAdd?: (object: FabricObject) => void;
/**
* Return contextmenu element
*
*/
onContext?: (el: HTMLDivElement, e: React.MouseEvent, target?: FabricObject) => Promise<any> | any;
/**
* Return tooltip element
*
*/
onTooltip?: (el: HTMLDivElement, target?: FabricObject) => Promise<any> | any;
/**
Expand All @@ -166,10 +169,12 @@ export interface HandlerOptions {
onZoom?: (zoomRatio: number) => void;
/**
* When clicked object, Called function
*
*/
onClick?: (canvas: FabricCanvas, target: FabricObject) => void;
/**
* When double clicked object, Called function
*
*/
onDblClick?: (canvas: FabricCanvas, target: FabricObject) => void;
/**
Expand All @@ -178,20 +183,29 @@ export interface HandlerOptions {
onModified?: (target: FabricObject) => void;
/**
* When select object, Called function
*
*/
onSelect?: (target: FabricObject) => void;
/**
* When has been removed object in Canvas, Called function
*
*/
onRemove?: (target: FabricObject) => void;
/**
* When has been undo or redo, Called function
*
*/
onTransaction?: (transaction: TransactionEvent) => void;
/**
* When has been changed interaction mode, Called function
*
*/
onInteraction?: (interactionMode: InteractionMode) => void;
/**
* When canvas has been loaded
*
*/
onLoad?: (handler: Handler, canvas?: fabric.Canvas) => void;
}

/**
Expand Down Expand Up @@ -236,6 +250,7 @@ class Handler implements HandlerOptions {
public onRemove?: (target: FabricObject) => void;
public onTransaction?: (transaction: TransactionEvent) => void;
public onInteraction?: (interactionMode: InteractionMode) => void;
public onLoad?: (handler: Handler, canvas?: fabric.Canvas) => void;

public imageHandler: ImageHandler;
public chartHandler: ChartHandler;
Expand Down Expand Up @@ -277,6 +292,9 @@ class Handler implements HandlerOptions {
this.init(options);
this.initCallback(options);
this.initHandler(options);
if (this.onLoad) {
this.onLoad(this, this.canvas);
}
}

/**
Expand Down Expand Up @@ -323,6 +341,7 @@ class Handler implements HandlerOptions {
this.onRemove = options.onRemove;
this.onTransaction = options.onTransaction;
this.onInteraction = options.onInteraction;
this.onLoad = options.onLoad;
};

/**
Expand Down

0 comments on commit 93adf82

Please sign in to comment.