@yorab/react-paint 0.6.4 → 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.
- package/README.md +5 -5
- package/dist/components/App.js +236 -423
- package/dist/components/Canvas.js +120 -139
- package/dist/components/common/Button.js +41 -50
- package/dist/components/common/Loading.js +24 -33
- package/dist/components/common/Modal.js +18 -17
- package/dist/components/common/Panel.js +20 -28
- package/dist/components/common/Snackbar.js +31 -38
- package/dist/components/settings/ColorField.js +59 -68
- package/dist/components/settings/DeleteButton.js +10 -9
- package/dist/components/settings/FontFamilyField.js +25 -20
- package/dist/components/settings/LayoutButton.js +11 -9
- package/dist/components/settings/Layouts.js +111 -111
- package/dist/components/settings/LineArrowField.js +25 -22
- package/dist/components/settings/LineTypeField.js +23 -20
- package/dist/components/settings/PointsNumberField.js +14 -13
- package/dist/components/settings/RangeField.js +35 -47
- package/dist/components/settings/SelectField.js +34 -43
- package/dist/components/settings/SettingsBar.js +100 -121
- package/dist/components/settings/ToggleField.js +18 -25
- package/dist/components/toolbox/EditTextBox.js +62 -49
- package/dist/components/toolbox/LoadFileTool.js +19 -21
- package/dist/components/toolbox/MenuGroup.js +66 -100
- package/dist/components/toolbox/PictureUrlInput.js +33 -62
- package/dist/components/toolbox/Tool.js +13 -13
- package/dist/components/toolbox/Toolbar.js +79 -113
- package/dist/components/toolbox/ToolbarGroup.js +60 -63
- package/dist/constants/app.js +51 -0
- package/dist/constants/icons.js +42 -48
- package/dist/constants/loading.js +8 -0
- package/dist/constants/shapes.js +10 -8
- package/dist/constants/snackbar.js +7 -15
- package/dist/constants/style.js +21 -18
- package/dist/constants/tools.js +99 -103
- package/dist/hooks/useComponent.js +15 -20
- package/dist/hooks/useDoubleClick.js +12 -12
- package/dist/hooks/useDrag.js +24 -32
- package/dist/hooks/useDrawableCanvas.js +106 -122
- package/dist/hooks/useKeyboard.js +80 -63
- package/dist/hooks/useResizeObserver.js +18 -16
- package/dist/hooks/useShapes.js +92 -144
- package/dist/hooks/useSnackbar.js +28 -58
- package/dist/styles.css +16 -13
- package/dist/types/Mode.js +1 -13
- package/dist/types/Shapes.js +1 -17
- package/dist/types/snackbar.js +5 -0
- package/dist/types/tools.js +1 -18
- package/dist/utils/canvas.js +49 -0
- package/dist/utils/data.js +15 -274
- package/dist/utils/dom.js +12 -0
- package/dist/utils/file.js +75 -120
- package/dist/utils/intersect.js +54 -131
- package/dist/utils/migration.js +59 -0
- package/dist/utils/selection.js +18 -20
- package/dist/utils/shapes/brush.js +135 -0
- package/dist/utils/shapes/circle.js +93 -0
- package/dist/utils/shapes/curve.js +55 -0
- package/dist/utils/shapes/default.js +73 -0
- package/dist/utils/shapes/ellipse.js +101 -0
- package/dist/utils/shapes/grid.js +36 -0
- package/dist/utils/shapes/index.js +341 -0
- package/dist/utils/shapes/line.js +179 -0
- package/dist/utils/shapes/picture.js +88 -0
- package/dist/utils/shapes/polygon.js +69 -0
- package/dist/utils/shapes/rectangle.js +100 -0
- package/dist/utils/shapes/text.js +128 -0
- package/dist/utils/shapes/triangle.js +24 -0
- package/dist/utils/string.js +10 -16
- package/dist/utils/style.js +11 -13
- package/dist/utils/toolbar.js +35 -49
- package/dist/utils/transform.js +47 -339
- package/dist/utils/trigo.js +42 -0
- package/package.json +6 -6
- package/Changelog.md +0 -119
- package/dist/types/keyboard.js +0 -28
- package/dist/utils/draw.js +0 -461
- package/dist/utils/shapeData.js +0 -173
|
@@ -2,14 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
4
|
|
|
5
|
-
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
6
|
-
|
|
7
5
|
Object.defineProperty(exports, "__esModule", {
|
|
8
6
|
value: true
|
|
9
7
|
});
|
|
10
|
-
exports
|
|
11
|
-
|
|
12
|
-
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
8
|
+
exports.default = void 0;
|
|
13
9
|
|
|
14
10
|
var _fp = _interopRequireDefault(require("lodash/fp"));
|
|
15
11
|
|
|
@@ -17,34 +13,31 @@ var _react = _interopRequireWildcard(require("react"));
|
|
|
17
13
|
|
|
18
14
|
var _Button = _interopRequireDefault(require("../common/Button"));
|
|
19
15
|
|
|
20
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function
|
|
21
|
-
|
|
22
|
-
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; }
|
|
16
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
23
17
|
|
|
24
|
-
var
|
|
25
|
-
var setSelectedSettings = _ref.setSelectedSettings,
|
|
26
|
-
_ref$disabled = _ref.disabled,
|
|
27
|
-
disabled = _ref$disabled === void 0 ? false : _ref$disabled,
|
|
28
|
-
field = _ref.field,
|
|
29
|
-
icon = _ref.icon,
|
|
30
|
-
values = _ref.values,
|
|
31
|
-
_ref$value = _ref.value,
|
|
32
|
-
value = _ref$value === void 0 ? false : _ref$value,
|
|
33
|
-
valueChanged = _ref.valueChanged;
|
|
18
|
+
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; }
|
|
34
19
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
20
|
+
const ToggleField = _ref => {
|
|
21
|
+
let {
|
|
22
|
+
setSelectedSettings,
|
|
23
|
+
disabled = false,
|
|
24
|
+
field,
|
|
25
|
+
icon,
|
|
26
|
+
values,
|
|
27
|
+
value = false,
|
|
28
|
+
valueChanged
|
|
29
|
+
} = _ref;
|
|
30
|
+
const [customKey] = (0, _react.useState)(_fp.default.uniqueId('settings_'));
|
|
38
31
|
|
|
39
|
-
|
|
40
|
-
setSelectedSettings(
|
|
32
|
+
const handleClick = () => {
|
|
33
|
+
setSelectedSettings(prev => {
|
|
41
34
|
return prev === customKey ? undefined : customKey;
|
|
42
35
|
});
|
|
43
36
|
valueChanged(field, !value);
|
|
44
37
|
};
|
|
45
38
|
|
|
46
39
|
if (values.length !== 2) return null;
|
|
47
|
-
return /*#__PURE__*/_react
|
|
40
|
+
return /*#__PURE__*/_react.default.createElement(_Button.default, {
|
|
48
41
|
onClick: handleClick,
|
|
49
42
|
selected: value,
|
|
50
43
|
disabled: disabled,
|
|
@@ -53,4 +46,4 @@ var ToggleField = function ToggleField(_ref) {
|
|
|
53
46
|
};
|
|
54
47
|
|
|
55
48
|
var _default = ToggleField;
|
|
56
|
-
exports
|
|
49
|
+
exports.default = _default;
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
4
|
-
|
|
5
3
|
Object.defineProperty(exports, "__esModule", {
|
|
6
4
|
value: true
|
|
7
5
|
});
|
|
8
|
-
exports
|
|
6
|
+
exports.default = void 0;
|
|
9
7
|
|
|
10
8
|
var _style = require("../../constants/style");
|
|
11
9
|
|
|
@@ -13,94 +11,109 @@ var _react = _interopRequireWildcard(require("react"));
|
|
|
13
11
|
|
|
14
12
|
var _react2 = require("@linaria/react");
|
|
15
13
|
|
|
16
|
-
var _intersect = require("../../utils/intersect");
|
|
17
|
-
|
|
18
|
-
var _shapeData = require("../../utils/shapeData");
|
|
19
|
-
|
|
20
14
|
var _string = require("../../utils/string");
|
|
21
15
|
|
|
22
|
-
var
|
|
16
|
+
var _shapes = require("../../utils/shapes");
|
|
23
17
|
|
|
24
|
-
|
|
18
|
+
var _trigo = require("../../utils/trigo");
|
|
25
19
|
|
|
26
|
-
function
|
|
20
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
27
21
|
|
|
28
|
-
var
|
|
22
|
+
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; }
|
|
23
|
+
|
|
24
|
+
const StyledEditBox = /*#__PURE__*/(0, _react2.styled)('div')({
|
|
29
25
|
name: "StyledEditBox",
|
|
30
|
-
|
|
26
|
+
class: "s1unz6yq",
|
|
31
27
|
vars: {
|
|
32
|
-
"s1unz6yq-0": [
|
|
33
|
-
|
|
28
|
+
"s1unz6yq-0": [_ref => {
|
|
29
|
+
let {
|
|
30
|
+
transform
|
|
31
|
+
} = _ref;
|
|
34
32
|
return transform;
|
|
35
33
|
}],
|
|
36
|
-
"s1unz6yq-1": [
|
|
37
|
-
|
|
34
|
+
"s1unz6yq-1": [_ref2 => {
|
|
35
|
+
let {
|
|
36
|
+
color
|
|
37
|
+
} = _ref2;
|
|
38
38
|
return color;
|
|
39
39
|
}],
|
|
40
|
-
"s1unz6yq-2": [
|
|
41
|
-
|
|
40
|
+
"s1unz6yq-2": [_ref3 => {
|
|
41
|
+
let {
|
|
42
|
+
padding
|
|
43
|
+
} = _ref3;
|
|
42
44
|
return padding;
|
|
43
45
|
}, "px"],
|
|
44
|
-
"s1unz6yq-3": [
|
|
45
|
-
|
|
46
|
+
"s1unz6yq-3": [_ref4 => {
|
|
47
|
+
let {
|
|
48
|
+
fontsize
|
|
49
|
+
} = _ref4;
|
|
46
50
|
return fontsize;
|
|
47
51
|
}, "px"],
|
|
48
|
-
"s1unz6yq-5": [
|
|
49
|
-
|
|
52
|
+
"s1unz6yq-5": [_ref5 => {
|
|
53
|
+
let {
|
|
54
|
+
fontfamily
|
|
55
|
+
} = _ref5;
|
|
50
56
|
return fontfamily;
|
|
51
57
|
}],
|
|
52
|
-
"s1unz6yq-6": [
|
|
53
|
-
|
|
58
|
+
"s1unz6yq-6": [_ref6 => {
|
|
59
|
+
let {
|
|
60
|
+
opacity
|
|
61
|
+
} = _ref6;
|
|
54
62
|
return opacity;
|
|
55
63
|
}]
|
|
56
64
|
}
|
|
57
65
|
});
|
|
58
66
|
|
|
59
|
-
|
|
67
|
+
const EditTextBox = _ref7 => {
|
|
60
68
|
var _shape$style$strokeCo, _shape$style, _shape$style$globalAl, _shape$style2, _shape$style$fontFami, _shape$style3, _shape$style$fontBold, _shape$style4, _shape$style$fontItal, _shape$style5;
|
|
61
69
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
70
|
+
let {
|
|
71
|
+
disabled = false,
|
|
72
|
+
scaleRatio,
|
|
73
|
+
shape,
|
|
74
|
+
defaultValue,
|
|
75
|
+
updateValue,
|
|
76
|
+
selectionPadding
|
|
77
|
+
} = _ref7;
|
|
78
|
+
const ref = (0, _react.useRef)(null);
|
|
79
|
+
|
|
80
|
+
const updateContentEditable = e => {
|
|
72
81
|
updateValue((0, _string.convertDivContentToStringArray)(e.target.innerHTML));
|
|
73
82
|
};
|
|
74
83
|
|
|
75
|
-
(0, _react.useEffect)(
|
|
84
|
+
(0, _react.useEffect)(() => {
|
|
76
85
|
if (!ref.current) return;
|
|
77
|
-
|
|
86
|
+
const currentNode = ref.current;
|
|
78
87
|
|
|
79
|
-
|
|
88
|
+
const handlePaste = e => {
|
|
80
89
|
var _e$clipboardData;
|
|
81
90
|
|
|
82
91
|
e.preventDefault();
|
|
83
|
-
|
|
92
|
+
const text = (_e$clipboardData = e.clipboardData) === null || _e$clipboardData === void 0 ? void 0 : _e$clipboardData.getData('text/plain');
|
|
84
93
|
document.execCommand('insertText', false, text); //TODO use Clipboard API when ready
|
|
85
94
|
};
|
|
86
95
|
|
|
87
96
|
currentNode.addEventListener('paste', handlePaste);
|
|
88
97
|
currentNode.innerHTML = (0, _string.convertStringArrayToDivContent)(defaultValue);
|
|
89
98
|
currentNode.focus();
|
|
90
|
-
return
|
|
99
|
+
return () => {
|
|
91
100
|
currentNode.removeEventListener('paste', handlePaste);
|
|
92
101
|
};
|
|
93
102
|
}, [defaultValue]);
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
return (0,
|
|
103
|
+
const position = (0, _react.useMemo)(() => {
|
|
104
|
+
const {
|
|
105
|
+
borders,
|
|
106
|
+
center
|
|
107
|
+
} = (0, _shapes.getShapeInfos)(shape, selectionPadding);
|
|
108
|
+
return (0, _trigo.rotatePoint)({
|
|
109
|
+
point: [borders.x, borders.y],
|
|
110
|
+
rotation: shape.rotation,
|
|
111
|
+
origin: center
|
|
112
|
+
});
|
|
100
113
|
}, [shape, selectionPadding]);
|
|
101
|
-
return /*#__PURE__*/_react
|
|
114
|
+
return /*#__PURE__*/_react.default.createElement(StyledEditBox, {
|
|
102
115
|
ref: ref,
|
|
103
|
-
transform: "translate3D(".concat(position[0] * scaleRatio, "px, ").concat(position[1] * scaleRatio, "px, 0) rotate(").concat((0,
|
|
116
|
+
transform: "translate3D(".concat(position[0] * scaleRatio, "px, ").concat(position[1] * scaleRatio, "px, 0) rotate(").concat((0, _trigo.radiansToDegrees)(shape.rotation), "deg)"),
|
|
104
117
|
fontsize: shape.fontSize * scaleRatio,
|
|
105
118
|
padding: selectionPadding * scaleRatio,
|
|
106
119
|
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',
|
|
@@ -114,4 +127,4 @@ var EditTextBox = function EditTextBox(_ref7) {
|
|
|
114
127
|
};
|
|
115
128
|
|
|
116
129
|
var _default = EditTextBox;
|
|
117
|
-
exports
|
|
130
|
+
exports.default = _default;
|
|
@@ -2,48 +2,46 @@
|
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
4
|
|
|
5
|
-
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
6
|
-
|
|
7
5
|
Object.defineProperty(exports, "__esModule", {
|
|
8
6
|
value: true
|
|
9
7
|
});
|
|
10
|
-
exports
|
|
8
|
+
exports.default = void 0;
|
|
11
9
|
|
|
12
10
|
var _react = _interopRequireWildcard(require("react"));
|
|
13
11
|
|
|
14
12
|
var _Button = _interopRequireDefault(require("../common/Button"));
|
|
15
13
|
|
|
16
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function
|
|
14
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
17
15
|
|
|
18
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null ||
|
|
16
|
+
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; }
|
|
19
17
|
|
|
20
|
-
|
|
18
|
+
const LoadFileTool = _ref => {
|
|
21
19
|
var _type$label;
|
|
22
20
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
21
|
+
let {
|
|
22
|
+
disabled = false,
|
|
23
|
+
withText = false,
|
|
24
|
+
loadFile,
|
|
25
|
+
type,
|
|
26
|
+
img,
|
|
27
|
+
accept
|
|
28
|
+
} = _ref;
|
|
29
|
+
const inputRef = (0, _react.useRef)(null);
|
|
30
|
+
|
|
31
|
+
const handleClick = event => {
|
|
34
32
|
event.stopPropagation();
|
|
35
33
|
if (inputRef.current) inputRef.current.value = '';
|
|
36
34
|
};
|
|
37
35
|
|
|
38
|
-
|
|
36
|
+
const handleChange = event => {
|
|
39
37
|
var _event$target$files;
|
|
40
38
|
|
|
41
|
-
|
|
39
|
+
const file = (_event$target$files = event.target.files) === null || _event$target$files === void 0 ? void 0 : _event$target$files.item(0);
|
|
42
40
|
if (!file) return;
|
|
43
41
|
loadFile(file);
|
|
44
42
|
};
|
|
45
43
|
|
|
46
|
-
return /*#__PURE__*/_react
|
|
44
|
+
return /*#__PURE__*/_react.default.createElement(_Button.default, {
|
|
47
45
|
ref: inputRef,
|
|
48
46
|
type: "file",
|
|
49
47
|
onClick: handleClick,
|
|
@@ -57,4 +55,4 @@ var LoadFileTool = function LoadFileTool(_ref) {
|
|
|
57
55
|
};
|
|
58
56
|
|
|
59
57
|
var _default = LoadFileTool;
|
|
60
|
-
exports
|
|
58
|
+
exports.default = _default;
|
|
@@ -2,18 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
4
|
|
|
5
|
-
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
6
|
-
|
|
7
5
|
Object.defineProperty(exports, "__esModule", {
|
|
8
6
|
value: true
|
|
9
7
|
});
|
|
10
|
-
exports
|
|
11
|
-
|
|
12
|
-
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
13
|
-
|
|
14
|
-
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
15
|
-
|
|
16
|
-
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
8
|
+
exports.default = void 0;
|
|
17
9
|
|
|
18
10
|
var _fp = _interopRequireDefault(require("lodash/fp"));
|
|
19
11
|
|
|
@@ -33,175 +25,149 @@ var _icons = require("../../constants/icons");
|
|
|
33
25
|
|
|
34
26
|
var _tools = require("../../constants/tools");
|
|
35
27
|
|
|
36
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function
|
|
28
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
37
29
|
|
|
38
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null ||
|
|
30
|
+
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; }
|
|
39
31
|
|
|
40
|
-
|
|
41
|
-
name: "
|
|
42
|
-
|
|
32
|
+
const StyledPanelContent = /*#__PURE__*/(0, _react2.styled)('div')({
|
|
33
|
+
name: "StyledPanelContent",
|
|
34
|
+
class: "s1uphjfh"
|
|
43
35
|
});
|
|
44
|
-
|
|
36
|
+
const StyledRelative = /*#__PURE__*/(0, _react2.styled)('div')({
|
|
45
37
|
name: "StyledRelative",
|
|
46
|
-
|
|
38
|
+
class: "s1e5a6k5"
|
|
47
39
|
});
|
|
48
40
|
|
|
49
|
-
|
|
50
|
-
var
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
var _useState = (0, _react.useState)(false),
|
|
80
|
-
_useState2 = (0, _slicedToArray2["default"])(_useState, 2),
|
|
81
|
-
isOpen = _useState2[0],
|
|
82
|
-
setIsOpen = _useState2[1];
|
|
83
|
-
|
|
84
|
-
var _useTransition = (0, _react.useTransition)(),
|
|
85
|
-
_useTransition2 = (0, _slicedToArray2["default"])(_useTransition, 2),
|
|
86
|
-
startTransition = _useTransition2[1];
|
|
87
|
-
|
|
88
|
-
var loadFile = function loadFile(file) {
|
|
41
|
+
const MenuGroup = _ref => {
|
|
42
|
+
var _ref2;
|
|
43
|
+
|
|
44
|
+
let {
|
|
45
|
+
activeTool,
|
|
46
|
+
withActionsInMenu,
|
|
47
|
+
hasActionToUndo = false,
|
|
48
|
+
hasActionToRedo = false,
|
|
49
|
+
hasActionToClear = false,
|
|
50
|
+
undoAction,
|
|
51
|
+
redoAction,
|
|
52
|
+
clearCanvas,
|
|
53
|
+
alignment,
|
|
54
|
+
group,
|
|
55
|
+
vertical = false,
|
|
56
|
+
disabled = false,
|
|
57
|
+
withLoadAndSave,
|
|
58
|
+
withExport,
|
|
59
|
+
addPicture: addPictureFromProps,
|
|
60
|
+
loadFile: loadFileFromProps,
|
|
61
|
+
togglePictureUrlModal,
|
|
62
|
+
saveFile,
|
|
63
|
+
exportCanvasInFile,
|
|
64
|
+
withUploadPicture,
|
|
65
|
+
withUrlPicture
|
|
66
|
+
} = _ref;
|
|
67
|
+
const [isOpen, setIsOpen] = (0, _react.useState)(false);
|
|
68
|
+
const [, startTransition] = (0, _react.useTransition)();
|
|
69
|
+
|
|
70
|
+
const loadFile = file => {
|
|
89
71
|
setIsOpen(false);
|
|
90
72
|
loadFileFromProps(file);
|
|
91
73
|
};
|
|
92
74
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
switch (_context.prev = _context.next) {
|
|
98
|
-
case 0:
|
|
99
|
-
setIsOpen(false);
|
|
100
|
-
_context.next = 3;
|
|
101
|
-
return addPictureFromProps(file);
|
|
102
|
-
|
|
103
|
-
case 3:
|
|
104
|
-
case "end":
|
|
105
|
-
return _context.stop();
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
}, _callee);
|
|
109
|
-
}));
|
|
110
|
-
|
|
111
|
-
return function addPicture(_x) {
|
|
112
|
-
return _ref2.apply(this, arguments);
|
|
113
|
-
};
|
|
114
|
-
}();
|
|
75
|
+
const addPicture = async file => {
|
|
76
|
+
setIsOpen(false);
|
|
77
|
+
await addPictureFromProps(file);
|
|
78
|
+
};
|
|
115
79
|
|
|
116
|
-
|
|
117
|
-
startTransition(
|
|
80
|
+
const openPanel = () => {
|
|
81
|
+
startTransition(() => {
|
|
118
82
|
setIsOpen(true);
|
|
119
83
|
});
|
|
120
84
|
};
|
|
121
85
|
|
|
122
|
-
|
|
86
|
+
const isActive = _fp.default.includes(activeTool.type, group === null || group === void 0 ? void 0 : group.tools);
|
|
123
87
|
|
|
124
|
-
|
|
125
|
-
(0, _react.useEffect)(
|
|
88
|
+
const groupIcon = (_ref2 = isActive ? activeTool.icon : group.img) !== null && _ref2 !== void 0 ? _ref2 : group.title;
|
|
89
|
+
(0, _react.useEffect)(() => {
|
|
126
90
|
if (!isOpen) return;
|
|
127
91
|
|
|
128
|
-
|
|
92
|
+
const closePanel = () => {
|
|
129
93
|
setIsOpen(false);
|
|
130
94
|
};
|
|
131
95
|
|
|
132
96
|
document.addEventListener('click', closePanel);
|
|
133
|
-
return
|
|
97
|
+
return () => {
|
|
134
98
|
document.removeEventListener('click', closePanel);
|
|
135
99
|
};
|
|
136
100
|
}, [isOpen]);
|
|
137
|
-
|
|
138
|
-
return withMenu ? /*#__PURE__*/_react
|
|
101
|
+
const withMenu = withActionsInMenu || withUploadPicture || withUrlPicture || withLoadAndSave || withExport;
|
|
102
|
+
return withMenu ? /*#__PURE__*/_react.default.createElement(StyledRelative, null, /*#__PURE__*/_react.default.createElement(_Button.default, {
|
|
139
103
|
selected: isActive,
|
|
140
104
|
title: group.title,
|
|
141
105
|
disabled: disabled,
|
|
142
106
|
onClick: openPanel,
|
|
143
107
|
icon: groupIcon
|
|
144
|
-
}), isOpen && /*#__PURE__*/_react
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
},
|
|
108
|
+
}), isOpen && /*#__PURE__*/_react.default.createElement(_Panel.default, {
|
|
109
|
+
alignment: alignment,
|
|
110
|
+
position: "top"
|
|
111
|
+
}, /*#__PURE__*/_react.default.createElement(StyledPanelContent, {
|
|
112
|
+
"data-vertical": +vertical
|
|
113
|
+
}, withActionsInMenu && /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_Tool.default, {
|
|
148
114
|
withText: true,
|
|
149
115
|
type: _tools.UNDO_TOOL,
|
|
150
116
|
disabled: disabled || !hasActionToUndo,
|
|
151
117
|
img: _tools.UNDO_TOOL.icon,
|
|
152
118
|
isActive: activeTool.id === _tools.UNDO_TOOL.id,
|
|
153
119
|
setActive: undoAction
|
|
154
|
-
}), /*#__PURE__*/_react
|
|
120
|
+
}), /*#__PURE__*/_react.default.createElement(_Tool.default, {
|
|
155
121
|
withText: true,
|
|
156
122
|
type: _tools.REDO_TOOL,
|
|
157
123
|
disabled: disabled || !hasActionToRedo,
|
|
158
124
|
img: _tools.REDO_TOOL.icon,
|
|
159
125
|
isActive: activeTool.id === _tools.REDO_TOOL.id,
|
|
160
126
|
setActive: redoAction
|
|
161
|
-
}), /*#__PURE__*/_react
|
|
127
|
+
}), /*#__PURE__*/_react.default.createElement(_Tool.default, {
|
|
162
128
|
withText: true,
|
|
163
129
|
type: _tools.CLEAR_TOOL,
|
|
164
130
|
disabled: disabled || !hasActionToClear,
|
|
165
131
|
img: _tools.CLEAR_TOOL.icon,
|
|
166
132
|
isActive: activeTool.id === _tools.CLEAR_TOOL.id,
|
|
167
133
|
setActive: clearCanvas
|
|
168
|
-
}), (withUploadPicture || withUrlPicture || withLoadAndSave) && /*#__PURE__*/_react
|
|
134
|
+
}), (withUploadPicture || withUrlPicture || withLoadAndSave) && /*#__PURE__*/_react.default.createElement("hr", null)), withUploadPicture && /*#__PURE__*/_react.default.createElement(_LoadFileTool.default, {
|
|
169
135
|
withText: true,
|
|
170
136
|
type: _tools.UPLOAD_PICTURE_TOOL,
|
|
171
137
|
disabled: disabled,
|
|
172
138
|
loadFile: addPicture,
|
|
173
139
|
img: _tools.UPLOAD_PICTURE_TOOL.icon,
|
|
174
140
|
accept: "image/png, image/gif, image/jpeg"
|
|
175
|
-
}), withUrlPicture && /*#__PURE__*/_react
|
|
141
|
+
}), withUrlPicture && /*#__PURE__*/_react.default.createElement(_Button.default, {
|
|
176
142
|
disabled: disabled,
|
|
177
143
|
selected: false,
|
|
178
144
|
onClick: togglePictureUrlModal,
|
|
179
145
|
title: "Add picture from URL",
|
|
180
146
|
icon: _icons.publicIcon,
|
|
181
147
|
children: "Add picture from URL"
|
|
182
|
-
}), (withUploadPicture || withUrlPicture) && withLoadAndSave && /*#__PURE__*/_react
|
|
148
|
+
}), (withUploadPicture || withUrlPicture) && withLoadAndSave && /*#__PURE__*/_react.default.createElement("hr", null), withLoadAndSave && /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_LoadFileTool.default, {
|
|
183
149
|
withText: true,
|
|
184
150
|
type: _tools.LOAD_TOOL,
|
|
185
151
|
disabled: disabled,
|
|
186
152
|
loadFile: loadFile,
|
|
187
153
|
img: _tools.LOAD_TOOL.icon,
|
|
188
154
|
accept: "application/JSON"
|
|
189
|
-
}), /*#__PURE__*/_react
|
|
155
|
+
}), /*#__PURE__*/_react.default.createElement(_Tool.default, {
|
|
190
156
|
withText: true,
|
|
191
157
|
disabled: disabled,
|
|
192
158
|
type: _tools.SAVE_TOOL,
|
|
193
159
|
img: _tools.SAVE_TOOL.icon,
|
|
194
160
|
isActive: activeTool.id === _tools.SAVE_TOOL.id,
|
|
195
161
|
setActive: saveFile
|
|
196
|
-
})), withExport && /*#__PURE__*/_react
|
|
162
|
+
})), withExport && /*#__PURE__*/_react.default.createElement(_Tool.default, {
|
|
197
163
|
withText: true,
|
|
198
164
|
disabled: disabled,
|
|
199
165
|
type: _tools.EXPORT_TOOL,
|
|
200
166
|
img: _tools.EXPORT_TOOL.icon,
|
|
201
167
|
isActive: activeTool.id === _tools.EXPORT_TOOL.id,
|
|
202
168
|
setActive: exportCanvasInFile
|
|
203
|
-
}))) : null;
|
|
169
|
+
})))) : null;
|
|
204
170
|
};
|
|
205
171
|
|
|
206
172
|
var _default = MenuGroup;
|
|
207
|
-
exports
|
|
173
|
+
exports.default = _default;
|