@yorab/react-paint 0.6.5 → 0.6.6
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 +2 -0
- package/dist/components/App.js +224 -384
- package/dist/components/Canvas.js +104 -114
- package/dist/components/common/Button.js +41 -50
- package/dist/components/common/Loading.js +21 -33
- package/dist/components/common/Modal.js +18 -17
- package/dist/components/common/Panel.js +20 -24
- package/dist/components/common/Snackbar.js +27 -34
- package/dist/components/settings/ColorField.js +59 -68
- package/dist/components/settings/DeleteButton.js +10 -9
- package/dist/components/settings/FontFamilyField.js +24 -19
- package/dist/components/settings/LayoutButton.js +11 -9
- package/dist/components/settings/Layouts.js +93 -103
- 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 +95 -118
- package/dist/components/settings/ToggleField.js +18 -25
- package/dist/components/toolbox/EditTextBox.js +53 -42
- package/dist/components/toolbox/LoadFileTool.js +19 -21
- package/dist/components/toolbox/MenuGroup.js +60 -96
- package/dist/components/toolbox/PictureUrlInput.js +33 -62
- package/dist/components/toolbox/Tool.js +13 -13
- package/dist/components/toolbox/Toolbar.js +74 -106
- package/dist/components/toolbox/ToolbarGroup.js +41 -57
- package/dist/constants/icons.js +43 -43
- package/dist/constants/shapes.js +6 -6
- package/dist/constants/snackbar.js +3 -3
- package/dist/constants/style.js +13 -13
- package/dist/constants/tools.js +80 -80
- package/dist/hooks/useComponent.js +12 -19
- package/dist/hooks/useDoubleClick.js +12 -12
- package/dist/hooks/useDrag.js +24 -32
- package/dist/hooks/useDrawableCanvas.js +86 -100
- package/dist/hooks/useKeyboard.js +26 -36
- package/dist/hooks/useResizeObserver.js +18 -16
- package/dist/hooks/useShapes.js +91 -143
- package/dist/hooks/useSnackbar.js +28 -58
- package/dist/styles.css +55 -55
- package/dist/types/Mode.js +1 -1
- package/dist/types/Shapes.js +1 -1
- package/dist/types/keyboard.js +2 -2
- package/dist/types/tools.js +1 -1
- package/dist/utils/data.js +91 -107
- package/dist/utils/draw.js +116 -146
- package/dist/utils/file.js +69 -119
- package/dist/utils/intersect.js +57 -97
- package/dist/utils/selection.js +12 -12
- package/dist/utils/shapeData.js +33 -51
- package/dist/utils/string.js +10 -16
- package/dist/utils/style.js +1 -1
- package/dist/utils/toolbar.js +26 -38
- package/dist/utils/transform.js +183 -239
- package/package.json +6 -5
- package/Changelog.md +0 -123
|
@@ -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
|
|
|
@@ -21,84 +19,97 @@ var _string = require("../../utils/string");
|
|
|
21
19
|
|
|
22
20
|
var _transform = require("../../utils/transform");
|
|
23
21
|
|
|
24
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function
|
|
22
|
+
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); }
|
|
25
23
|
|
|
26
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null ||
|
|
24
|
+
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; }
|
|
27
25
|
|
|
28
|
-
|
|
26
|
+
const StyledEditBox = /*#__PURE__*/(0, _react2.styled)("div")({
|
|
29
27
|
name: "StyledEditBox",
|
|
30
|
-
|
|
28
|
+
class: "s1unz6yq",
|
|
31
29
|
vars: {
|
|
32
|
-
"
|
|
33
|
-
|
|
30
|
+
"s1unz6yq-0": [_ref => {
|
|
31
|
+
let {
|
|
32
|
+
transform
|
|
33
|
+
} = _ref;
|
|
34
34
|
return transform;
|
|
35
35
|
}],
|
|
36
|
-
"
|
|
37
|
-
|
|
36
|
+
"s1unz6yq-1": [_ref2 => {
|
|
37
|
+
let {
|
|
38
|
+
color
|
|
39
|
+
} = _ref2;
|
|
38
40
|
return color;
|
|
39
41
|
}],
|
|
40
|
-
"
|
|
41
|
-
|
|
42
|
+
"s1unz6yq-2": [_ref3 => {
|
|
43
|
+
let {
|
|
44
|
+
padding
|
|
45
|
+
} = _ref3;
|
|
42
46
|
return padding;
|
|
43
47
|
}, "px"],
|
|
44
|
-
"
|
|
45
|
-
|
|
48
|
+
"s1unz6yq-3": [_ref4 => {
|
|
49
|
+
let {
|
|
50
|
+
fontsize
|
|
51
|
+
} = _ref4;
|
|
46
52
|
return fontsize;
|
|
47
53
|
}, "px"],
|
|
48
|
-
"
|
|
49
|
-
|
|
54
|
+
"s1unz6yq-5": [_ref5 => {
|
|
55
|
+
let {
|
|
56
|
+
fontfamily
|
|
57
|
+
} = _ref5;
|
|
50
58
|
return fontfamily;
|
|
51
59
|
}],
|
|
52
|
-
"
|
|
53
|
-
|
|
60
|
+
"s1unz6yq-6": [_ref6 => {
|
|
61
|
+
let {
|
|
62
|
+
opacity
|
|
63
|
+
} = _ref6;
|
|
54
64
|
return opacity;
|
|
55
65
|
}]
|
|
56
66
|
}
|
|
57
67
|
});
|
|
58
68
|
|
|
59
|
-
|
|
69
|
+
const EditTextBox = _ref7 => {
|
|
60
70
|
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
71
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
+
let {
|
|
73
|
+
disabled = false,
|
|
74
|
+
scaleRatio,
|
|
75
|
+
shape,
|
|
76
|
+
defaultValue,
|
|
77
|
+
updateValue,
|
|
78
|
+
selectionPadding
|
|
79
|
+
} = _ref7;
|
|
80
|
+
const ref = (0, _react.useRef)(null);
|
|
81
|
+
|
|
82
|
+
const updateContentEditable = e => {
|
|
72
83
|
updateValue((0, _string.convertDivContentToStringArray)(e.target.innerHTML));
|
|
73
84
|
};
|
|
74
85
|
|
|
75
|
-
(0, _react.useEffect)(
|
|
86
|
+
(0, _react.useEffect)(() => {
|
|
76
87
|
if (!ref.current) return;
|
|
77
|
-
|
|
88
|
+
const currentNode = ref.current;
|
|
78
89
|
|
|
79
|
-
|
|
90
|
+
const handlePaste = e => {
|
|
80
91
|
var _e$clipboardData;
|
|
81
92
|
|
|
82
93
|
e.preventDefault();
|
|
83
|
-
|
|
94
|
+
const text = (_e$clipboardData = e.clipboardData) === null || _e$clipboardData === void 0 ? void 0 : _e$clipboardData.getData('text/plain');
|
|
84
95
|
document.execCommand('insertText', false, text); //TODO use Clipboard API when ready
|
|
85
96
|
};
|
|
86
97
|
|
|
87
98
|
currentNode.addEventListener('paste', handlePaste);
|
|
88
99
|
currentNode.innerHTML = (0, _string.convertStringArrayToDivContent)(defaultValue);
|
|
89
100
|
currentNode.focus();
|
|
90
|
-
return
|
|
101
|
+
return () => {
|
|
91
102
|
currentNode.removeEventListener('paste', handlePaste);
|
|
92
103
|
};
|
|
93
104
|
}, [defaultValue]);
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
105
|
+
const position = (0, _react.useMemo)(() => {
|
|
106
|
+
const {
|
|
107
|
+
borders,
|
|
108
|
+
center
|
|
109
|
+
} = (0, _shapeData.getShapeInfos)(shape, selectionPadding);
|
|
99
110
|
return (0, _intersect.getPointPositionBeforeCanvasTransformation)([borders.x, borders.y], [-shape.translation[0], -shape.translation[1]], shape.rotation, center);
|
|
100
111
|
}, [shape, selectionPadding]);
|
|
101
|
-
return /*#__PURE__*/_react
|
|
112
|
+
return /*#__PURE__*/_react.default.createElement(StyledEditBox, {
|
|
102
113
|
ref: ref,
|
|
103
114
|
transform: "translate3D(".concat(position[0] * scaleRatio, "px, ").concat(position[1] * scaleRatio, "px, 0) rotate(").concat((0, _transform.radiansToDegrees)(shape.rotation), "deg)"),
|
|
104
115
|
fontsize: shape.fontSize * scaleRatio,
|
|
@@ -114,4 +125,4 @@ var EditTextBox = function EditTextBox(_ref7) {
|
|
|
114
125
|
};
|
|
115
126
|
|
|
116
127
|
var _default = EditTextBox;
|
|
117
|
-
exports
|
|
128
|
+
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,167 +25,139 @@ 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
|
-
|
|
32
|
+
const StyledPanel = /*#__PURE__*/(0, _react2.styled)(_Panel.default)({
|
|
41
33
|
name: "StyledPanel",
|
|
42
|
-
|
|
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
|
|
108
|
+
}), isOpen && /*#__PURE__*/_react.default.createElement(StyledPanel, {
|
|
145
109
|
vertical: vertical,
|
|
146
110
|
alignment: alignment
|
|
147
|
-
}, withActionsInMenu && /*#__PURE__*/_react
|
|
111
|
+
}, withActionsInMenu && /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_Tool.default, {
|
|
148
112
|
withText: true,
|
|
149
113
|
type: _tools.UNDO_TOOL,
|
|
150
114
|
disabled: disabled || !hasActionToUndo,
|
|
151
115
|
img: _tools.UNDO_TOOL.icon,
|
|
152
116
|
isActive: activeTool.id === _tools.UNDO_TOOL.id,
|
|
153
117
|
setActive: undoAction
|
|
154
|
-
}), /*#__PURE__*/_react
|
|
118
|
+
}), /*#__PURE__*/_react.default.createElement(_Tool.default, {
|
|
155
119
|
withText: true,
|
|
156
120
|
type: _tools.REDO_TOOL,
|
|
157
121
|
disabled: disabled || !hasActionToRedo,
|
|
158
122
|
img: _tools.REDO_TOOL.icon,
|
|
159
123
|
isActive: activeTool.id === _tools.REDO_TOOL.id,
|
|
160
124
|
setActive: redoAction
|
|
161
|
-
}), /*#__PURE__*/_react
|
|
125
|
+
}), /*#__PURE__*/_react.default.createElement(_Tool.default, {
|
|
162
126
|
withText: true,
|
|
163
127
|
type: _tools.CLEAR_TOOL,
|
|
164
128
|
disabled: disabled || !hasActionToClear,
|
|
165
129
|
img: _tools.CLEAR_TOOL.icon,
|
|
166
130
|
isActive: activeTool.id === _tools.CLEAR_TOOL.id,
|
|
167
131
|
setActive: clearCanvas
|
|
168
|
-
}), (withUploadPicture || withUrlPicture || withLoadAndSave) && /*#__PURE__*/_react
|
|
132
|
+
}), (withUploadPicture || withUrlPicture || withLoadAndSave) && /*#__PURE__*/_react.default.createElement("hr", null)), withUploadPicture && /*#__PURE__*/_react.default.createElement(_LoadFileTool.default, {
|
|
169
133
|
withText: true,
|
|
170
134
|
type: _tools.UPLOAD_PICTURE_TOOL,
|
|
171
135
|
disabled: disabled,
|
|
172
136
|
loadFile: addPicture,
|
|
173
137
|
img: _tools.UPLOAD_PICTURE_TOOL.icon,
|
|
174
138
|
accept: "image/png, image/gif, image/jpeg"
|
|
175
|
-
}), withUrlPicture && /*#__PURE__*/_react
|
|
139
|
+
}), withUrlPicture && /*#__PURE__*/_react.default.createElement(_Button.default, {
|
|
176
140
|
disabled: disabled,
|
|
177
141
|
selected: false,
|
|
178
142
|
onClick: togglePictureUrlModal,
|
|
179
143
|
title: "Add picture from URL",
|
|
180
144
|
icon: _icons.publicIcon,
|
|
181
145
|
children: "Add picture from URL"
|
|
182
|
-
}), (withUploadPicture || withUrlPicture) && withLoadAndSave && /*#__PURE__*/_react
|
|
146
|
+
}), (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
147
|
withText: true,
|
|
184
148
|
type: _tools.LOAD_TOOL,
|
|
185
149
|
disabled: disabled,
|
|
186
150
|
loadFile: loadFile,
|
|
187
151
|
img: _tools.LOAD_TOOL.icon,
|
|
188
152
|
accept: "application/JSON"
|
|
189
|
-
}), /*#__PURE__*/_react
|
|
153
|
+
}), /*#__PURE__*/_react.default.createElement(_Tool.default, {
|
|
190
154
|
withText: true,
|
|
191
155
|
disabled: disabled,
|
|
192
156
|
type: _tools.SAVE_TOOL,
|
|
193
157
|
img: _tools.SAVE_TOOL.icon,
|
|
194
158
|
isActive: activeTool.id === _tools.SAVE_TOOL.id,
|
|
195
159
|
setActive: saveFile
|
|
196
|
-
})), withExport && /*#__PURE__*/_react
|
|
160
|
+
})), withExport && /*#__PURE__*/_react.default.createElement(_Tool.default, {
|
|
197
161
|
withText: true,
|
|
198
162
|
disabled: disabled,
|
|
199
163
|
type: _tools.EXPORT_TOOL,
|
|
@@ -204,4 +168,4 @@ var MenuGroup = function MenuGroup(_ref) {
|
|
|
204
168
|
};
|
|
205
169
|
|
|
206
170
|
var _default = MenuGroup;
|
|
207
|
-
exports
|
|
171
|
+
exports.default = _default;
|