@yorab/react-paint 0.6.6 → 0.7.1

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 (64) hide show
  1. package/README.md +3 -5
  2. package/dist/components/App.js +30 -57
  3. package/dist/components/Canvas.js +31 -40
  4. package/dist/components/common/Button.js +4 -4
  5. package/dist/components/common/Loading.js +8 -5
  6. package/dist/components/common/Modal.js +3 -3
  7. package/dist/components/common/Panel.js +7 -11
  8. package/dist/components/common/Snackbar.js +6 -6
  9. package/dist/components/settings/ColorField.js +3 -3
  10. package/dist/components/settings/FontFamilyField.js +1 -1
  11. package/dist/components/settings/Layouts.js +36 -26
  12. package/dist/components/settings/LineArrowField.js +3 -3
  13. package/dist/components/settings/LineTypeField.js +2 -2
  14. package/dist/components/settings/RangeField.js +1 -1
  15. package/dist/components/settings/SelectField.js +1 -1
  16. package/dist/components/settings/SettingsBar.js +9 -7
  17. package/dist/components/toolbox/EditTextBox.js +11 -9
  18. package/dist/components/toolbox/MenuGroup.js +9 -7
  19. package/dist/components/toolbox/Toolbar.js +7 -9
  20. package/dist/components/toolbox/ToolbarGroup.js +24 -11
  21. package/dist/constants/app.js +51 -0
  22. package/dist/constants/icons.js +2 -8
  23. package/dist/constants/loading.js +8 -0
  24. package/dist/constants/shapes.js +4 -2
  25. package/dist/constants/snackbar.js +6 -14
  26. package/dist/constants/style.js +12 -9
  27. package/dist/constants/tools.js +20 -24
  28. package/dist/hooks/useComponent.js +3 -1
  29. package/dist/hooks/useDrawableCanvas.js +35 -37
  30. package/dist/hooks/useKeyboard.js +60 -33
  31. package/dist/hooks/useShapes.js +2 -2
  32. package/dist/styles.css +16 -13
  33. package/dist/types/Mode.js +1 -13
  34. package/dist/types/Shapes.js +1 -17
  35. package/dist/types/snackbar.js +5 -0
  36. package/dist/types/tools.js +1 -18
  37. package/dist/utils/canvas.js +49 -0
  38. package/dist/utils/data.js +5 -248
  39. package/dist/utils/dom.js +12 -0
  40. package/dist/utils/file.js +12 -7
  41. package/dist/utils/intersect.js +29 -66
  42. package/dist/utils/migration.js +59 -0
  43. package/dist/utils/selection.js +9 -11
  44. package/dist/utils/shapes/brush.js +135 -0
  45. package/dist/utils/shapes/circle.js +93 -0
  46. package/dist/utils/shapes/curve.js +55 -0
  47. package/dist/utils/shapes/default.js +73 -0
  48. package/dist/utils/shapes/ellipse.js +101 -0
  49. package/dist/utils/shapes/grid.js +36 -0
  50. package/dist/utils/shapes/index.js +341 -0
  51. package/dist/utils/shapes/line.js +179 -0
  52. package/dist/utils/shapes/picture.js +88 -0
  53. package/dist/utils/shapes/polygon.js +69 -0
  54. package/dist/utils/shapes/rectangle.js +100 -0
  55. package/dist/utils/shapes/text.js +128 -0
  56. package/dist/utils/shapes/triangle.js +24 -0
  57. package/dist/utils/style.js +10 -12
  58. package/dist/utils/toolbar.js +9 -11
  59. package/dist/utils/transform.js +25 -261
  60. package/dist/utils/trigo.js +42 -0
  61. package/package.json +7 -8
  62. package/dist/types/keyboard.js +0 -28
  63. package/dist/utils/draw.js +0 -431
  64. package/dist/utils/shapeData.js +0 -155
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.STYLE_ZINDEX_SNACKBAR = exports.STYLE_ZINDEX_PANEL = exports.STYLE_ZINDEX_LOADING = exports.STYLE_ZINDEX_APP = exports.STYLE_LINE_WITH_ARROW = exports.STYLE_LINE_DASH = exports.STYLE_FONT_SIZE_DEFAULT = exports.STYLE_FONT_DEFAULT = exports.STYLE_FONTS = exports.STYLE_COLORS = exports.POLYGON_POINTS_VALUES = exports.LINE_DASH_DATA = exports.CURVE_POINTS_VALUES = void 0;
6
+ exports.STYLE_ZINDEX = exports.STYLE_LINE_WITH_ARROW = exports.STYLE_LINE_DASH = exports.STYLE_FONT_SIZE_DEFAULT = exports.STYLE_FONT_DEFAULT = exports.STYLE_FONTS = exports.STYLE_COLORS = exports.POLYGON_POINTS_VALUES = exports.LINE_DASH_DATA = exports.GRID_STEP = exports.GRID_ROTATION_STEPS = exports.CURVE_POINTS_VALUES = void 0;
7
7
  const POLYGON_POINTS_VALUES = [3, 4, 5, 6, 7, 8, 9, 10];
