@yorab/react-paint 0.3.0 → 0.4.2

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,28 @@
1
+ # V.0.4.2
2
+
3
+ - fix toolgroup not displayed
4
+ - add passive prop to event listener
5
+
6
+ # V.0.4.1
7
+
8
+ - prevent mounting selection canvas when viewer mode
9
+ - prevent drawing selection when not needed
10
+ - Click on toolbar tool group always enable a tool
11
+ - fix input and select options not being impacted by
12
+ - new reponsive for toolbar
13
+
14
+ # V.0.4.0
15
+
16
+ - Add possibility to customize UI from props
17
+
18
+ # V.0.3.1
19
+
20
+ - Add prop to change canvas background color
21
+ - Move some props to options
22
+ - fix Picture shape not being saved and not triggering onDataChanged
23
+ - small picture are upscaled to fit container when imported
24
+ - Add prop to choose to display save/load/export
25
+
1
26
  # V.0.3.0 :
2
27
 
3
28
  - 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,21 +541,34 @@ 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"], {
571
+ width: canvasSize.width,
481
572
  disabled: disabled,
482
573
  activeTool: activeTool,
483
574
  clearCanvas: clearCanvas,
@@ -491,7 +582,9 @@ var App = function App(_ref5) {
491
582
  hasActionToClear: canClear,
492
583
  undoAction: undoAction,
493
584
  redoAction: redoAction,
494
- availableTools: availableTools
585
+ availableTools: availableTools,
586
+ withExport: withExport,
587
+ withLoadAndSave: withLoadAndSave
495
588
  }), /*#__PURE__*/_react["default"].createElement(StyledRow, {
496
589
  "data-grow": canGrow,
497
590
  width: canvasSize.width,
@@ -517,7 +610,11 @@ var App = function App(_ref5) {
517
610
  ref: canvasRef,
518
611
  canvasSize: canvasSize,
519
612
  selectionMode: selectionMode,
520
- setSelectionMode: setSelectionMode
613
+ setSelectionMode: setSelectionMode,
614
+ selectionColor: canvasSelectionColor,
615
+ selectionWidth: canvasSelectionWidth,
616
+ selectionPadding: canvasSelectionPadding,
617
+ isEditMode: isEditMode
521
618
  }), isEditMode && layersManipulation && /*#__PURE__*/_react["default"].createElement(_Layouts["default"], {
522
619
  withGrid: withGrid,
523
620
  setWithGrid: setWithGrid,
@@ -39,24 +39,32 @@ 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 renderDrawCanvas = function renderDrawCanvas(drawCtx, selectionMode, canvasSize, canvasOffset, shapes, selectionPadding, selectedShape) {
43
43
  var width = canvasSize.width,
44
44
  height = canvasSize.height,
45
45
  scaleRatio = canvasSize.scaleRatio;
46
46
  drawCtx.clearRect(0, 0, width, height);
47
- selectionCtx.clearRect(0, 0, width, height);
48
47
 
49
48
  for (var i = shapes.length - 1; i >= 0; i--) {
50
49
  if (selectionMode.mode !== _Mode.SelectionModeLib.textedition || shapes[i] !== selectedShape) {
51
- (0, _draw.drawShape)(drawCtx, shapes[i], scaleRatio, canvasOffset);
50
+ (0, _draw.drawShape)(drawCtx, shapes[i], scaleRatio, canvasOffset, selectionPadding);
52
51
  }
53
52
  }
53
+ };
54
54
 
55
+ var renderSelectionCanvas = function renderSelectionCanvas(selectionCtx, selectionMode, canvasSize, activeTool, canvasOffset, selectionPadding, selectionWidth, selectionColor, selectedShape) {
56
+ var width = canvasSize.width,
57
+ height = canvasSize.height,
58
+ scaleRatio = canvasSize.scaleRatio;
59
+ selectionCtx.clearRect(0, 0, width, height);
55
60
  selectedShape && activeTool !== _Shapes.ShapeEnum.brush && (0, _draw.drawSelection)({
56
61
  ctx: selectionCtx,
57
62
  shape: selectedShape,
58
63
  scaleRatio: scaleRatio,
59
64
  canvasOffset: canvasOffset,
65
+ selectionPadding: selectionPadding,
66
+ selectionWidth: selectionWidth,
67
+ selectionColor: selectionColor,
60
68
  withAnchors: selectionMode.mode !== _Mode.SelectionModeLib.textedition
61
69
  });
62
70
  };
@@ -105,7 +113,11 @@ var Canvas = /*#__PURE__*/_react["default"].forwardRef(function (_ref2, ref) {
105
113
  defaultConf = _ref2.defaultConf,
106
114
  isInsideComponent = _ref2.isInsideComponent,
107
115
  selectionMode = _ref2.selectionMode,
108
- setSelectionMode = _ref2.setSelectionMode;
116
+ setSelectionMode = _ref2.setSelectionMode,
117
+ selectionWidth = _ref2.selectionWidth,
118
+ selectionColor = _ref2.selectionColor,
119
+ selectionPadding = _ref2.selectionPadding,
120
+ isEditMode = _ref2.isEditMode;
109
121
  var drawCanvasRef = (0, _react.useRef)(null);
110
122
  var selectionCanvasRef = (0, _react.useRef)(null); // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
111
123
 
@@ -133,7 +145,8 @@ var Canvas = /*#__PURE__*/_react["default"].forwardRef(function (_ref2, ref) {
133
145
  updateSingleShape: updateSingleShape,
134
146
  canvasOffset: canvasOffset,
135
147
  saveShapes: saveShapes,
136
- setSelectionMode: setSelectionMode
148
+ setSelectionMode: setSelectionMode,
149
+ selectionPadding: selectionPadding
137
150
  }),
138
151
  hoverMode = _useDrawableCanvas.hoverMode;
139
152
 
@@ -156,14 +169,21 @@ var Canvas = /*#__PURE__*/_react["default"].forwardRef(function (_ref2, ref) {
156
169
  updateSingleShape(resizedShape);
157
170
  }, [updateSingleShape, selectedShape]);
158
171
  (0, _react.useEffect)(function () {
159
- var _drawCanvasRef$curren2, _selectionCanvasRef$c;
172
+ var _drawCanvasRef$curren2;
160
173
 
161
174
  var drawCtx = (_drawCanvasRef$curren2 = drawCanvasRef.current) === null || _drawCanvasRef$curren2 === void 0 ? void 0 : _drawCanvasRef$curren2.getContext('2d');
175
+ drawCtx && window.requestAnimationFrame(function () {
176
+ return renderDrawCanvas(drawCtx, selectionMode, canvasSize, canvasOffset, shapes, selectionPadding, selectedShape);
177
+ });
178
+ }, [shapes, selectionMode, selectedShape, canvasOffset, canvasSize, selectionPadding]);
179
+ (0, _react.useEffect)(function () {
180
+ var _selectionCanvasRef$c;
181
+
162
182
  var selectionCtx = (_selectionCanvasRef$c = selectionCanvasRef.current) === null || _selectionCanvasRef$c === void 0 ? void 0 : _selectionCanvasRef$c.getContext('2d');
163
- drawCtx && selectionCtx && window.requestAnimationFrame(function () {
164
- return drawCanvas(drawCtx, selectionCtx, selectionMode, canvasSize, activeTool, canvasOffset, shapes, selectedShape);
183
+ selectionCtx && window.requestAnimationFrame(function () {
184
+ return renderSelectionCanvas(selectionCtx, selectionMode, canvasSize, activeTool, canvasOffset, selectionPadding, selectionWidth, selectionColor, selectedShape);
165
185
  });
166
- }, [shapes, selectionMode, selectedShape, activeTool, canvasOffset, canvasSize]);
186
+ }, [selectionMode, selectedShape, activeTool, canvasOffset, canvasSize, selectionPadding, selectionWidth, selectionColor]);
167
187
  return /*#__PURE__*/_react["default"].createElement(StyledCanvasBox, null, /*#__PURE__*/_react["default"].createElement(StyledCanvasContainer, {
168
188
  "data-grid": withGrid,
169
189
  "data-grow": canGrow
@@ -172,18 +192,19 @@ var Canvas = /*#__PURE__*/_react["default"].forwardRef(function (_ref2, ref) {
172
192
  "data-grow": canGrow,
173
193
  width: canvasSize.width,
174
194
  height: canvasSize.height
175
- }), /*#__PURE__*/_react["default"].createElement(StyledSelectionCanvas, {
195
+ }), isEditMode && /*#__PURE__*/_react["default"].createElement(StyledSelectionCanvas, {
176
196
  ref: selectionCanvasRef,
177
197
  width: canvasSize.width,
178
198
  height: canvasSize.height,
179
199
  "data-grow": canGrow,
180
200
  cursor: activeTool !== _Shapes.ToolEnum.selection && activeTool !== _Shapes.ToolEnum.move || hoverMode.mode === _Mode.SelectionModeLib.resize ? 'crosshair' : activeTool === _Shapes.ToolEnum.move || hoverMode.mode === _Mode.SelectionModeLib.translate ? 'move' : hoverMode.mode === _Mode.SelectionModeLib.rotate ? 'grab' : 'default'
181
- }), selectionMode.mode === _Mode.SelectionModeLib.textedition && (selectedShape === null || selectedShape === void 0 ? void 0 : selectedShape.type) === _Shapes.ShapeEnum.text && /*#__PURE__*/_react["default"].createElement(_EditTextBox["default"], {
201
+ }), isEditMode && selectionMode.mode === _Mode.SelectionModeLib.textedition && (selectedShape === null || selectedShape === void 0 ? void 0 : selectedShape.type) === _Shapes.ShapeEnum.text && /*#__PURE__*/_react["default"].createElement(_EditTextBox["default"], {
182
202
  scaleRatio: canvasSize.scaleRatio,
183
203
  disabled: disabled,
184
204
  shape: selectedShape,
185
205
  defaultValue: selectionMode.defaultValue,
186
- updateValue: updateSelectedShapeText
206
+ updateValue: updateSelectedShapeText,
207
+ selectionPadding: selectionPadding
187
208
  })));
188
209
  });
189
210
 
@@ -49,10 +49,6 @@ var StyledCustomColor = /*#__PURE__*/(0, _react2.styled)("div")({
49
49
  }]
50
50
  }
51
51
  });
52
- var StyledColorButton = /*#__PURE__*/(0, _react2.styled)(_Button["default"])({
53
- name: "StyledColorButton",
54
- "class": "sttf061"
55
- });
56
52
 
57
53
  var ColorField = function ColorField(_ref3) {
58
54
  var selectedSettings = _ref3.selectedSettings,
@@ -98,7 +94,7 @@ var ColorField = function ColorField(_ref3) {
98
94
  title: title,
99
95
  alignment: "left"
100
96
  }, /*#__PURE__*/_react["default"].createElement("div", null, _style.STYLE_COLORS.map(function (color, index) {
101
- return /*#__PURE__*/_react["default"].createElement(StyledColorButton, {
97
+ return /*#__PURE__*/_react["default"].createElement(_Button["default"], {
102
98
  title: color,
103
99
  key: index,
104
100
  selected: color === value,
@@ -109,14 +105,14 @@ var ColorField = function ColorField(_ref3) {
109
105
  }, /*#__PURE__*/_react["default"].createElement(StyledColor, {
110
106
  color: color === 'transparent' ? "url('data:image/svg+xml,".concat(_icons.encodedTransparentIcon, "')") : color
111
107
  }));
112
- }), /*#__PURE__*/_react["default"].createElement(StyledColorButton, {
108
+ }), /*#__PURE__*/_react["default"].createElement(_Button["default"], {
113
109
  type: "color",
114
110
  title: "Custom color",
115
111
  selected: !_fp["default"].includes(value, _style.STYLE_COLORS),
116
112
  value: value,
117
113
  onChange: handleChange
118
114
  }, /*#__PURE__*/_react["default"].createElement(StyledCustomColor, {
119
- color: _fp["default"].includes(value, _style.STYLE_COLORS) ? 'black' : value
115
+ color: _fp["default"].includes(value, _style.STYLE_COLORS) ? 'var(--font-color)' : value
120
116
  }, /*#__PURE__*/_react["default"].createElement("span", {
121
117
  dangerouslySetInnerHTML: {
122
118
  __html: _icons.paletteIcon
@@ -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,
@@ -52,12 +52,24 @@ var MenuGroup = function MenuGroup(_ref) {
52
52
  var _ref3;
53
53
 
54
54
  var activeTool = _ref.activeTool,
55
+ withActionsInMenu = _ref.withActionsInMenu,
56
+ _ref$hasActionToUndo = _ref.hasActionToUndo,
57
+ hasActionToUndo = _ref$hasActionToUndo === void 0 ? false : _ref$hasActionToUndo,
58
+ _ref$hasActionToRedo = _ref.hasActionToRedo,
59
+ hasActionToRedo = _ref$hasActionToRedo === void 0 ? false : _ref$hasActionToRedo,
60
+ _ref$hasActionToClear = _ref.hasActionToClear,
61
+ hasActionToClear = _ref$hasActionToClear === void 0 ? false : _ref$hasActionToClear,
62
+ undoAction = _ref.undoAction,
63
+ redoAction = _ref.redoAction,
64
+ clearCanvas = _ref.clearCanvas,
55
65
  alignment = _ref.alignment,
56
66
  group = _ref.group,
57
67
  _ref$vertical = _ref.vertical,
58
68
  vertical = _ref$vertical === void 0 ? false : _ref$vertical,
59
69
  _ref$disabled = _ref.disabled,
60
70
  disabled = _ref$disabled === void 0 ? false : _ref$disabled,
71
+ withLoadAndSave = _ref.withLoadAndSave,
72
+ withExport = _ref.withExport,
61
73
  addPictureFromProps = _ref.addPicture,
62
74
  loadFileFromProps = _ref.loadFile,
63
75
  togglePictureUrlModal = _ref.togglePictureUrlModal,
@@ -121,7 +133,11 @@ var MenuGroup = function MenuGroup(_ref) {
121
133
  document.removeEventListener('click', closePanel);
122
134
  };
123
135
  }, [isOpen]);
124
- return /*#__PURE__*/_react["default"].createElement(StyledRelative, null, /*#__PURE__*/_react["default"].createElement(_Button["default"], {
136
+
137
+ var withPicture = _fp["default"].includes(_Shapes.ShapeEnum.picture, availableTools);
138
+
139
+ var withMenu = withActionsInMenu || withPicture || withLoadAndSave || withExport;
140
+ return withMenu ? /*#__PURE__*/_react["default"].createElement(StyledRelative, null, /*#__PURE__*/_react["default"].createElement(_Button["default"], {
125
141
  selected: isActive,
126
142
  title: group.title,
127
143
  disabled: disabled,
@@ -130,7 +146,33 @@ var MenuGroup = function MenuGroup(_ref) {
130
146
  }), isOpen && /*#__PURE__*/_react["default"].createElement(StyledPanel, {
131
147
  vertical: vertical,
132
148
  alignment: alignment
133
- }, _fp["default"].includes(_Shapes.ShapeEnum.picture, availableTools) && /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_LoadFileTool["default"], {
149
+ }, withActionsInMenu && /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_Tool["default"], {
150
+ withText: true,
151
+ type: _Shapes.ToolEnum.undo,
152
+ disabled: disabled || !hasActionToUndo,
153
+ lib: "Undo",
154
+ img: _icons.undoIcon,
155
+ isActive: activeTool === _Shapes.ToolEnum.undo,
156
+ setActive: undoAction
157
+ }), /*#__PURE__*/_react["default"].createElement(_Tool["default"], {
158
+ withText: true,
159
+ type: _Shapes.ToolEnum.redo,
160
+ disabled: disabled || !hasActionToRedo,
161
+ lib: "Redo",
162
+ img: _icons.redoIcon,
163
+ isActive: activeTool === _Shapes.ToolEnum.redo,
164
+ setActive: redoAction
165
+ }), /*#__PURE__*/_react["default"].createElement(_Tool["default"], {
166
+ withText: true,
167
+ type: _Shapes.ToolEnum.clear,
168
+ disabled: disabled || !hasActionToClear,
169
+ lib: "Clear",
170
+ img: _icons.clearIcon,
171
+ isActive: activeTool === _Shapes.ToolEnum.clear,
172
+ setActive: function setActive() {
173
+ return clearCanvas();
174
+ }
175
+ }), (withPicture || withLoadAndSave) && /*#__PURE__*/_react["default"].createElement("hr", null)), withPicture && /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_LoadFileTool["default"], {
134
176
  withText: true,
135
177
  disabled: disabled,
136
178
  loadFile: addPicture,
@@ -144,7 +186,7 @@ var MenuGroup = function MenuGroup(_ref) {
144
186
  title: "Add picture from URL",
145
187
  icon: _icons.publicIcon,
146
188
  children: "Add picture from URL"
147
- }), /*#__PURE__*/_react["default"].createElement("hr", null)), /*#__PURE__*/_react["default"].createElement(_LoadFileTool["default"], {
189
+ }), withLoadAndSave && /*#__PURE__*/_react["default"].createElement("hr", null)), withLoadAndSave && /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_LoadFileTool["default"], {
148
190
  withText: true,
149
191
  disabled: disabled,
150
192
  loadFile: loadFile,
@@ -159,7 +201,7 @@ var MenuGroup = function MenuGroup(_ref) {
159
201
  img: _icons.saveIcon,
160
202
  isActive: activeTool === _Shapes.ToolEnum.saveFile,
161
203
  setActive: saveFile
162
- }), /*#__PURE__*/_react["default"].createElement(_Tool["default"], {
204
+ })), withExport && /*#__PURE__*/_react["default"].createElement(_Tool["default"], {
163
205
  withText: true,
164
206
  disabled: disabled,
165
207
  type: _Shapes.ToolEnum["export"],
@@ -167,7 +209,7 @@ var MenuGroup = function MenuGroup(_ref) {
167
209
  img: _icons.exportFileIcon,
168
210
  isActive: activeTool === _Shapes.ToolEnum["export"],
169
211
  setActive: exportCanvasInFile
170
- })));
212
+ }))) : null;
171
213
  };
172
214
 
173
215
  var _default = MenuGroup;