react-design-editor 0.0.32 → 0.0.36

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. package/README.md +37 -33
  2. package/dist/react-design-editor.js +33723 -13736
  3. package/dist/react-design-editor.min.js +1 -1
  4. package/dist/react-design-editor.min.js.LICENSE.txt +13 -2
  5. package/lib/Canvas.d.ts +18 -32
  6. package/lib/Canvas.js +172 -245
  7. package/lib/CanvasObject.d.ts +10 -10
  8. package/lib/CanvasObject.js +96 -89
  9. package/lib/constants/code.d.ts +19 -0
  10. package/lib/constants/code.js +22 -0
  11. package/lib/constants/defaults.d.ts +38 -0
  12. package/lib/constants/defaults.js +69 -0
  13. package/lib/constants/index.d.ts +3 -0
  14. package/lib/constants/index.js +26 -0
  15. package/lib/handlers/AlignmentHandler.d.ts +18 -18
  16. package/lib/handlers/AlignmentHandler.js +58 -58
  17. package/lib/handlers/AnimationHandler.d.ts +50 -48
  18. package/lib/handlers/AnimationHandler.js +323 -298
  19. package/lib/handlers/ChartHandler.d.ts +8 -8
  20. package/lib/handlers/ChartHandler.js +8 -8
  21. package/lib/handlers/ContextmenuHandler.d.ts +28 -23
  22. package/lib/handlers/ContextmenuHandler.js +65 -56
  23. package/lib/handlers/CropHandler.d.ts +43 -37
  24. package/lib/handlers/CropHandler.js +261 -243
  25. package/lib/handlers/CustomHandler.d.ts +7 -0
  26. package/lib/handlers/CustomHandler.js +10 -0
  27. package/lib/handlers/DrawingHandler.d.ts +28 -28
  28. package/lib/handlers/DrawingHandler.js +318 -318
  29. package/lib/handlers/ElementHandler.d.ts +80 -80
  30. package/lib/handlers/ElementHandler.js +154 -154
  31. package/lib/handlers/EventHandler.d.ts +170 -182
  32. package/lib/handlers/EventHandler.js +880 -904
  33. package/lib/handlers/FiberHandler.d.ts +6 -0
  34. package/lib/handlers/FiberHandler.js +23 -0
  35. package/lib/handlers/GridHandler.d.ts +19 -18
  36. package/lib/handlers/GridHandler.js +77 -76
  37. package/lib/handlers/GuidelineHandler.d.ts +61 -39
  38. package/lib/handlers/GuidelineHandler.js +315 -266
  39. package/lib/handlers/Handler.d.ts +622 -543
  40. package/lib/handlers/Handler.js +1638 -1510
  41. package/lib/handlers/ImageHandler.d.ts +307 -307
  42. package/lib/handlers/ImageHandler.js +529 -484
  43. package/lib/handlers/InteractionHandler.d.ts +45 -45
  44. package/lib/handlers/InteractionHandler.js +164 -159
  45. package/lib/handlers/LinkHandler.d.ts +115 -116
  46. package/lib/handlers/LinkHandler.js +247 -246
  47. package/lib/handlers/NodeHandler.d.ts +50 -50
  48. package/lib/handlers/NodeHandler.js +274 -274
  49. package/lib/handlers/PortHandler.d.ts +22 -22
  50. package/lib/handlers/PortHandler.js +179 -179
  51. package/lib/handlers/ShortcutHandler.d.ts +119 -119
  52. package/lib/handlers/ShortcutHandler.js +151 -150
  53. package/lib/handlers/TooltipHandler.d.ts +33 -24
  54. package/lib/handlers/TooltipHandler.js +91 -78
  55. package/lib/handlers/TransactionHandler.d.ts +59 -54
  56. package/lib/handlers/TransactionHandler.js +137 -132
  57. package/lib/handlers/WorkareaHandler.d.ts +43 -41
  58. package/lib/handlers/WorkareaHandler.js +354 -352
  59. package/lib/handlers/ZoomHandler.d.ts +48 -48
  60. package/lib/handlers/ZoomHandler.js +143 -143
  61. package/lib/handlers/index.d.ts +23 -21
  62. package/lib/handlers/index.js +48 -44
  63. package/lib/index.d.ts +6 -5
  64. package/lib/index.js +20 -19
  65. package/lib/objects/Arrow.d.ts +2 -2
  66. package/lib/objects/Arrow.js +40 -39
  67. package/lib/objects/Chart.d.ts +10 -10
  68. package/lib/objects/Chart.js +117 -116
  69. package/lib/objects/CirclePort.d.ts +2 -2
  70. package/lib/objects/CirclePort.js +28 -28
  71. package/lib/objects/Cube.d.ts +5 -5
  72. package/lib/objects/Cube.js +71 -71
  73. package/lib/objects/CurvedLink.d.ts +2 -2
  74. package/lib/objects/CurvedLink.js +51 -49
  75. package/lib/objects/Element.d.ts +13 -13
  76. package/lib/objects/Element.js +77 -76
  77. package/lib/objects/Gif.d.ts +3 -3
  78. package/lib/objects/Gif.js +41 -38
  79. package/lib/objects/Iframe.d.ts +9 -9
  80. package/lib/objects/Iframe.js +63 -62
  81. package/lib/objects/Line.d.ts +2 -2
  82. package/lib/objects/Line.js +24 -24
  83. package/lib/objects/Link.d.ts +15 -15
  84. package/lib/objects/Link.js +106 -104
  85. package/lib/objects/Node.d.ts +59 -59
  86. package/lib/objects/Node.js +271 -268
  87. package/lib/objects/OrthogonalLink.d.ts +2 -2
  88. package/lib/objects/OrthogonalLink.js +54 -52
  89. package/lib/objects/Port.d.ts +12 -12
  90. package/lib/objects/Port.js +28 -28
  91. package/lib/objects/Svg.d.ts +8 -0
  92. package/lib/objects/Svg.js +59 -0
  93. package/lib/objects/Video.d.ts +14 -14
  94. package/lib/objects/Video.js +113 -112
  95. package/lib/objects/index.d.ts +15 -14
  96. package/lib/objects/index.js +32 -30
  97. package/lib/utils/ObjectUtil.d.ts +407 -413
  98. package/lib/utils/ObjectUtil.js +13 -13
  99. package/lib/utils/index.d.ts +1 -1
  100. package/lib/utils/index.js +13 -13
  101. package/package.json +20 -17