8
8
  exports.POLYGON_POINTS_VALUES = POLYGON_POINTS_VALUES;
9
9
  const CURVE_POINTS_VALUES = [3, 4, 5, 6, 7, 8, 9];
@@ -22,11 +22,14 @@ const STYLE_FONT_DEFAULT = 'serif';
22
22
  exports.STYLE_FONT_DEFAULT = STYLE_FONT_DEFAULT;
23
23
  const STYLE_FONT_SIZE_DEFAULT = 36;
24
24
  exports.STYLE_FONT_SIZE_DEFAULT = STYLE_FONT_SIZE_DEFAULT;
25
- const STYLE_ZINDEX_APP = 1;
26
- exports.STYLE_ZINDEX_APP = STYLE_ZINDEX_APP;
27
- const STYLE_ZINDEX_LOADING = 2;
28
- exports.STYLE_ZINDEX_LOADING = STYLE_ZINDEX_LOADING;
29
- const STYLE_ZINDEX_PANEL = 3;
30
- exports.STYLE_ZINDEX_PANEL = STYLE_ZINDEX_PANEL;
31
- const STYLE_ZINDEX_SNACKBAR = 4;
32
- exports.STYLE_ZINDEX_SNACKBAR = STYLE_ZINDEX_SNACKBAR;
25
+ const STYLE_ZINDEX = {
26
+ APP: 1,
27
+ LOADING: 2,
28
+ PANEL: 3,
29
+ SNACKBAR: 4
30
+ };
31
+ exports.STYLE_ZINDEX = STYLE_ZINDEX;
32
+ const GRID_STEP = [10, 20, 40];
33
+ exports.GRID_STEP = GRID_STEP;
34
+ const GRID_ROTATION_STEPS = 18;
35
+ exports.GRID_ROTATION_STEPS = GRID_ROTATION_STEPS;
@@ -5,10 +5,6 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.UPLOAD_PICTURE_TOOL = exports.UNDO_TOOL = exports.SETTINGS_DEFAULT_TEXT = exports.SETTINGS_DEFAULT_SQUARE = exports.SETTINGS_DEFAULT_RECT = exports.SETTINGS_DEFAULT_POLYGON = exports.SETTINGS_DEFAULT_PICTURE = exports.SETTINGS_DEFAULT_LINE = exports.SETTINGS_DEFAULT_ELLIPSE = exports.SETTINGS_DEFAULT_CURVE = exports.SETTINGS_DEFAULT_CIRCLE = exports.SETTINGS_DEFAULT_BRUSH = exports.SELECTION_TOOL = exports.SAVE_TOOL = exports.REDO_TOOL = exports.MOVE_TOOL = exports.LOAD_TOOL = exports.EXPORT_TOOL = exports.DEFAULT_SHAPE_TOOLS = exports.DEFAULT_SHAPE_TEXT = exports.DEFAULT_SHAPE_SQUARE = exports.DEFAULT_SHAPE_RECT = exports.DEFAULT_SHAPE_POLYGON = exports.DEFAULT_SHAPE_PICTURE = exports.DEFAULT_SHAPE_LINE = exports.DEFAULT_SHAPE_ELLIPSE = exports.DEFAULT_SHAPE_CURVE = exports.DEFAULT_SHAPE_CIRCLE = exports.DEFAULT_SHAPE_BRUSH = exports.CLEAR_TOOL = exports.ADD_URL_PICTURE_TOOL = void 0;
7
7
 
8
- var _Shapes = require("../types/Shapes");
9
-
10
- var _tools = require("../types/tools");
11
-
12
8
  var _icons = require("./icons");
13
9
 
14
10
  var _style = require("./style");
@@ -273,7 +269,7 @@ const SETTINGS_DEFAULT_CURVE = {
273
269
  };
274
270
  exports.SETTINGS_DEFAULT_CURVE = SETTINGS_DEFAULT_CURVE;
