@yorab/react-paint 0.3.0 → 0.4.0

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.
package/Changelog.md CHANGED
@@ -1,3 +1,15 @@
1
+ # V.0.4.0
2
+
3
+ - Add possibility to customize UI from props
4
+
5
+ # V.0.3.1
6
+
7
+ - Add prop to change canvas background color
8
+ - Move some props to options
9
+ - fix Picture shape not being saved and not triggering onDataChanged
10
+ - small picture are upscaled to fit container when imported
11
+ - Add prop to choose to display save/load/export
12
+
1
13
  # V.0.3.0 :
2
14
 
3
15
  - prevent picture from url submit to reload page
package/README.md CHANGED
@@ -1,9 +1,9 @@
1
1
  # known issues :
2
2
 
3
- ## critical
3
+ ## To resolve before beta release
4
4
 
5
5
  - Text tool broken since 0.2.2
6
- - double click not working with touch (fix: fake it countinng delay between touch)
6
+ - double click not working with touch (fix: fake it counting delay between touch)
7
7
 
8
8
  ## mobile/touch
9
9
 
@@ -11,6 +11,8 @@
11
11
 
12
12
  ## other
13
13
 
14
- - TextEdit cursor overflow MINOR (quick fix : edit on modale)
15
- - TextEdit copy/paste contains html and breaks display
14
+ - TextEdit cursor overflow MINOR (quick fix : edit on modale ?)
15
+ - TextEdit copy/paste containing html breaks display
16
16
  - circle resizing only goes one direction
17
+ - New text component opacity range is dancing
18
+ - adding padding to selection result in wrong intersection calculs
@@ -57,6 +57,8 @@ var _data = require("../utils/data");
57
57
 
58
58
  var _useResizeObserver = _interopRequireDefault(require("../hooks/useResizeObserver"));
59
59
 
60
+ var _shapes = require("../constants/shapes");
61
+
60
62
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
61
63
 