@@ -25,6 +25,17 @@ object-assign
25
25
 
26
26
  /*! Fabric.js Copyright 2008-2015, Printio (Juriy Zaytsev, Maxim Chernyak) */
27
27
 
28
+ /*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
29
+
30
+ /**
31
+ * @license
32
+ * Lodash <https://lodash.com/>
33
+ * Copyright OpenJS Foundation and other contributors <https://openjsf.org/>
34
+ * Released under MIT license <https://lodash.com/license>
35
+ * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
36
+ * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
37
+ */
38
+
28
39
  /** @license React v0.19.1
29
40
  * scheduler.production.min.js
30
41
  *
@@ -34,7 +45,7 @@ object-assign
34
45
  * LICENSE file in the root directory of this source tree.
35
46
  */
36
47
 
37
- /** @license React v16.13.1
48
+ /** @license React v16.14.0
38
49
  * react-dom.production.min.js
39
50
  *
40
51
  * Copyright (c) Facebook, Inc. and its affiliates.
@@ -43,7 +54,7 @@ object-assign
43
54
  * LICENSE file in the root directory of this source tree.
44
55
  */
45
56
 
46
- /** @license React v16.13.1
57
+ /** @license React v16.14.0
47
58
  * react.production.min.js
48
59
  *
49
60
  * Copyright (c) Facebook, Inc. and its affiliates.
package/lib/Canvas.d.ts CHANGED
@@ -1,32 +1,18 @@
1
- import React, { Component } from 'react';
2
- import Handler, { HandlerOptions } from './handlers/Handler';
3
- import { FabricCanvas } from './utils';
4
- import '../../styles/core/canvas.less';
5
- import '../../styles/core/tooltip.less';
6
- import '../../styles/core/contextmenu.less';
7
- import '../../styles/fabricjs/fabricjs.less';
8
- export declare type CanvasProps = HandlerOptions & {
9
- responsive?: boolean;
10
- style?: React.CSSProperties;
11
- ref?: React.RefAttributes<Handler>;
12
- };
13
- interface IState {
14
- id: string;
15
- loaded: boolean;
16
- }
17
- declare class Canvas extends Component<CanvasProps, IState> {
18
- handler: Handler;
19
- canvas: FabricCanvas;
20
- container: React.RefObject<HTMLDivElement>;
21
- private resizeObserver;
22
- static defaultProps: CanvasProps;
23
- state: IState;
24
- componentDidMount(): void;
25
- componentDidUpdate(prevProps: CanvasProps): void;
26
- componentWillUnmount(): void;
27
- createObserver: () => void;
28
- cancelObserver: () => void;
29
- handleLoad: () => void;
30
- render(): JSX.Element;
31
- }
32
- export default Canvas;
1
+ import React from 'react';
2
+ import Handler, { HandlerOptions } from './handlers/Handler';
3
+ import { FabricCanvas } from './utils';
4
+ import '../styles/core/canvas.less';
5
+ import '../styles/core/tooltip.less';
6
+ import '../styles/core/contextmenu.less';
7
+ import '../styles/fabricjs/fabricjs.less';
8
+ export interface CanvasInstance {
9
+ handler: Handler;
10
+ canvas: FabricCanvas;
11
+ container: HTMLDivElement;
12
+ }
13
+ export declare type CanvasProps = HandlerOptions & {
14
+ responsive?: boolean;
15
+ style?: React.CSSProperties;
16
+ };
17
+ declare const Canvas: React.FC<CanvasProps>;
18
+ export default Canvas;
package/lib/Canvas.js CHANGED
@@ -1,245 +1,172 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
- Object.defineProperty(o, "default", { enumerable: true, value: v });
11
- }) : function(o, v) {
12
- o["default"] = v;
13
- });
14
- var __importStar = (this && this.__importStar) || function (mod) {
15
- if (mod && mod.__esModule) return mod;
16
- var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
- __setModuleDefault(result, mod);
19
- return result;
20
- };
21
- var __importDefault = (this && this.__importDefault) || function (mod) {
22
- return (mod && mod.__esModule) ? mod : { "default": mod };
23
- };
24
- Object.defineProperty(exports, "__esModule", { value: true });
25
- const react_1 = __importStar(require("react"));
26
- const fabric_1 = require("fabric");
27
- const uuid_1 = require("uuid");
28
- const resize_observer_polyfill_1 = __importDefault(require("resize-observer-polyfill"));
29
- const union_1 = __importDefault(require("lodash/union"));
30
- const Handler_1 = __importDefault(require("./handlers/Handler"));
31
- require("../../styles/core/canvas.less");
32
- require("../../styles/core/tooltip.less");
33
- require("../../styles/core/contextmenu.less");
34
- require("../../styles/fabricjs/fabricjs.less");
35
- const defaultCanvasOption = {
36
- preserveObjectStacking: true,
37
- width: 300,
38
- height: 150,
39
- selection: true,
40
- defaultCursor: 'default',
41
- backgroundColor: '#f3f3f3',
42
- };
43
- const defaultKeyboardEvent = {
44
- move: true,
45
- all: true,
46
- copy: true,
47
- paste: true,
48
- esc: true,
49
- del: true,
50
- clipboard: false,
51
- transaction: true,
52
- zoom: true,
53
- cut: true,
54
- };
55
- const defaultGripOption = {
56
- enabled: false,
57
- grid: 10,
58
- snapToGrid: false,
59
- lineColor: '#ebebeb',
60
- borderColor: '#cccccc',
61
- };
62
- const defaultWorkareaOption = {
63
- width: 600,
64
- height: 400,
65
- workareaWidth: 600,
66
- workareaHeight: 400,
67
- lockScalingX: true,
68
- lockScalingY: true,
69
- scaleX: 1,
70
- scaleY: 1,
71
- backgroundColor: '#fff',
72
- hasBorders: false,
73
- hasControls: false,
74
- selectable: false,
75
- lockMovementX: true,
76
- lockMovementY: true,
77
- hoverCursor: 'default',
78
- name: '',
79
- id: 'workarea',
80
- type: 'image',
81
- layout: 'fixed',
82
- link: {},
83
- tooltip: {
84
- enabled: false,
85
- },
86
- isElement: false,
87
- };
88
- const defaultPropertiesToInclude = ['id', 'name', 'locke', 'editable'];
89
- class Canvas extends react_1.Component {
90
- constructor() {
91
- super(...arguments);
92
- this.container = react_1.default.createRef();
93
- this.state = {
94
- id: uuid_1.v4(),
95
- loaded: false,
96
- };
97
- this.createObserver = () => {
98
- this.resizeObserver = new resize_observer_polyfill_1.default((entries) => {
99
- const { width = 0, height = 0 } = (entries[0] && entries[0].contentRect) || {};
100
- this.handler.eventHandler.resize(width, height);
101
- if (!this.state.loaded) {
102
- this.handleLoad();
103
- }
104
- });
105
- this.resizeObserver.observe(this.container.current);
106
- };
107
- this.cancelObserver = () => {
108
- if (this.resizeObserver) {
109
- this.resizeObserver.disconnect();
110
- }
111
- };
112
- this.handleLoad = () => {
113
- if (this.props.onLoad) {
114
- this.props.onLoad(this.handler, this.canvas);
115
- }
116
- this.setState({
117
- loaded: true,
118
- });
119
- };
120
- }
121
- componentDidMount() {
122
- const { editable, canvasOption, width, height, keyEvent, guidelineOption, defaultOption, responsive, propertiesToInclude, gridOption, workareaOption, ...other } = this.props;
123
- const { id } = this.state;
124
- const mergedPropertiesToInclude = union_1.default(propertiesToInclude, defaultPropertiesToInclude);
125
- const mergedCanvasOption = Object.assign({}, defaultCanvasOption, canvasOption, {
126
- width,
127
- height,
128
- selection: editable,
129
- });
130
- this.canvas = new fabric_1.fabric.Canvas(`canvas_${id}`, mergedCanvasOption);
131
- this.canvas.setBackgroundColor(mergedCanvasOption.backgroundColor, this.canvas.renderAll.bind(this.canvas));
132
- this.canvas.renderAll();
133
- this.handler = new Handler_1.default({
134
- id,
135
- canvas: this.canvas,
136
- container: this.container.current,
137
- keyEvent: Object.assign({}, defaultKeyboardEvent, keyEvent),
138
- canvasOption: mergedCanvasOption,
139
- guidelineOption,
140
- editable,
141
- defaultOption,
142
- propertiesToInclude: mergedPropertiesToInclude,
143
- gridOption: Object.assign({}, defaultGripOption, gridOption),
144
- width,
145
- height,
146
- workareaOption: Object.assign({}, defaultWorkareaOption, workareaOption),
147
- ...other,
148
- });
149
- if (this.props.responsive) {
150
- this.createObserver();
151
- }
152
- else {
153
- this.handleLoad();
154
- }
155
- }
156
- componentDidUpdate(prevProps) {
157
- if (JSON.stringify(this.props.canvasOption) !== JSON.stringify(prevProps.canvasOption)) {
158
- this.handler.canvasOption = this.props.canvasOption;
159
- this.handler.canvas.setBackgroundColor(this.props.canvasOption.backgroundColor, this.canvas.renderAll.bind(this.handler.canvas));
160
- const { canvasOption: { width: currentWidth, height: currentHeight }, } = this.props;
161
- const { canvasOption: { width: prevWidth, height: prevHeight }, } = prevProps;
162
- if (!this.props.responsive && (currentWidth !== prevWidth || currentHeight !== prevHeight)) {
163
- this.handler.eventHandler.resize(currentWidth, currentHeight);
164
- }
165
- if (typeof this.props.canvasOption.selection === 'undefined') {
166
- this.canvas.selection = true;
167
- }
168
- else {
169
- this.canvas.selection = this.props.canvasOption.selection;
170
- }
171
- }
172
- if (!this.props.responsive &&
173
- (this.props.width !== prevProps.width || this.props.height !== prevProps.height)) {
174
- this.handler.eventHandler.resize(this.props.width, this.props.height);
175
- }
176
- if (JSON.stringify(this.props.keyEvent) !== JSON.stringify(prevProps.keyEvent)) {
177
- this.handler.keyEvent = Object.assign({}, defaultKeyboardEvent, this.props.keyEvent);
178
- }
179
- if (JSON.stringify(this.props.fabricObjects) !== JSON.stringify(prevProps.fabricObjects)) {
180
- this.handler.fabricObjects = Object.assign({}, this.handler.fabricObjects, this.props.fabricObjects);
181
- }
182
- if (JSON.stringify(this.props.workareaOption) !== JSON.stringify(prevProps.workareaOption)) {
183
- this.handler.workarea.set({
184
- ...this.props.workareaOption,
185
- });
186
- }
187
- if (JSON.stringify(this.props.guidelineOption) !== JSON.stringify(prevProps.guidelineOption)) {
188
- if (this.props.guidelineOption.enabled) {
189
- this.canvas.on({
190
- 'before:render': this.handler.eventHandler.beforeRender,
191
- 'after:render': this.handler.eventHandler.afterRender,
192
- });
193
- }
194
- else {
195
- this.canvas.off({
196
- 'before:render': this.handler.eventHandler.beforeRender,
197
- 'after:render': this.handler.eventHandler.afterRender,
198
- });
199
- }
200
- }
201
- }
202
- componentWillUnmount() {
203
- this.handler.eventHandler.detachEventListener();
204
- this.cancelObserver();
205
- this.handler.clear(true);
206
- if (this.handler.tooltipHandler.tooltipEl) {
207
- document.body.removeChild(this.handler.tooltipHandler.tooltipEl);
208
- }
209
- if (this.handler.contextmenuHandler.contextmenuEl) {
210
- document.body.removeChild(this.handler.contextmenuHandler.contextmenuEl);
211
- }
212
- }
213
- render() {
214
- const { style } = this.props;
215
- const { id } = this.state;
216
- return (react_1.default.createElement("div", { ref: this.container, id: id, className: "rde-canvas", style: { width: '100%', height: '100%', ...style } },
217
- react_1.default.createElement("canvas", { id: `canvas_${id}` })));
218
- }
219
- }
220
- Canvas.defaultProps = {
221
- id: uuid_1.v4(),
222
- editable: true,
223
- canvasOption: {
224
- selection: true,
225
- },
226
- defaultOption: {},
227
- activeSelection: {
228
- hasControls: true,
229
- },
230
- tooltip: null,
231
- zoomEnabled: true,
232
- minZoom: 30,
233
- maxZoom: 300,
234
- propertiesToInclude: defaultPropertiesToInclude,
235
- workareaOption: defaultWorkareaOption,
236
- gridOption: defaultGripOption,
237
- guidelineOption: {
238
- enabled: true,
239
- },
240
- keyEvent: {},
241
- responsive: true,
242
- width: 0,
243
- height: 0,
244
- };
245
- exports.default = Canvas;
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ var __importDefault = (this && this.__importDefault) || function (mod) {
22
+ return (mod && mod.__esModule) ? mod : { "default": mod };
23
+ };
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ const react_1 = __importStar(require("react"));
26
+ const fabric_1 = require("fabric");
27
+ const resize_observer_polyfill_1 = __importDefault(require("resize-observer-polyfill"));
28
+ const Handler_1 = __importDefault(require("./handlers/Handler"));
29
+ const constants_1 = require("./constants");
30
+ const uuidv4_1 = require("uuidv4");
31
+ require("../styles/core/canvas.less");
32
+ require("../styles/core/tooltip.less");
33
+ require("../styles/core/contextmenu.less");
34
+ require("../styles/fabricjs/fabricjs.less");
35
+ class InternalCanvas extends react_1.Component {
36
+ constructor() {
37
+ super(...arguments);
38
+ this.containerRef = react_1.default.createRef();
39
+ this.state = {
40
+ id: uuidv4_1.uuid(),
41
+ loaded: false,
42
+ };
43
+ this.createObserver = () => {
44
+ this.resizeObserver = new resize_observer_polyfill_1.default((entries) => {
45
+ const { width = 0, height = 0 } = (entries[0] && entries[0].contentRect) || {};
46
+ this.handler.eventHandler.resize(width, height);
47
+ if (!this.state.loaded) {
48
+ this.handleLoad();
49
+ }
50
+ });
51
+ this.resizeObserver.observe(this.containerRef.current);
52
+ };
53
+ this.destroyObserver = () => {
54
+ if (this.resizeObserver) {
55
+ this.resizeObserver.disconnect();
56
+ this.resizeObserver = null;
57
+ }
58
+ };
59
+ this.handleLoad = () => {
60
+ this.setState({
61
+ loaded: true,
62
+ }, () => {
63
+ if (this.props.onLoad) {
64
+ this.props.onLoad(this.handler, this.canvas);
65
+ }
66
+ });
67
+ };
68
+ }
69
+ componentDidMount() {
70
+ const { editable, canvasOption, width, height, responsive, ...other } = this.props;
71
+ const { id } = this.state;
72
+ const mergedCanvasOption = Object.assign({}, constants_1.defaults.canvasOption, canvasOption, {
73
+ width,
74
+ height,
75
+ selection: editable,
76
+ });
77
+ this.canvas = new fabric_1.fabric.Canvas(`canvas_${id}`, mergedCanvasOption);
78
+ this.canvas.setBackgroundColor(mergedCanvasOption.backgroundColor, this.canvas.renderAll.bind(this.canvas));
79
+ this.canvas.renderAll();
80
+ this.container = this.containerRef.current;
81
+ this.handler = new Handler_1.default({
82
+ id,
83
+ width,
84
+ height,
85
+ editable,
86
+ canvas: this.canvas,
87
+ container: this.containerRef.current,
88
+ canvasOption: mergedCanvasOption,
89
+ ...other,
90
+ });
91
+ if (this.props.responsive) {
92
+ this.createObserver();
93
+ }
94
+ else {
95
+ this.handleLoad();
96
+ }
97
+ }
98
+ componentDidUpdate(prevProps) {
99
+ if (this.props.width !== prevProps.width || this.props.height !== prevProps.height) {
100
+ this.handler.eventHandler.resize(this.props.width, this.props.height);
101
+ }
102
+ if (this.props.editable !== prevProps.editable) {
103
+ this.handler.editable = this.props.editable;
104
+ }
105
+ if (this.props.responsive !== prevProps.responsive) {
106
+ if (!this.props.responsive) {
107
+ this.destroyObserver();
108
+ }
109
+ else {
110
+ this.destroyObserver();
111
+ this.createObserver();
112
+ }
113
+ }
114
+ if (JSON.stringify(this.props.canvasOption) !== JSON.stringify(prevProps.canvasOption)) {
115
+ this.handler.setCanvasOption(this.props.canvasOption);
116
+ }
117
+ if (JSON.stringify(this.props.keyEvent) !== JSON.stringify(prevProps.keyEvent)) {
118
+ this.handler.setKeyEvent(this.props.keyEvent);
119
+ }
120
+ if (JSON.stringify(this.props.fabricObjects) !== JSON.stringify(prevProps.fabricObjects)) {
121
+ this.handler.setFabricObjects(this.props.fabricObjects);
122
+ }
123
+ if (JSON.stringify(this.props.workareaOption) !== JSON.stringify(prevProps.workareaOption)) {
124
+ this.handler.setWorkareaOption(this.props.workareaOption);
125
+ }
126
+ if (JSON.stringify(this.props.guidelineOption) !== JSON.stringify(prevProps.guidelineOption)) {
127
+ this.handler.setGuidelineOption(this.props.guidelineOption);
128
+ }
129
+ if (JSON.stringify(this.props.objectOption) !== JSON.stringify(prevProps.objectOption)) {
130
+ this.handler.setObjectOption(this.props.objectOption);
131
+ }
132
+ if (JSON.stringify(this.props.gridOption) !== JSON.stringify(prevProps.gridOption)) {
133
+ this.handler.setGridOption(this.props.gridOption);
134
+ }
135
+ if (JSON.stringify(this.props.propertiesToInclude) !== JSON.stringify(prevProps.propertiesToInclude)) {
136
+ this.handler.setPropertiesToInclude(this.props.propertiesToInclude);
137
+ }
138
+ if (JSON.stringify(this.props.activeSelectionOption) !== JSON.stringify(prevProps.activeSelectionOption)) {
139
+ this.handler.setActiveSelectionOption(this.props.activeSelectionOption);
140
+ }
141
+ }
142
+ componentWillUnmount() {
143
+ this.destroyObserver();
144
+ this.handler.destroy();
145
+ }
146
+ render() {
147
+ const { style } = this.props;
148
+ const { id } = this.state;
149
+ return (react_1.default.createElement("div", { ref: this.containerRef, id: id, className: "rde-canvas", style: { width: '100%', height: '100%', ...style } },
150
+ react_1.default.createElement("canvas", { id: `canvas_${id}` })));
151
+ }
152
+ }
153
+ InternalCanvas.defaultProps = {
154
+ id: uuidv4_1.uuid(),
155
+ editable: true,
156
+ zoomEnabled: true,
157
+ minZoom: 30,
158
+ maxZoom: 300,
159
+ responsive: true,
160
+ width: 0,
161
+ height: 0,
162
+ };
163
+ const Canvas = react_1.default.forwardRef((props, ref) => {
164
+ const canvasRef = react_1.useRef();
165
+ react_1.default.useImperativeHandle(ref, () => ({
166
+ handler: canvasRef.current.handler,
167
+ canvas: canvasRef.current.canvas,
168
+ container: canvasRef.current.container,
169
+ }));
170
+ return react_1.default.createElement(InternalCanvas, Object.assign({ ref: canvasRef }, props));
171
+ });
172
+ exports.default = Canvas;
@@ -1,10 +1,10 @@
1
- import { fabric } from 'fabric';
2
- export interface ObjectSchema {
3
- create: (...option: any) => fabric.Object;
4
- }
5
- export interface CanvasObjectSchema {
6
- [key: string]: ObjectSchema;
7
- }
8
- export declare const createCanvasObject: (objectSchema: CanvasObjectSchema) => CanvasObjectSchema;
9
- declare const CanvasObject: CanvasObjectSchema;
10
- export default CanvasObject;
1
+ import { fabric } from 'fabric';
2
+ export interface ObjectSchema {
3
+ create: (...option: any) => fabric.Object;
4
+ }
5
+ export interface CanvasObjectSchema {
6
+ [key: string]: ObjectSchema;
7
+ }
8
+ export declare const createCanvasObject: (objectSchema: CanvasObjectSchema) => CanvasObjectSchema;
9
+ declare const CanvasObject: CanvasObjectSchema;
10
+ export default CanvasObject;