275
271
  const DEFAULT_SHAPE_PICTURE = {
276
- type: _Shapes.ShapeEnum.picture,
272
+ type: 'picture',
277
273
  id: "".concat(PREFIX_ID, "picture"),
278
274
  icon: _icons.pictureIcon,
279
275
  label: 'Image',
@@ -281,7 +277,7 @@ const DEFAULT_SHAPE_PICTURE = {
281
277
  };
282
278
  exports.DEFAULT_SHAPE_PICTURE = DEFAULT_SHAPE_PICTURE;
283
279
  const DEFAULT_SHAPE_BRUSH = {
284
- type: _Shapes.ShapeEnum.brush,
280
+ type: 'brush',
285
281
  id: "".concat(PREFIX_ID, "brush"),
286
282
  icon: _icons.brushIcon,
287
283
  label: 'Brosse',
@@ -289,7 +285,7 @@ const DEFAULT_SHAPE_BRUSH = {
289
285
  };
290
286
  exports.DEFAULT_SHAPE_BRUSH = DEFAULT_SHAPE_BRUSH;
291
287
  const DEFAULT_SHAPE_LINE = {
292
- type: _Shapes.ShapeEnum.line,
288
+ type: 'line',
293
289
  id: "".concat(PREFIX_ID, "line"),
294
290
  icon: _icons.arrowIcon,
295
291
  label: 'Ligne',
@@ -297,7 +293,7 @@ const DEFAULT_SHAPE_LINE = {
297
293
  };
298
294
  exports.DEFAULT_SHAPE_LINE = DEFAULT_SHAPE_LINE;
299
295
  const DEFAULT_SHAPE_POLYGON = {
300
- type: _Shapes.ShapeEnum.polygon,
296
+ type: 'polygon',
301
297
  id: "".concat(PREFIX_ID, "polygon"),
302
298
  icon: _icons.polygonIcon,
303
299
  label: 'Polygone',
@@ -305,7 +301,7 @@ const DEFAULT_SHAPE_POLYGON = {
305
301
  };
306
302
  exports.DEFAULT_SHAPE_POLYGON = DEFAULT_SHAPE_POLYGON;
307
303
  const DEFAULT_SHAPE_CURVE = {
308
- type: _Shapes.ShapeEnum.curve,
304
+ type: 'curve',
309
305
  id: "".concat(PREFIX_ID, "curve"),
310
306
  icon: _icons.curveIcon,
311
307
  label: 'Courbe',
@@ -313,7 +309,7 @@ const DEFAULT_SHAPE_CURVE = {
313
309
  };
314
310
  exports.DEFAULT_SHAPE_CURVE = DEFAULT_SHAPE_CURVE;
315
311
  const DEFAULT_SHAPE_RECT = {
316
- type: _Shapes.ShapeEnum.rect,
312
+ type: 'rect',
317
313
  id: "".concat(PREFIX_ID, "rect"),
318
314
  icon: _icons.squareIcon,
319
315
  // temporary
@@ -322,7 +318,7 @@ const DEFAULT_SHAPE_RECT = {
322
318
  };
323
319
  exports.DEFAULT_SHAPE_RECT = DEFAULT_SHAPE_RECT;
324
320
  const DEFAULT_SHAPE_SQUARE = {
325
- type: _Shapes.ShapeEnum.square,
321
+ type: 'square',
326
322
  id: "".concat(PREFIX_ID, "square"),
327
323
  icon: _icons.squareIcon,
328
324
  label: 'Carré',
@@ -330,7 +326,7 @@ const DEFAULT_SHAPE_SQUARE = {
330
326
  };
331
327
  exports.DEFAULT_SHAPE_SQUARE = DEFAULT_SHAPE_SQUARE;
332
328
  const DEFAULT_SHAPE_CIRCLE = {
333
- type: _Shapes.ShapeEnum.circle,
329
+ type: 'circle',
334
330
  id: "".concat(PREFIX_ID, "circle"),
335
331
  icon: _icons.circleIcon,
336
332
  label: 'Cercle',
@@ -338,7 +334,7 @@ const DEFAULT_SHAPE_CIRCLE = {
338
334
  };
339
335
  exports.DEFAULT_SHAPE_CIRCLE = DEFAULT_SHAPE_CIRCLE;
340
336
  const DEFAULT_SHAPE_ELLIPSE = {
341
- type: _Shapes.ShapeEnum.ellipse,
337
+ type: 'ellipse',
342
338
  id: "".concat(PREFIX_ID, "ellipse"),
343
339
  icon: _icons.circleIcon,
344
340
  // temporary
@@ -347,7 +343,7 @@ const DEFAULT_SHAPE_ELLIPSE = {
347
343
  };
348
344
  exports.DEFAULT_SHAPE_ELLIPSE = DEFAULT_SHAPE_ELLIPSE;
349
345
  const DEFAULT_SHAPE_TEXT = {
350
- type: _Shapes.ShapeEnum.text,
346
+ type: 'text',
351
347
  id: "".concat(PREFIX_ID, "text"),
352
348
  icon: _icons.textIcon,
353
349
  label: 'Texte',
@@ -358,70 +354,70 @@ const DEFAULT_SHAPE_TOOLS = [DEFAULT_SHAPE_BRUSH, DEFAULT_SHAPE_LINE, DEFAULT_SH
358
354
  exports.DEFAULT_SHAPE_TOOLS = DEFAULT_SHAPE_TOOLS;
359
355
  const SELECTION_TOOL = {
360
356
  id: "".concat(PREFIX_ID, "selection"),
361
- type: _tools.ActionsEnum.selection,
357
+ type: 'selection',
362
358
  icon: _icons.cursorIcon,
363
359
  label: 'Sélection'
364
360
  };
365
361
  exports.SELECTION_TOOL = SELECTION_TOOL;
366
362
  const UNDO_TOOL = {
367
363
  id: "".concat(PREFIX_ID, "undo"),
368
- type: _tools.ActionsEnum.undo,
364
+ type: 'undo',
369
365
  icon: _icons.undoIcon,
370
366
  label: 'Undo'
371
367
  };
372
368
  exports.UNDO_TOOL = UNDO_TOOL;
373
369
  const REDO_TOOL = {
374
370
  id: "".concat(PREFIX_ID, "redo"),
375
- type: _tools.ActionsEnum.redo,
371
+ type: 'redo',
376
372
  icon: _icons.redoIcon,
377
373
  label: 'Redo'
378
374
  };
379
375
  exports.REDO_TOOL = REDO_TOOL;
380
376
  const CLEAR_TOOL = {
381
377
  id: "".concat(PREFIX_ID, "clear"),
382
- type: _tools.ActionsEnum.clear,
378
+ type: 'clear',
383
379
  icon: _icons.clearIcon,
384
380
  label: 'Clear'
385
381
  };
386
382
  exports.CLEAR_TOOL = CLEAR_TOOL;
387
383
  const EXPORT_TOOL = {
388
384
  id: "".concat(PREFIX_ID, "export"),
389
- type: _tools.ActionsEnum.export,
385
+ type: 'export',
390
386
  icon: _icons.exportFileIcon,
391
387
  label: 'Export PNG'
392
388
  };
393
389
  exports.EXPORT_TOOL = EXPORT_TOOL;
394
390
  const LOAD_TOOL = {
395
391
  id: "".concat(PREFIX_ID, "load"),
396
- type: _tools.ActionsEnum.loadFile,
392
+ type: 'loadfile',
397
393
  icon: _icons.openFileIcon,
398
394
  label: 'Load project'
399
395
  };
400
396
  exports.LOAD_TOOL = LOAD_TOOL;
401
397
  const SAVE_TOOL = {
402
398
  id: "".concat(PREFIX_ID, "save"),
403
- type: _tools.ActionsEnum.saveFile,
399
+ type: 'savefile',
404
400
  icon: _icons.saveIcon,
405
401
  label: 'Save project'
406
402
  };
407
403
  exports.SAVE_TOOL = SAVE_TOOL;
408
404
  const MOVE_TOOL = {
409
405
  id: "".concat(PREFIX_ID, "move"),
410
- type: _tools.ActionsEnum.move,
406
+ type: 'move',
411
407
  icon: _icons.cursorIcon,
412
408
  label: 'Move'
413
409
  };
414
410
  exports.MOVE_TOOL = MOVE_TOOL;
415
411
  const UPLOAD_PICTURE_TOOL = {
416
412
  id: "".concat(PREFIX_ID, "upload-picture"),
417
- type: _tools.ActionsEnum.uploadPicture,
413
+ type: 'uploadpicture',
418
414
  icon: _icons.pictureIcon,
419
415
  label: 'Upload picture'
420
416
  };
421
417
  exports.UPLOAD_PICTURE_TOOL = UPLOAD_PICTURE_TOOL;
422
418
  const ADD_URL_PICTURE_TOOL = {
423
419
  id: "".concat(PREFIX_ID, "upload-picture"),
424
- type: _tools.ActionsEnum.addUrlPicture,
420
+ type: 'addurlpicture',
425
421
  icon: _icons.pictureIcon,
426
422
  label: 'Add picture from URL'
427
423
  };
@@ -7,6 +7,8 @@ exports.default = void 0;
7
7
 
8
8
  var _react = require("react");
9
9
 
10
+ var _dom = require("../utils/dom");
11
+
10
12
  const useComponent = _ref => {
11
13
  let {
12
14
  disabled,
@@ -15,7 +17,7 @@ const useComponent = _ref => {
15
17
  const [isInsideComponent, setIsInsideComponent] = (0, _react.useState)(false);
16
18
  (0, _react.useEffect)(() => {
17
19
  const onDetectClick = event => {
18
- setIsInsideComponent(!(event.target instanceof Node) || !componentRef.current ? false : componentRef.current.contains(event.target));
20
+ setIsInsideComponent((0, _dom.isEventInsideNode)(event, componentRef.current));
19
21
  };
20
22
 
21
23
  if (disabled) {
@@ -9,28 +9,24 @@ exports.default = void 0;
9
9
 
10
10
  var _react = require("react");
11
11
 
12
- var _fp = _interopRequireDefault(require("lodash/fp"));
13
-
14
12
  var _selection = require("../utils/selection");
15
13
 
16
- var _Shapes = require("../types/Shapes");
17
-
18
14
  var _intersect = require("../utils/intersect");
19
15
 
20
- var _Mode = require("../types/Mode");
21
-
22
16
  var _transform = require("../utils/transform");
23
17
 
24
- var _data = require("../utils/data");
18
+ var _tools = require("../constants/tools");
25
19
 
26
- var _tools = require("../types/tools");
20
+ var _useDoubleClick = _interopRequireDefault(require("./useDoubleClick"));
27
21
 
28
- var _tools2 = require("../constants/tools");
22
+ var _shapes = require("../constants/shapes");
29
23
 
30
- var _useDoubleClick = _interopRequireDefault(require("./useDoubleClick"));
24
+ var _shapes2 = require("../utils/shapes");
25
+
26
+ var _brush = require("../utils/shapes/brush");
31
27
 
32
- const handleMove = (e, canvasRef, activeTool, canvasOffset, selectedShape, selectionMode, canvasOffsetStartPosition, width, height, scaleRatio, setHoverMode, updateSingleShape, setCanvasOffset, setSelectedShape, selectionPadding) => {
33
- if (activeTool.type === _tools.ActionsEnum.move && canvasOffsetStartPosition !== undefined) {
28
+ const handleMove = (e, canvasRef, activeTool, gridFormat, canvasOffset, selectedShape, selectionMode, canvasOffsetStartPosition, width, height, scaleRatio, setHoverMode, updateSingleShape, setCanvasOffset, setSelectedShape, selectionPadding, isShiftPressed) => {
29
+ if (activeTool.type === 'move' && canvasOffsetStartPosition !== undefined) {
34
30
  const cursorPosition = (0, _intersect.getCursorPosition)(e, canvasRef.current, width, height, scaleRatio);
35
31
  setCanvasOffset([cursorPosition[0] - canvasOffsetStartPosition[0], cursorPosition[1] - canvasOffsetStartPosition[1]]);
36
32
  }
@@ -39,9 +35,9 @@ const handleMove = (e, canvasRef, activeTool, canvasOffset, selectedShape, selec
39
35
  if (selectedShape.locked) return;
40
36
  const cursorPosition = (0, _intersect.getCursorPosition)(e, canvasRef.current, width, height, scaleRatio);
41
37
 
42
- if (selectionMode.mode === _Mode.SelectionModeLib.default || selectionMode.mode === _Mode.SelectionModeLib.textedition) {
38
+ if (selectionMode.mode === 'default' || selectionMode.mode === 'textedition') {
43
39
  const positionIntersection = (0, _intersect.checkPositionIntersection)(selectedShape, cursorPosition, canvasOffset, selectionPadding, scaleRatio, true) || {
44
- mode: _Mode.SelectionModeLib.default
40
+ mode: 'default'
45
41
  };
46
42
  setHoverMode(positionIntersection);
47
43
  } else {
@@ -49,7 +45,7 @@ const handleMove = (e, canvasRef, activeTool, canvasOffset, selectedShape, selec
49
45
 
50
46
  const ctx = (_canvasRef$current = canvasRef.current) === null || _canvasRef$current === void 0 ? void 0 : _canvasRef$current.getContext('2d');
51
47
  if (!ctx) return;
52
- const newShape = (0, _transform.transformShape)(ctx, selectedShape, cursorPosition, canvasOffset, selectionMode, selectionPadding);
48
+ const newShape = (0, _transform.transformShape)(ctx, selectedShape, cursorPosition, gridFormat, canvasOffset, selectionMode, selectionPadding, isShiftPressed);
53
49
  updateSingleShape(newShape);
54
50
  setSelectedShape(newShape);
55
51
  }
@@ -73,10 +69,12 @@ const useDrawableCanvas = _ref => {
73
69
  setSelectedShape,
74
70
  setCanvasOffsetStartPosition,
75
71
  updateSingleShape,
72
+ gridFormat,
76
73
  canvasOffset,
77
74
  saveShapes,
78
75
  setSelectionMode,
79
- selectionPadding
76
+ selectionPadding,
77
+ isShiftPressed
80
78
  } = _ref;
81
79
  const {
82
80
  width,
@@ -84,14 +82,14 @@ const useDrawableCanvas = _ref => {
84
82
  scaleRatio
85
83
  } = canvasSize;
86
84
  const [hoverMode, setHoverMode] = (0, _react.useState)({
87
- mode: _Mode.SelectionModeLib.default
85
+ mode: 'default'
88
86
  });
89
87
  const {
90
88
  registerDoubleClickEvent,
91
89
  unRegisterDoubleClickEvent
92
90
  } = (0, _useDoubleClick.default)();
93
91
  (0, _react.useEffect)(() => {
94
- const handleMouseMove = e => window.requestAnimationFrame(() => handleMove(e, selectionCanvasRef, activeTool, canvasOffset, selectedShape, selectionMode, canvasOffsetStartPosition, width, height, scaleRatio, setHoverMode, updateSingleShape, setCanvasOffset, setSelectedShape, selectionPadding));
92
+ const handleMouseMove = e => window.requestAnimationFrame(() => handleMove(e, selectionCanvasRef, activeTool, gridFormat, canvasOffset, selectedShape, selectionMode, canvasOffsetStartPosition, width, height, scaleRatio, setHoverMode, updateSingleShape, setCanvasOffset, setSelectedShape, selectionPadding, isShiftPressed));
95
93
 
96
94
  if (isInsideComponent) {
97
95
  document.addEventListener('mousemove', handleMouseMove);
@@ -104,14 +102,14 @@ const useDrawableCanvas = _ref => {
104
102
  document.removeEventListener('touchmove', handleMouseMove);
105
103
  }
106
104
  };
107
- }, [isInsideComponent, selectionCanvasRef, selectedShape, selectionMode, setHoverMode, canvasOffset, canvasOffsetStartPosition, width, height, scaleRatio, updateSingleShape, activeTool, setCanvasOffset, setSelectedShape, selectionPadding]);
105
+ }, [isInsideComponent, selectionCanvasRef, selectedShape, selectionMode, setHoverMode, gridFormat, canvasOffset, canvasOffsetStartPosition, width, height, scaleRatio, updateSingleShape, activeTool, setCanvasOffset, setSelectedShape, selectionPadding, isShiftPressed]);
108
106
  (0, _react.useEffect)(() => {
109
107
  const handleMouseUp = () => {
110
- if (selectionMode.mode === _Mode.SelectionModeLib.textedition) return;
108
+ if (selectionMode.mode === 'textedition') return;
111
109
 
112
- if (selectionMode.mode !== _Mode.SelectionModeLib.default) {
110
+ if (selectionMode.mode !== 'default') {
113
111
  setSelectionMode({
114
- mode: _Mode.SelectionModeLib.default
112
+ mode: 'default'
115
113
  });
116
114
  saveShapes();
117
115
  }
@@ -138,49 +136,49 @@ const useDrawableCanvas = _ref => {
138
136
  e.preventDefault();
139
137
  const cursorPosition = (0, _intersect.getCursorPosition)(e, selectionCanvasRef.current, width, height, scaleRatio);
140
138
 
141
- if (activeTool.type === _tools.ActionsEnum.selection) {
139
+ if (activeTool.type === 'selection') {
142
140
  const {
143
141
  shape,
144
142
  mode
145
143
  } = (0, _selection.selectShape)(shapes, cursorPosition, scaleRatio, canvasOffset, selectedShape, selectionPadding);
146
144
  setSelectedShape(shape);
147
145
  setSelectionMode(mode);
148
- } else if (activeTool.type === _tools.ActionsEnum.move) {
146
+ } else if (activeTool.type === 'move') {
149
147
  setCanvasOffsetStartPosition(cursorPosition);
150
148
  }
151
149
 
152
- if (_fp.default.includes(activeTool.type, _Shapes.ShapeEnum)) {
150
+ if (_shapes.ShapeTypeArray.includes(activeTool.type)) {
153
151
  var _drawCanvasRef$curren;
154
152
 
155
153
  const drawCtx = (_drawCanvasRef$curren = drawCanvasRef.current) === null || _drawCanvasRef$curren === void 0 ? void 0 : _drawCanvasRef$curren.getContext('2d');
156
154
  if (!drawCtx) return;
157
155
 
158
- if (activeTool.type === _Shapes.ShapeEnum.brush) {
156
+ if (activeTool.type === 'brush') {
159
157
  if (!!selectedShape) {
160
- const newShape = (0, _transform.createNewPointGroupToShape)(selectedShape, cursorPosition);
158
+ const newShape = (0, _brush.addNewPointGroupToShape)(selectedShape, cursorPosition);
161
159
  updateSingleShape(newShape);
162
160
  setSelectedShape(newShape);
163
161
  } else {
164
- const newShape = (0, _data.createShape)(drawCtx, activeTool, cursorPosition);
162
+ const newShape = (0, _shapes2.createShape)(drawCtx, activeTool, cursorPosition, gridFormat);
165
163
  if (!newShape) return;
166
164
  addShape(newShape);
167
165
  setSelectedShape(newShape);
168
166
  }
169
167
 
170
168
  setSelectionMode({
171
- mode: _Mode.SelectionModeLib.brush
169
+ mode: 'brush'
172
170
  });
173
171
  } else {
174
- const newShape = (0, _data.createShape)(drawCtx, activeTool, cursorPosition);
172
+ const newShape = (0, _shapes2.createShape)(drawCtx, activeTool, cursorPosition, gridFormat);
175
173
  if (!newShape) return;
176
174
  addShape(newShape);
177
- setActiveTool(_tools2.SELECTION_TOOL);
175
+ setActiveTool(_tools.SELECTION_TOOL);
178
176
  setSelectedShape(newShape);
179
177
  setSelectionMode({
180
- mode: _Mode.SelectionModeLib.resize,
178
+ mode: 'resize',
181
179
  cursorStartPosition: cursorPosition,
182
180
  originalShape: newShape,
183
- anchor: activeTool.type === _Shapes.ShapeEnum.line || activeTool.type === _Shapes.ShapeEnum.polygon || activeTool.type === _Shapes.ShapeEnum.curve ? 0 : [1, 1]
181
+ anchor: activeTool.type === 'line' || activeTool.type === 'polygon' || activeTool.type === 'curve' ? 0 : [1, 1]
184
182
  });
185
183
  }
186
184
  }
@@ -196,19 +194,19 @@ const useDrawableCanvas = _ref => {
196
194
  ref.removeEventListener('mousedown', handleMouseDown);
197
195
  ref.removeEventListener('touchstart', handleMouseDown);
198
196
  };
199
- }, [disabled, selectionCanvasRef, drawCanvasRef, selectedShape, activeTool, canvasOffset, setCanvasOffsetStartPosition, shapes, width, height, scaleRatio, updateSingleShape, addShape, setActiveTool, setSelectedShape, setSelectionMode, selectionPadding]);
197
+ }, [disabled, selectionCanvasRef, drawCanvasRef, selectedShape, activeTool, canvasOffset, setCanvasOffsetStartPosition, shapes, width, height, scaleRatio, updateSingleShape, addShape, setActiveTool, setSelectedShape, setSelectionMode, selectionPadding, gridFormat]);
200
198
  (0, _react.useEffect)(() => {
201
199
  const ref = selectionCanvasRef.current;
202
200
  if (!ref) return;
203
201
 
204
202
  const handleDoubleClick = e => {
205
- if (activeTool.type === _tools.ActionsEnum.selection) {
206
- if ((selectedShape === null || selectedShape === void 0 ? void 0 : selectedShape.type) === _Shapes.ShapeEnum.text) {
203
+ if (activeTool.type === 'selection') {
204
+ if ((selectedShape === null || selectedShape === void 0 ? void 0 : selectedShape.type) === 'text') {
207
205
  const cursorPosition = (0, _intersect.getCursorPosition)(e, selectionCanvasRef.current, width, height, scaleRatio);
208
206
 
209
207
  if ((0, _intersect.checkPositionIntersection)(selectedShape, cursorPosition, canvasOffset, selectionPadding)) {
210
208
  setSelectionMode({
211
- mode: _Mode.SelectionModeLib.textedition,
209
+ mode: 'textedition',
212
210
  defaultValue: selectedShape.value
213
211
  });
214
212
  }
@@ -1,22 +1,36 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
3
  Object.defineProperty(exports, "__esModule", {
6
4
  value: true
7
5
  });
8
6
  exports.default = void 0;
9
7
 
10
- var _react = require("react");
11
-
12
- var _fp = _interopRequireDefault(require("lodash/fp"));
8
+ var _style = require("../constants/style");
13
9
 
14
- var _data = require("../utils/data");
10
+ var _react = require("react");
15
11
 
16
- var _keyboard = require("../types/keyboard");
12
+ var _shapes = require("../utils/shapes");
13
+
14
+ const KeyboardCode = {
15
+ ArrowUp: 'ArrowUp',
16
+ ArrowDown: 'ArrowDown',
17
+ ArrowLeft: 'ArrowLeft',
18
+ ArrowRight: 'ArrowRight',
19
+ Delete: 'Delete',
20
+ Backspace: 'Backspace',
21
+ Escape: 'Escape',
22
+ Shift: 'Shift',
23
+ Z: 'z',
24
+ Y: 'y'
25
+ };
26
+ const KeyboardCommand = {
27
+ Copy: 'copy',
28
+ Paste: 'paste'
29
+ };
17
30
 
18
31
  const useKeyboard = _ref => {
19
32
  let {
33
+ gridFormat,
20
34
  isInsideComponent,
21
35
  selectedShape,
22
36
  isEditingText,
@@ -25,7 +39,8 @@ const useKeyboard = _ref => {
25
39
  pasteShape,
26
40
  updateShape,
27
41
  backwardShape,
28
- forwardShape
42
+ forwardShape,
43
+ setShiftPressed
29
44
  } = _ref;
30
45
  const [copiedShape, setCopiedShape] = (0, _react.useState)(undefined);
31
46
  (0, _react.useEffect)(() => {
@@ -41,17 +56,25 @@ const useKeyboard = _ref => {
41
56
  if (!copiedShape) return;
42
57
  if (isEditingText) return;
43
58
  e.preventDefault();
44
- pasteShape((0, _data.copyShape)(copiedShape));
59
+ pasteShape((0, _shapes.copyShape)(copiedShape, gridFormat));
60
+ };
61
+
62
+ const handleKeyUp = e => {
63
+ switch (e.key) {
64
+ case KeyboardCode.Shift:
65
+ setShiftPressed(false);
66
+ break;
67
+ }
45
68
  };
46
69
 
47
70
  const handleKeyDown = e => {
48
71
  if (e.metaKey || e.ctrlKey) {
49
- if (e.key === _keyboard.KeyboardCode.Z) {
72
+ if (e.key === KeyboardCode.Z) {
50
73
  e.preventDefault();
51
74
  e.stopPropagation();
52
75
  backwardShape();
53
76
  return;
54
- } else if (e.key === _keyboard.KeyboardCode.Y) {
77
+ } else if (e.key === KeyboardCode.Y) {
55
78
  e.preventDefault();
56
79
  e.stopPropagation();
57
80
  forwardShape();
@@ -59,34 +82,36 @@ const useKeyboard = _ref => {
59
82
  }
60
83
  }
61
84
 
85
+ if (e.key === KeyboardCode.Shift) {
86
+ setShiftPressed(true);
87
+ return;
88
+ }
89
+
62
90
  if (!selectedShape) return;
63
91
 
64
- if (e.key === _keyboard.KeyboardCode.Escape) {
92
+ if (e.key === KeyboardCode.Escape) {
65
93
  setSelectedShape(undefined);
66
94
  return;
67
95
  }
68
96
 
69
97
  if (isEditingText) return;
98
+ const translationMap = {
99
+ [KeyboardCode.ArrowLeft]: [gridFormat ? -_style.GRID_STEP[gridFormat - 1] : -1, 0],
100
+ [KeyboardCode.ArrowRight]: [gridFormat ? _style.GRID_STEP[gridFormat - 1] : 1, 0],
101
+ [KeyboardCode.ArrowDown]: [0, gridFormat ? _style.GRID_STEP[gridFormat - 1] : 1],
102
+ [KeyboardCode.ArrowUp]: [0, gridFormat ? -_style.GRID_STEP[gridFormat - 1] : -1]
103
+ };
70
104
 
71
105
  switch (e.key) {
72
- case _keyboard.KeyboardCode.ArrowLeft:
73
- updateShape(_fp.default.set('translation', [selectedShape.translation[0] - 1, selectedShape.translation[1]], selectedShape));
74
- break;
75
-
76
- case _keyboard.KeyboardCode.ArrowRight:
77
- updateShape(_fp.default.set('translation', [selectedShape.translation[0] + 1, selectedShape.translation[1]], selectedShape));
78
- break;
79
-
80
- case _keyboard.KeyboardCode.ArrowDown:
81
- updateShape(_fp.default.set('translation', [selectedShape.translation[0], selectedShape.translation[1] + 1], selectedShape));
82
- break;
83
-
84
- case _keyboard.KeyboardCode.ArrowUp:
85
- updateShape(_fp.default.set('translation', [selectedShape.translation[0], selectedShape.translation[1] - 1], selectedShape));
106
+ case KeyboardCode.ArrowLeft:
107
+ case KeyboardCode.ArrowRight:
108
+ case KeyboardCode.ArrowDown:
109
+ case KeyboardCode.ArrowUp:
110
+ updateShape((0, _shapes.translateShape)(translationMap[e.key], selectedShape, [0, 0], gridFormat));
86
111
  break;
87
112
 
88
- case _keyboard.KeyboardCode.Delete:
89
- case _keyboard.KeyboardCode.Backspace:
113
+ case KeyboardCode.Delete:
114
+ case KeyboardCode.Backspace:
90
115
  removeShape(selectedShape);
91
116
  break;
92
117
  }
@@ -94,18 +119,20 @@ const useKeyboard = _ref => {
94
119
 
95
120
  if (isInsideComponent) {
96
121
  document.addEventListener('keydown', handleKeyDown);
97
- document.addEventListener(_keyboard.KeyboardCommand.Copy, handleCopy);
98
- document.addEventListener(_keyboard.KeyboardCommand.Paste, handlePaste);
122
+ document.addEventListener('keyup', handleKeyUp);
123
+ document.addEventListener(KeyboardCommand.Copy, handleCopy);
124
+ document.addEventListener(KeyboardCommand.Paste, handlePaste);
99
125
  }
100
126
 
101
127
  return () => {
102
128
  if (isInsideComponent) {
103
129
  document.removeEventListener('keydown', handleKeyDown);
104
- document.removeEventListener(_keyboard.KeyboardCommand.Copy, handleCopy);
105
- document.removeEventListener(_keyboard.KeyboardCommand.Paste, handlePaste);
130
+ document.removeEventListener('keyup', handleKeyUp);
131
+ document.removeEventListener(KeyboardCommand.Copy, handleCopy);
132
+ document.removeEventListener(KeyboardCommand.Paste, handlePaste);
106
133
  }
107
134
  };
108
- }, [isInsideComponent, copiedShape, isEditingText, selectedShape, updateShape, removeShape, setSelectedShape, pasteShape, backwardShape, forwardShape]);
135
+ }, [isInsideComponent, gridFormat, copiedShape, isEditingText, selectedShape, updateShape, removeShape, setSelectedShape, pasteShape, backwardShape, forwardShape, setShiftPressed]);
109
136
  return {};
110
137
  };
111
138
 
@@ -11,7 +11,7 @@ var _react = require("react");
11
11
 
12
12
  var _fp = _interopRequireDefault(require("lodash/fp"));
13
13
 
14
- var _data = require("../utils/data");
14
+ var _picture = require("../utils/shapes/picture");
15
15
 
16
16
  const useShapes = function () {
17
17
  let onDataChanged = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _fp.default.noop;
@@ -46,7 +46,7 @@ const useShapes = function () {
46
46
  const addPictureShape = (0, _react.useCallback)(async function (fileOrUrl) {
47
47
  let maxWidth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 300;
48
48
  let maxHeight = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 300;
49
- const pictureShape = await (0, _data.createPicture)(fileOrUrl, maxWidth, maxHeight);
49
+ const pictureShape = await (0, _picture.createPicture)(fileOrUrl, maxWidth, maxHeight);
50
50
  addShape(pictureShape);
51
51
  saveShapes();
52
52
  return pictureShape;