62
64
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
@@ -69,13 +71,49 @@ var StyledApp = /*#__PURE__*/(0, _react2.styled)("div")({
69
71
  name: "StyledApp",
70
72
  "class": "s1v9piyg",
71
73
  vars: {
72
- "s1v9piyg-0": [function (_ref) {
73
- var canvaswidth = _ref.canvaswidth;
74
- return "min(100%, ".concat(canvaswidth, "px)");
74
+ "s1v9piyg-0": [function (props) {
75
+ return props.toolbarBackgroundColor;
76
+ }],
77
+ "s1v9piyg-1": [function (props) {
78
+ return props.dividerColor;
79
+ }],
80
+ "s1v9piyg-2": [function (props) {
81
+ return props.fontRadius;
82
+ }, "px"],
83
+ "s1v9piyg-3": [function (props) {
84
+ return props.fontDisabledColor;
85
+ }],
86
+ "s1v9piyg-4": [function (props) {
87
+ return props.fontDisabledBackgroundColor;
88
+ }],
89
+ "s1v9piyg-5": [function (props) {
90
+ return props.fontColor;
91
+ }],
92
+ "s1v9piyg-6": [function (props) {
93
+ return props.fontBackgroundColor;
94
+ }],
95
+ "s1v9piyg-7": [function (props) {
96
+ return props.fontSelectedColor;
75
97
  }],
76
- "s1v9piyg-1": [function (_ref2) {
77
- var canvaswidth = _ref2.canvaswidth;
78
- return canvaswidth;
98
+ "s1v9piyg-8": [function (props) {
99
+ return props.fontSelectedBackgroundColor;
100
+ }],
101
+ "s1v9piyg-9": [function (props) {
102
+ return props.fontHoverColor;
103
+ }],
104
+ "s1v9piyg-10": [function (props) {
105
+ return props.fontHoverBackgroundColor;
106
+ }],
107
+ "s1v9piyg-11": [function (props) {
108
+ return props.canvasBackgroundColor;
109
+ }],
110
+ "s1v9piyg-12": [function (_ref) {
111
+ var canvasWidth = _ref.canvasWidth;
112
+ return "min(100%, ".concat(canvasWidth, "px)");
113
+ }],
114
+ "s1v9piyg-13": [function (_ref2) {
115
+ var canvasWidth = _ref2.canvasWidth;
116
+ return canvasWidth;
79
117
  }, "px"]
80
118
  }
81
119
  });
@@ -96,18 +134,38 @@ var StyledRow = /*#__PURE__*/(0, _react2.styled)("div")({
96
134
  var DEFAULT_TOOLS = [_Shapes.ShapeEnum.brush, _Shapes.ShapeEnum.line, _Shapes.ShapeEnum.polygon, _Shapes.ShapeEnum.curve, _Shapes.ShapeEnum.rect, _Shapes.ShapeEnum.square, _Shapes.ShapeEnum.circle, _Shapes.ShapeEnum.ellipse, _Shapes.ShapeEnum.text, _Shapes.ShapeEnum.picture];
97
135
  var DEFAULT_OPTIONS = {
98
136
  layersManipulation: true,
99
- gridVisible: false
137
+ gridVisible: false,
138
+ canGrow: false,
139
+ canShrink: true,
140
+ withExport: true,
141
+ withLoadAndSave: true,
142
+ availableTools: DEFAULT_TOOLS,
143
+ uiStyle: {
144
+ toolbarBackgroundColor: 'white',
145
+ dividerColor: '#36418129',
146
+ fontRadius: 8,
147
+ fontDisabledColor: '#3641812b',
148
+ fontDisabledBackgroundColor: 'transparent',
149
+ fontColor: '#364181',
150
+ fontBackgroundColor: 'transparent',
151
+ fontSelectedColor: 'white',
152
+ fontSelectedBackgroundColor: '#364181',
153
+ fontHoverColor: '#364181',
154
+ fontHoverBackgroundColor: '#afd8d8',
155
+ canvasBackgroundColor: 'white',
156
+ canvasSelectionColor: _shapes.SELECTION_DEFAULT_COLOR,
157
+ canvasSelectionWidth: _shapes.SELECTION_DEFAULT_WIDTH,
158
+ canvasSelectionPadding: _shapes.SELECTION_DEFAULT_PADDING
159
+ }
100
160
  };
101
161
 
102
162
  var App = function App(_ref5) {
163
+ var _options$uiStyle;
164
+
103
165
  var _ref5$width = _ref5.width,
104
166
  canvasWidth = _ref5$width === void 0 ? 1000 : _ref5$width,
105
167
  _ref5$height = _ref5.height,
106
168
  canvasHeight = _ref5$height === void 0 ? 600 : _ref5$height,
107
- _ref5$canGrow = _ref5.canGrow,
108
- canGrow = _ref5$canGrow === void 0 ? false : _ref5$canGrow,
109
- _ref5$canShrink = _ref5.canShrink,
110
- canShrink = _ref5$canShrink === void 0 ? true : _ref5$canShrink,
111
169
  shapesFromProps = _ref5.shapes,
112
170
  classNameFromProps = _ref5.className,
113
171
  _ref5$mode = _ref5.mode,
@@ -115,14 +173,34 @@ var App = function App(_ref5) {
115
173
  _ref5$disabled = _ref5.disabled,
116
174
  disabledFromProps = _ref5$disabled === void 0 ? false : _ref5$disabled,
117
175
  onDataChanged = _ref5.onDataChanged,
118
- _ref5$availableTools = _ref5.availableTools,
119
- availableToolsFromProps = _ref5$availableTools === void 0 ? DEFAULT_TOOLS : _ref5$availableTools,
120
176
  apiRef = _ref5.apiRef,
121
177
  options = _ref5.options;
122
178
 
123
179
  var _DEFAULT_OPTIONS$opti = _objectSpread(_objectSpread({}, DEFAULT_OPTIONS), options),
124
180
  layersManipulation = _DEFAULT_OPTIONS$opti.layersManipulation,
125
- gridVisible = _DEFAULT_OPTIONS$opti.gridVisible;
181
+ gridVisible = _DEFAULT_OPTIONS$opti.gridVisible,
182
+ canGrow = _DEFAULT_OPTIONS$opti.canGrow,
183
+ canShrink = _DEFAULT_OPTIONS$opti.canShrink,
184
+ withExport = _DEFAULT_OPTIONS$opti.withExport,
185
+ withLoadAndSave = _DEFAULT_OPTIONS$opti.withLoadAndSave,
186
+ availableToolsFromProps = _DEFAULT_OPTIONS$opti.availableTools;
187
+
188
+ var _DEFAULT_OPTIONS$uiSt = _objectSpread(_objectSpread({}, DEFAULT_OPTIONS.uiStyle), (_options$uiStyle = options === null || options === void 0 ? void 0 : options.uiStyle) !== null && _options$uiStyle !== void 0 ? _options$uiStyle : {}),
189
+ toolbarBackgroundColor = _DEFAULT_OPTIONS$uiSt.toolbarBackgroundColor,
190
+ dividerColor = _DEFAULT_OPTIONS$uiSt.dividerColor,
191
+ fontRadius = _DEFAULT_OPTIONS$uiSt.fontRadius,
192
+ fontDisabledColor = _DEFAULT_OPTIONS$uiSt.fontDisabledColor,
193
+ fontDisabledBackgroundColor = _DEFAULT_OPTIONS$uiSt.fontDisabledBackgroundColor,
194
+ fontColor = _DEFAULT_OPTIONS$uiSt.fontColor,
195
+ fontBackgroundColor = _DEFAULT_OPTIONS$uiSt.fontBackgroundColor,
196
+ fontSelectedColor = _DEFAULT_OPTIONS$uiSt.fontSelectedColor,
197
+ fontSelectedBackgroundColor = _DEFAULT_OPTIONS$uiSt.fontSelectedBackgroundColor,
198
+ fontHoverColor = _DEFAULT_OPTIONS$uiSt.fontHoverColor,
199
+ fontHoverBackgroundColor = _DEFAULT_OPTIONS$uiSt.fontHoverBackgroundColor,
200
+ canvasBackgroundColor = _DEFAULT_OPTIONS$uiSt.canvasBackgroundColor,
201
+ canvasSelectionColor = _DEFAULT_OPTIONS$uiSt.canvasSelectionColor,
202
+ canvasSelectionWidth = _DEFAULT_OPTIONS$uiSt.canvasSelectionWidth,
203
+ canvasSelectionPadding = _DEFAULT_OPTIONS$uiSt.canvasSelectionPadding;
126
204
 
127
205
  var isEditMode = mode !== 'viewer';
128
206
  var disabled = disabledFromProps || !isEditMode;
@@ -253,7 +331,7 @@ var App = function App(_ref5) {
253
331
  setIsLoading(true);
254
332
 
255
333
  try {
256
- var dataURL = canvasRef.current && (0, _file.getCanvasImage)(shapesRef.current, canvasOffset, canvasWidth, canvasHeight);
334
+ var dataURL = canvasRef.current && (0, _file.getCanvasImage)(shapesRef.current, canvasOffset, canvasWidth, canvasHeight, canvasSelectionPadding);
257
335
 
258
336
  if (!dataURL) {
259
337
  throw new Error();
@@ -273,7 +351,7 @@ var App = function App(_ref5) {
273
351
  } finally {
274
352
  setIsLoading(false);
275
353
  }
276
- }, [addSnackbar, shapesRef, canvasOffset, canvasWidth, canvasHeight]);
354
+ }, [addSnackbar, shapesRef, canvasOffset, canvasWidth, canvasHeight, canvasSelectionPadding]);
277
355
  var saveFile = (0, _react.useCallback)(function () {
278
356
  setIsLoading(true);
279
357
 
@@ -463,20 +541,32 @@ var App = function App(_ref5) {
463
541
  if (!apiRef) return;
464
542
  apiRef.current = {
465
543
  getCurrentImage: function getCurrentImage() {
466
- return canvasRef.current ? (0, _file.getCanvasImage)(shapesRef.current, canvasOffset, canvasWidth, canvasHeight) : undefined;
544
+ return canvasRef.current ? (0, _file.getCanvasImage)(shapesRef.current, canvasOffset, canvasWidth, canvasHeight, canvasSelectionPadding) : undefined;
467
545
  },
468
546
  getCurrentData: function getCurrentData() {
469
547
  return (0, _data.cleanShapesBeforeExport)(shapesRef.current); //TODO : create different types for stored shapes
470
548
  }
471
549
  };
472
- }, [apiRef, shapesRef, canvasOffset, canvasWidth, canvasHeight]);
550
+ }, [apiRef, shapesRef, canvasOffset, canvasWidth, canvasHeight, canvasSelectionPadding]);
473
551
  var className = "".concat(classNameFromProps !== null && classNameFromProps !== void 0 ? classNameFromProps : '', " ").concat(isLayoutPanelShown ? 'layoutPanelOpened' : '');
474
552
  return /*#__PURE__*/_react["default"].createElement(StyledApp, {
475
553
  ref: componentRef,
476
554
  className: className,
477
- canvaswidth: canvasWidth,
478
555
  "data-grow": canGrow,
479
- "data-shrink": canShrink
556
+ "data-shrink": canShrink,
557
+ canvasWidth: canvasWidth,
558
+ toolbarBackgroundColor: toolbarBackgroundColor,
559
+ dividerColor: dividerColor,
560
+ fontRadius: fontRadius,
561
+ fontDisabledColor: fontDisabledColor,
562
+ fontDisabledBackgroundColor: fontDisabledBackgroundColor,
563
+ fontColor: fontColor,
564
+ fontBackgroundColor: fontBackgroundColor,
565
+ fontSelectedColor: fontSelectedColor,
566
+ fontSelectedBackgroundColor: fontSelectedBackgroundColor,
567
+ fontHoverColor: fontHoverColor,
568
+ fontHoverBackgroundColor: fontHoverBackgroundColor,
569
+ canvasBackgroundColor: canvasBackgroundColor
480
570
  }, isEditMode && /*#__PURE__*/_react["default"].createElement(_Toolbar["default"], {
481
571
  disabled: disabled,
482
572
  activeTool: activeTool,
@@ -491,7 +581,9 @@ var App = function App(_ref5) {
491
581
  hasActionToClear: canClear,
492
582
  undoAction: undoAction,
493
583
  redoAction: redoAction,
494
- availableTools: availableTools
584
+ availableTools: availableTools,
585
+ withExport: withExport,
586
+ withLoadAndSave: withLoadAndSave
495
587
  }), /*#__PURE__*/_react["default"].createElement(StyledRow, {
496
588
  "data-grow": canGrow,
497
589
  width: canvasSize.width,
@@ -517,7 +609,10 @@ var App = function App(_ref5) {
517
609
  ref: canvasRef,
518
610
  canvasSize: canvasSize,
519
611
  selectionMode: selectionMode,
520
- setSelectionMode: setSelectionMode
612
+ setSelectionMode: setSelectionMode,
613
+ selectionColor: canvasSelectionColor,
614
+ selectionWidth: canvasSelectionWidth,
615
+ selectionPadding: canvasSelectionPadding
521
616
  }), isEditMode && layersManipulation && /*#__PURE__*/_react["default"].createElement(_Layouts["default"], {
522
617
  withGrid: withGrid,
523
618
  setWithGrid: setWithGrid,
@@ -39,7 +39,7 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
39
39
 
40
40
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
41
41
 
42
- var drawCanvas = function drawCanvas(drawCtx, selectionCtx, selectionMode, canvasSize, activeTool, canvasOffset, shapes, selectedShape) {
42
+ var drawCanvas = function drawCanvas(drawCtx, selectionCtx, selectionMode, canvasSize, activeTool, canvasOffset, shapes, selectionPadding, selectionWidth, selectionColor, selectedShape) {
43
43
  var width = canvasSize.width,
44
44
  height = canvasSize.height,
45
45
  scaleRatio = canvasSize.scaleRatio;
@@ -48,7 +48,7 @@ var drawCanvas = function drawCanvas(drawCtx, selectionCtx, selectionMode, canva
48
48
 
49
49
  for (var i = shapes.length - 1; i >= 0; i--) {
50
50
  if (selectionMode.mode !== _Mode.SelectionModeLib.textedition || shapes[i] !== selectedShape) {
51
- (0, _draw.drawShape)(drawCtx, shapes[i], scaleRatio, canvasOffset);
51
+ (0, _draw.drawShape)(drawCtx, shapes[i], scaleRatio, canvasOffset, selectionPadding);
52
52
  }
53
53
  }
54
54
 
@@ -57,6 +57,9 @@ var drawCanvas = function drawCanvas(drawCtx, selectionCtx, selectionMode, canva
57
57
  shape: selectedShape,
58
58
  scaleRatio: scaleRatio,
59
59
  canvasOffset: canvasOffset,
60
+ selectionPadding: selectionPadding,
61
+ selectionWidth: selectionWidth,
62
+ selectionColor: selectionColor,
60
63
  withAnchors: selectionMode.mode !== _Mode.SelectionModeLib.textedition
61
64
  });
62
65
  };
@@ -105,7 +108,10 @@ var Canvas = /*#__PURE__*/_react["default"].forwardRef(function (_ref2, ref) {
105
108
  defaultConf = _ref2.defaultConf,
106
109
  isInsideComponent = _ref2.isInsideComponent,
107
110
  selectionMode = _ref2.selectionMode,
108
- setSelectionMode = _ref2.setSelectionMode;
111
+ setSelectionMode = _ref2.setSelectionMode,
112
+ selectionWidth = _ref2.selectionWidth,
113
+ selectionColor = _ref2.selectionColor,
114
+ selectionPadding = _ref2.selectionPadding;
109
115
  var drawCanvasRef = (0, _react.useRef)(null);
110
116
  var selectionCanvasRef = (0, _react.useRef)(null); // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
111
117
 
@@ -133,7 +139,8 @@ var Canvas = /*#__PURE__*/_react["default"].forwardRef(function (_ref2, ref) {
133
139
  updateSingleShape: updateSingleShape,
134
140
  canvasOffset: canvasOffset,
135
141
  saveShapes: saveShapes,
136
- setSelectionMode: setSelectionMode
142
+ setSelectionMode: setSelectionMode,
143
+ selectionPadding: selectionPadding
137
144
  }),
138
145
  hoverMode = _useDrawableCanvas.hoverMode;
139
146
 
@@ -161,9 +168,9 @@ var Canvas = /*#__PURE__*/_react["default"].forwardRef(function (_ref2, ref) {
161
168
  var drawCtx = (_drawCanvasRef$curren2 = drawCanvasRef.current) === null || _drawCanvasRef$curren2 === void 0 ? void 0 : _drawCanvasRef$curren2.getContext('2d');
162
169
  var selectionCtx = (_selectionCanvasRef$c = selectionCanvasRef.current) === null || _selectionCanvasRef$c === void 0 ? void 0 : _selectionCanvasRef$c.getContext('2d');
163
170
  drawCtx && selectionCtx && window.requestAnimationFrame(function () {
164
- return drawCanvas(drawCtx, selectionCtx, selectionMode, canvasSize, activeTool, canvasOffset, shapes, selectedShape);
171
+ return drawCanvas(drawCtx, selectionCtx, selectionMode, canvasSize, activeTool, canvasOffset, shapes, selectionPadding, selectionWidth, selectionColor, selectedShape);
165
172
  });
166
- }, [shapes, selectionMode, selectedShape, activeTool, canvasOffset, canvasSize]);
173
+ }, [shapes, selectionMode, selectedShape, activeTool, canvasOffset, canvasSize, selectionPadding, selectionWidth, selectionColor]);
167
174
  return /*#__PURE__*/_react["default"].createElement(StyledCanvasBox, null, /*#__PURE__*/_react["default"].createElement(StyledCanvasContainer, {
168
175
  "data-grid": withGrid,
169
176
  "data-grow": canGrow
@@ -183,7 +190,8 @@ var Canvas = /*#__PURE__*/_react["default"].forwardRef(function (_ref2, ref) {
183
190
  disabled: disabled,
184
191
  shape: selectedShape,
185
192
  defaultValue: selectionMode.defaultValue,
186
- updateValue: updateSelectedShapeText
193
+ updateValue: updateSelectedShapeText,
194
+ selectionPadding: selectionPadding
187
195
  })));
188
196
  });
189
197
 
@@ -38,25 +38,30 @@ var StyledEditBox = /*#__PURE__*/(0, _react2.styled)("div")({
38
38
  return color;
39
39
  }],
40
40
  "s1unz6yq-2": [function (_ref3) {
41
- var fontsize = _ref3.fontsize;
41
+ var padding = _ref3.padding;
42
+ return padding;
43
+ }, "px"],
44
+ "s1unz6yq-3": [function (_ref4) {
45
+ var fontsize = _ref4.fontsize;
42
46
  return fontsize;
43
47
  }, "px"],
44
- "s1unz6yq-4": [function (_ref4) {
45
- var fontfamily = _ref4.fontfamily;
48
+ "s1unz6yq-5": [function (_ref5) {
49
+ var fontfamily = _ref5.fontfamily;
46
50
  return fontfamily;
47
51
  }]
48
52
  }
49
53
  });
50
54
 
51
- var EditTextBox = function EditTextBox(_ref5) {
55
+ var EditTextBox = function EditTextBox(_ref6) {
52
56
  var _shape$style$strokeCo, _shape$style, _shape$style$fontFami, _shape$style2;
53
57
 
54
- var _ref5$disabled = _ref5.disabled,
55
- disabled = _ref5$disabled === void 0 ? false : _ref5$disabled,
56
- scaleRatio = _ref5.scaleRatio,
57
- shape = _ref5.shape,
58
- defaultValue = _ref5.defaultValue,
59
- updateValue = _ref5.updateValue;
58
+ var _ref6$disabled = _ref6.disabled,
59
+ disabled = _ref6$disabled === void 0 ? false : _ref6$disabled,
60
+ scaleRatio = _ref6.scaleRatio,
61
+ shape = _ref6.shape,
62
+ defaultValue = _ref6.defaultValue,
63
+ updateValue = _ref6.updateValue,
64
+ selectionPadding = _ref6.selectionPadding;
60
65
  var ref = (0, _react.useRef)(null);
61
66
 
62
67
  var updateContentEditable = function updateContentEditable(e) {
@@ -69,16 +74,17 @@ var EditTextBox = function EditTextBox(_ref5) {
69
74
  ref.current.focus();
70
75
  }, [defaultValue]);
71
76
  var position = (0, _react.useMemo)(function () {
72
- var _getShapeInfos = (0, _shapeData.getShapeInfos)(shape),
77
+ var _getShapeInfos = (0, _shapeData.getShapeInfos)(shape, selectionPadding),
73
78
  borders = _getShapeInfos.borders,
74
79
  center = _getShapeInfos.center;
75
80
 
76
81
  return (0, _intersect.getPointPositionBeforeCanvasTransformation)([borders.x, borders.y], [-shape.translation[0], -shape.translation[1]], shape.rotation, center);
77
- }, [shape]);
82
+ }, [shape, selectionPadding]);
78
83
  return /*#__PURE__*/_react["default"].createElement(StyledEditBox, {
79
84
  ref: ref,
80
85
  transform: "translate3D(".concat(position[0] * scaleRatio, "px, ").concat(position[1] * scaleRatio, "px, 0) rotate(").concat((0, _transform.radiansToDegrees)(shape.rotation), "deg)"),
81
86
  fontsize: shape.fontSize * scaleRatio,
87
+ padding: selectionPadding * scaleRatio,
82
88
  color: (_shape$style$strokeCo = (_shape$style = shape.style) === null || _shape$style === void 0 ? void 0 : _shape$style.strokeColor) !== null && _shape$style$strokeCo !== void 0 ? _shape$style$strokeCo : 'inherit',
83
89
  fontfamily: (_shape$style$fontFami = (_shape$style2 = shape.style) === null || _shape$style2 === void 0 ? void 0 : _shape$style2.fontFamily) !== null && _shape$style$fontFami !== void 0 ? _shape$style$fontFami : _style.STYLE_FONT_DEFAULT,
84
90
  contentEditable: !disabled,
@@ -58,6 +58,8 @@ var MenuGroup = function MenuGroup(_ref) {
58
58
  vertical = _ref$vertical === void 0 ? false : _ref$vertical,
59
59
  _ref$disabled = _ref.disabled,
60
60
  disabled = _ref$disabled === void 0 ? false : _ref$disabled,
61
+ withLoadAndSave = _ref.withLoadAndSave,
62
+ withExport = _ref.withExport,
61
63
  addPictureFromProps = _ref.addPicture,
62
64
  loadFileFromProps = _ref.loadFile,
63
65
  togglePictureUrlModal = _ref.togglePictureUrlModal,
@@ -121,7 +123,12 @@ var MenuGroup = function MenuGroup(_ref) {
121
123
  document.removeEventListener('click', closePanel);
122
124
  };
123
125
  }, [isOpen]);
124
- return /*#__PURE__*/_react["default"].createElement(StyledRelative, null, /*#__PURE__*/_react["default"].createElement(_Button["default"], {
126
+
127
+ var withPicture = _fp["default"].includes(_Shapes.ShapeEnum.picture, availableTools);
128
+
129
+ var withDivider = withPicture && (withLoadAndSave || withExport);
130
+ var withMenu = withPicture || withLoadAndSave || withExport;
131
+ return withMenu ? /*#__PURE__*/_react["default"].createElement(StyledRelative, null, /*#__PURE__*/_react["default"].createElement(_Button["default"], {
125
132
  selected: isActive,
126
133
  title: group.title,
127
134
  disabled: disabled,
@@ -130,7 +137,7 @@ var MenuGroup = function MenuGroup(_ref) {
130
137
  }), isOpen && /*#__PURE__*/_react["default"].createElement(StyledPanel, {
131
138
  vertical: vertical,
132
139
  alignment: alignment
133
- }, _fp["default"].includes(_Shapes.ShapeEnum.picture, availableTools) && /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_LoadFileTool["default"], {
140
+ }, withPicture && /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_LoadFileTool["default"], {
134
141
  withText: true,
135
142
  disabled: disabled,
136
143
  loadFile: addPicture,
@@ -144,7 +151,7 @@ var MenuGroup = function MenuGroup(_ref) {
144
151
  title: "Add picture from URL",
145
152
  icon: _icons.publicIcon,
146
153
  children: "Add picture from URL"
147
- }), /*#__PURE__*/_react["default"].createElement("hr", null)), /*#__PURE__*/_react["default"].createElement(_LoadFileTool["default"], {
154
+ })), withDivider && /*#__PURE__*/_react["default"].createElement("hr", null), withLoadAndSave && /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_LoadFileTool["default"], {
148
155
  withText: true,
149
156
  disabled: disabled,
150
157
  loadFile: loadFile,
@@ -159,7 +166,7 @@ var MenuGroup = function MenuGroup(_ref) {
159
166
  img: _icons.saveIcon,
160
167
  isActive: activeTool === _Shapes.ToolEnum.saveFile,
161
168
  setActive: saveFile
162
- }), /*#__PURE__*/_react["default"].createElement(_Tool["default"], {
169
+ })), withExport && /*#__PURE__*/_react["default"].createElement(_Tool["default"], {
163
170
  withText: true,
164
171
  disabled: disabled,
165
172
  type: _Shapes.ToolEnum["export"],
@@ -167,7 +174,7 @@ var MenuGroup = function MenuGroup(_ref) {
167
174
  img: _icons.exportFileIcon,
168
175
  isActive: activeTool === _Shapes.ToolEnum["export"],
169
176
  setActive: exportCanvasInFile
170
- })));
177
+ }))) : null;
171
178
  };
172
179
 
173
180
  var _default = MenuGroup;
@@ -82,6 +82,8 @@ var Toolbar = function Toolbar(_ref) {
82
82
  hasActionToRedo = _ref$hasActionToRedo === void 0 ? false : _ref$hasActionToRedo,
83
83
  _ref$hasActionToClear = _ref.hasActionToClear,
84
84
  hasActionToClear = _ref$hasActionToClear === void 0 ? false : _ref$hasActionToClear,
85
+ withLoadAndSave = _ref.withLoadAndSave,
86
+ withExport = _ref.withExport,
85
87
  clearCanvas = _ref.clearCanvas,
86
88
  setActiveToolFromProps = _ref.setActiveTool,
87
89
  undoAction = _ref.undoAction,
@@ -181,7 +183,9 @@ var Toolbar = function Toolbar(_ref) {
181
183
  saveFile: saveFile,
182
184
  togglePictureUrlModal: openPictureUrlModal,
183
185
  exportCanvasInFile: exportCanvasInFile,
184
- availableTools: availableTools
186
+ availableTools: availableTools,
187
+ withLoadAndSave: withLoadAndSave,
188
+ withExport: withExport
185
189
  })), isMenuOpen && /*#__PURE__*/_react["default"].createElement(StyledToolsModal, {
186
190
  onClose: toggleTools
187
191
  }, availableTools.map(function (toolType) {
@@ -3,9 +3,13 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.SELECTION_ROTATED_ANCHOR_POSITION = exports.SELECTION_RESIZE_ANCHOR_POSITIONS = exports.SELECTION_PADDING = exports.SELECTION_ANCHOR_SIZE = void 0;
7
- var SELECTION_PADDING = 0;
8
- exports.SELECTION_PADDING = SELECTION_PADDING;
6
+ exports.SELECTION_ROTATED_ANCHOR_POSITION = exports.SELECTION_RESIZE_ANCHOR_POSITIONS = exports.SELECTION_DEFAULT_WIDTH = exports.SELECTION_DEFAULT_PADDING = exports.SELECTION_DEFAULT_COLOR = exports.SELECTION_ANCHOR_SIZE = void 0;
7
+ var SELECTION_DEFAULT_PADDING = 0;
8
+ exports.SELECTION_DEFAULT_PADDING = SELECTION_DEFAULT_PADDING;
9
+ var SELECTION_DEFAULT_WIDTH = 2;
10
+ exports.SELECTION_DEFAULT_WIDTH = SELECTION_DEFAULT_WIDTH;
11
+ var SELECTION_DEFAULT_COLOR = 'blue';
12
+ exports.SELECTION_DEFAULT_COLOR = SELECTION_DEFAULT_COLOR;
9
13
  var SELECTION_ANCHOR_SIZE = 14;
10
14
  exports.SELECTION_ANCHOR_SIZE = SELECTION_ANCHOR_SIZE;
11
15
  var SELECTION_ROTATED_ANCHOR_POSITION = 16;
@@ -25,7 +25,7 @@ var _transform = require("../utils/transform");
25
25
 
26
26
  var _data = require("../utils/data");
27
27
 
28
- var handleMove = function handleMove(e, canvasRef, activeTool, canvasOffset, selectedShape, selectionMode, canvasOffsetStartPosition, width, height, scaleRatio, setHoverMode, updateSingleShape, setCanvasOffset, setSelectedShape) {
28
+ var handleMove = function handleMove(e, canvasRef, activeTool, canvasOffset, selectedShape, selectionMode, canvasOffsetStartPosition, width, height, scaleRatio, setHoverMode, updateSingleShape, setCanvasOffset, setSelectedShape, selectionPadding) {
29
29
  if (activeTool === _Shapes.ToolEnum.move && canvasOffsetStartPosition !== undefined) {
30
30
  var _cursorPosition = (0, _intersect.getCursorPosition)(e, canvasRef.current, width, height, scaleRatio);
31
31
 
@@ -37,7 +37,7 @@ var handleMove = function handleMove(e, canvasRef, activeTool, canvasOffset, sel
37
37
  var cursorPosition = (0, _intersect.getCursorPosition)(e, canvasRef.current, width, height, scaleRatio);
38
38
 
39
39
  if (selectionMode.mode === _Mode.SelectionModeLib["default"]) {
40
- var positionIntersection = (0, _intersect.checkPositionIntersection)(selectedShape, cursorPosition, canvasOffset, scaleRatio, true) || {
40
+ var positionIntersection = (0, _intersect.checkPositionIntersection)(selectedShape, cursorPosition, canvasOffset, selectionPadding, scaleRatio, true) || {
41
41
  mode: _Mode.SelectionModeLib["default"]
42
42
  };
43
43
  setHoverMode(positionIntersection);
@@ -47,7 +47,7 @@ var handleMove = function handleMove(e, canvasRef, activeTool, canvasOffset, sel
47
47
  var ctx = (_canvasRef$current = canvasRef.current) === null || _canvasRef$current === void 0 ? void 0 : _canvasRef$current.getContext('2d');
48
48
  if (!ctx) return;
49
49
 
50
- var _newShape = (0, _transform.transformShape)(ctx, selectedShape, cursorPosition, canvasOffset, selectionMode);
50
+ var _newShape = (0, _transform.transformShape)(ctx, selectedShape, cursorPosition, canvasOffset, selectionMode, selectionPadding);
51
51
 
52
52
  updateSingleShape(_newShape);
53
53
  setSelectedShape(_newShape);
@@ -75,7 +75,8 @@ var useDrawableCanvas = function useDrawableCanvas(_ref) {
75
75
  updateSingleShape = _ref.updateSingleShape,
76
76
  canvasOffset = _ref.canvasOffset,
77
77
  saveShapes = _ref.saveShapes,
78
- setSelectionMode = _ref.setSelectionMode;
78
+ setSelectionMode = _ref.setSelectionMode,
79
+ selectionPadding = _ref.selectionPadding;
79
80
  var width = canvasSize.width,
80
81
  height = canvasSize.height,
81
82
  scaleRatio = canvasSize.scaleRatio;
@@ -90,7 +91,7 @@ var useDrawableCanvas = function useDrawableCanvas(_ref) {
90
91
  (0, _react.useEffect)(function () {
91
92
  var handleMouseMove = function handleMouseMove(e) {
92
93
  return window.requestAnimationFrame(function () {
93
- return handleMove(e, selectionCanvasRef, activeTool, canvasOffset, selectedShape, selectionMode, canvasOffsetStartPosition, width, height, scaleRatio, setHoverMode, updateSingleShape, setCanvasOffset, setSelectedShape);
94
+ return handleMove(e, selectionCanvasRef, activeTool, canvasOffset, selectedShape, selectionMode, canvasOffsetStartPosition, width, height, scaleRatio, setHoverMode, updateSingleShape, setCanvasOffset, setSelectedShape, selectionPadding);
94
95
  });
95
96
  };
96
97
 
@@ -105,7 +106,7 @@ var useDrawableCanvas = function useDrawableCanvas(_ref) {
105
106
  document.removeEventListener('touchmove', handleMouseMove);
106
107
  }
107
108
  };
108
- }, [isInsideComponent, selectionCanvasRef, selectedShape, selectionMode, setHoverMode, canvasOffset, canvasOffsetStartPosition, width, height, scaleRatio, updateSingleShape, activeTool, setCanvasOffset, setSelectedShape]);
109
+ }, [isInsideComponent, selectionCanvasRef, selectedShape, selectionMode, setHoverMode, canvasOffset, canvasOffsetStartPosition, width, height, scaleRatio, updateSingleShape, activeTool, setCanvasOffset, setSelectedShape, selectionPadding]);
109
110
  (0, _react.useEffect)(function () {
110
111
  var handleMouseUp = function handleMouseUp(e) {
111
112
  if (selectionMode.mode === _Mode.SelectionModeLib.textedition) return;
@@ -159,7 +160,7 @@ var useDrawableCanvas = function useDrawableCanvas(_ref) {
159
160
  var cursorPosition = (0, _intersect.getCursorPosition)(e, selectionCanvasRef.current, width, height, scaleRatio);
160
161
 
161
162
  if (activeTool === _Shapes.ToolEnum.selection) {
162
- var _selectShape = (0, _selection.selectShape)(shapes, cursorPosition, scaleRatio, canvasOffset, selectedShape),
163
+ var _selectShape = (0, _selection.selectShape)(shapes, cursorPosition, scaleRatio, canvasOffset, selectedShape, selectionPadding),
163
164
  shape = _selectShape.shape,
164
165
  mode = _selectShape.mode;
165
166
 
@@ -213,7 +214,7 @@ var useDrawableCanvas = function useDrawableCanvas(_ref) {
213
214
  ref.removeEventListener('mousedown', handleMouseDown);
214
215
  ref.removeEventListener('touchstart', handleMouseDown);
215
216
  };
216
- }, [disabled, selectionCanvasRef, drawCanvasRef, selectedShape, activeTool, canvasOffset, setCanvasOffsetStartPosition, shapes, defaultConf, width, height, scaleRatio, updateSingleShape, addShape, setActiveTool, setSelectedShape, setSelectionMode]);
217
+ }, [disabled, selectionCanvasRef, drawCanvasRef, selectedShape, activeTool, canvasOffset, setCanvasOffsetStartPosition, shapes, defaultConf, width, height, scaleRatio, updateSingleShape, addShape, setActiveTool, setSelectedShape, setSelectionMode, selectionPadding]);
217
218
  (0, _react.useEffect)(function () {
218
219
  var ref = selectionCanvasRef.current;
219
220
  if (!ref) return;
@@ -223,7 +224,7 @@ var useDrawableCanvas = function useDrawableCanvas(_ref) {
223
224
  if ((selectedShape === null || selectedShape === void 0 ? void 0 : selectedShape.type) === _Shapes.ShapeEnum.text) {
224
225
  var cursorPosition = (0, _intersect.getCursorPosition)(e, selectionCanvasRef.current, width, height, scaleRatio);
225
226
 
226
- if ((0, _intersect.checkPositionIntersection)(selectedShape, cursorPosition, canvasOffset)) {
227
+ if ((0, _intersect.checkPositionIntersection)(selectedShape, cursorPosition, canvasOffset, selectionPadding)) {
227
228
  setSelectionMode({
228
229
  mode: _Mode.SelectionModeLib.textedition,
229
230
  defaultValue: selectedShape.value
@@ -242,7 +243,7 @@ var useDrawableCanvas = function useDrawableCanvas(_ref) {
242
243
  ref.removeEventListener('dblclick', handleDoubleClick);
243
244
  }
244
245
  };
245
- }, [isInsideComponent, selectionCanvasRef, activeTool, selectedShape, width, height, scaleRatio, canvasOffset, setSelectionMode]);
246
+ }, [isInsideComponent, selectionCanvasRef, activeTool, selectedShape, width, height, scaleRatio, canvasOffset, setSelectionMode, selectionPadding]);
246
247
  return {
247
248
  hoverMode: hoverMode
248
249
  };
@@ -78,9 +78,10 @@ var useShapes = function useShapes() {
78
78
  case 4:
79
79
  pictureShape = _context.sent;
80
80
  addShape(pictureShape);
81
+ saveShapes();
81
82
  return _context.abrupt("return", pictureShape);
82
83
 
83
- case 7:
84
+ case 8:
84
85
  case "end":
85
86
  return _context.stop();
86
87
  }
@@ -91,7 +92,7 @@ var useShapes = function useShapes() {
91
92
  return function (_x) {
92
93
  return _ref.apply(this, arguments);
93
94
  };
94
- }(), [addShape]);
95
+ }(), [addShape, saveShapes]);
95
96
  var updateShape = (0, _react.useCallback)(function (updatedShape) {
96
97
  var withSave = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
97
98
  shapesRef.current = shapesRef.current.map(function (marker) {