@yorab/react-paint 0.2.2 → 0.4.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/Changelog.md +44 -0
- package/LICENSE.txt +21 -0
- package/README.md +9 -90
- package/dist/components/App.js +233 -113
- package/dist/components/Canvas.js +45 -21
- package/dist/components/settings/ColorField.js +3 -7
- package/dist/components/settings/LayoutButton.js +3 -3
- package/dist/components/settings/Layouts.js +6 -19
- package/dist/components/settings/SettingsBar.js +3 -3
- package/dist/components/toolbox/EditTextBox.js +20 -13
- package/dist/components/toolbox/MenuGroup.js +48 -5
- package/dist/components/toolbox/PictureUrlInput.js +8 -7
- package/dist/components/toolbox/Toolbar.js +56 -33
- package/dist/components/toolbox/ToolbarGroup.js +3 -3
- package/dist/constants/shapes.js +7 -3
- package/dist/hooks/useDrawableCanvas.js +23 -20
- package/dist/hooks/useResizeObserver.js +40 -0
- package/dist/hooks/useShapes.js +14 -9
- package/dist/styles.css +32 -35
- package/dist/types/utils.js +5 -0
- package/dist/utils/data.js +71 -19
- package/dist/utils/draw.js +90 -51
- package/dist/utils/file.js +26 -60
- package/dist/utils/intersect.js +22 -18
- package/dist/utils/selection.js +6 -6
- package/dist/utils/shapeData.js +49 -54
- package/dist/utils/transform.js +48 -34
- package/package.json +6 -7
- package/dist/components/App.d.ts +0 -20
- package/dist/components/Canvas.d.ts +0 -28
- package/dist/components/common/Button.d.ts +0 -14
- package/dist/components/common/Loading.d.ts +0 -6
- package/dist/components/common/Modal.d.ts +0 -8
- package/dist/components/common/Panel.d.ts +0 -10
- package/dist/components/common/Snackbar.d.ts +0 -7
- package/dist/components/settings/ColorField.d.ts +0 -12
- package/dist/components/settings/DeleteButton.d.ts +0 -9
- package/dist/components/settings/FontFamilyField.d.ts +0 -10
- package/dist/components/settings/LayoutButton.d.ts +0 -8
- package/dist/components/settings/Layouts.d.ts +0 -18
- package/dist/components/settings/LineArrowField.d.ts +0 -10
- package/dist/components/settings/LineTypeField.d.ts +0 -14
- package/dist/components/settings/PointsNumberField.d.ts +0 -11
- package/dist/components/settings/RangeField.d.ts +0 -16
- package/dist/components/settings/SelectField.d.ts +0 -16
- package/dist/components/settings/SettingsBar.d.ts +0 -16
- package/dist/components/toolbox/EditTextBox.d.ts +0 -10
- package/dist/components/toolbox/LoadFileTool.d.ts +0 -11
- package/dist/components/toolbox/MenuGroup.d.ts +0 -23
- package/dist/components/toolbox/PictureUrlInput.d.ts +0 -7
- package/dist/components/toolbox/Tool.d.ts +0 -13
- package/dist/components/toolbox/Toolbar.d.ts +0 -20
- package/dist/components/toolbox/ToolbarGroup.d.ts +0 -18
- package/dist/constants/draw.d.ts +0 -2
- package/dist/constants/draw.js +0 -10
- package/dist/constants/icons.d.ts +0 -36
- package/dist/constants/shapes.d.ts +0 -5
- package/dist/constants/snackbar.d.ts +0 -11
- package/dist/constants/style.d.ts +0 -12
- package/dist/hooks/useComponent.d.ts +0 -9
- package/dist/hooks/useDrag.d.ts +0 -15
- package/dist/hooks/useDrawableCanvas.d.ts +0 -30
- package/dist/hooks/useKeyboard.d.ts +0 -15
- package/dist/hooks/useShapes.d.ts +0 -22
- package/dist/hooks/useSnackbar.d.ts +0 -16
- package/dist/schemas/drawableShape.json +0 -1021
- package/dist/types/Mode.d.ts +0 -51
- package/dist/types/Shapes.d.ts +0 -122
- package/dist/types/keyboard.d.ts +0 -15
- package/dist/utils/data.d.ts +0 -4
- package/dist/utils/draw.d.ts +0 -18
- package/dist/utils/file.d.ts +0 -33
- package/dist/utils/intersect.d.ts +0 -8
- package/dist/utils/selection.d.ts +0 -7
- package/dist/utils/shapeData.d.ts +0 -5
- package/dist/utils/string.d.ts +0 -3
- package/dist/utils/style.d.ts +0 -2
- package/dist/utils/toolbar.d.ts +0 -12
- package/dist/utils/transform.d.ts +0 -271
package/dist/components/App.js
CHANGED
|
@@ -15,6 +15,8 @@ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/
|
|
|
15
15
|
|
|
16
16
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
17
17
|
|
|
18
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
19
|
+
|
|
18
20
|
var _react = _interopRequireWildcard(require("react"));
|
|
19
21
|
|
|
20
22
|
var _fp = _interopRequireDefault(require("lodash/fp"));
|
|
@@ -51,21 +53,67 @@ var _snackbar = require("../constants/snackbar");
|
|
|
51
53
|
|
|
52
54
|
var _Loading = _interopRequireDefault(require("./common/Loading"));
|
|
53
55
|
|
|
56
|
+
var _data = require("../utils/data");
|
|
57
|
+
|
|
58
|
+
var _useResizeObserver = _interopRequireDefault(require("../hooks/useResizeObserver"));
|
|
59
|
+
|
|
60
|
+
var _shapes = require("../constants/shapes");
|
|
61
|
+
|
|
54
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); }
|
|
55
63
|
|
|
56
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; }
|
|
57
65
|
|
|
66
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
67
|
+
|
|
68
|
+
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; }
|
|
69
|
+
|
|
58
70
|
var StyledApp = /*#__PURE__*/(0, _react2.styled)("div")({
|
|
59
71
|
name: "StyledApp",
|
|
60
72
|
"class": "s1v9piyg",
|
|
61
73
|
vars: {
|
|
62
|
-
"s1v9piyg-0": [function (
|
|
63
|
-
|
|
64
|
-
return "min(100%, ".concat(width, "px)");
|
|
74
|
+
"s1v9piyg-0": [function (props) {
|
|
75
|
+
return props.toolbarBackgroundColor;
|
|
65
76
|
}],
|
|
66
|
-
"s1v9piyg-1": [function (
|
|
67
|
-
|
|
68
|
-
|
|
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;
|
|
97
|
+
}],
|
|
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;
|
|
69
117
|
}, "px"]
|
|
70
118
|
}
|
|
71
119
|
});
|
|
@@ -84,29 +132,90 @@ var StyledRow = /*#__PURE__*/(0, _react2.styled)("div")({
|
|
|
84
132
|
}
|
|
85
133
|
});
|
|
86
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];
|
|
135
|
+
var DEFAULT_OPTIONS = {
|
|
136
|
+
layersManipulation: true,
|
|
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
|
+
}
|
|
160
|
+
};
|
|
87
161
|
|
|
88
162
|
var App = function App(_ref5) {
|
|
163
|
+
var _options$uiStyle;
|
|
164
|
+
|
|
89
165
|
var _ref5$width = _ref5.width,
|
|
90
|
-
|
|
166
|
+
canvasWidth = _ref5$width === void 0 ? 1000 : _ref5$width,
|
|
91
167
|
_ref5$height = _ref5.height,
|
|
92
|
-
|
|
93
|
-
_ref5$canGrow = _ref5.canGrow,
|
|
94
|
-
canGrow = _ref5$canGrow === void 0 ? false : _ref5$canGrow,
|
|
95
|
-
_ref5$canShrink = _ref5.canShrink,
|
|
96
|
-
canShrink = _ref5$canShrink === void 0 ? true : _ref5$canShrink,
|
|
97
|
-
_ref5$withLayouts = _ref5.withLayouts,
|
|
98
|
-
withLayouts = _ref5$withLayouts === void 0 ? 'hidden' : _ref5$withLayouts,
|
|
168
|
+
canvasHeight = _ref5$height === void 0 ? 600 : _ref5$height,
|
|
99
169
|
shapesFromProps = _ref5.shapes,
|
|
100
170
|
classNameFromProps = _ref5.className,
|
|
171
|
+
_ref5$mode = _ref5.mode,
|
|
172
|
+
mode = _ref5$mode === void 0 ? 'editor' : _ref5$mode,
|
|
101
173
|
_ref5$disabled = _ref5.disabled,
|
|
102
|
-
|
|
174
|
+
disabledFromProps = _ref5$disabled === void 0 ? false : _ref5$disabled,
|
|
103
175
|
onDataChanged = _ref5.onDataChanged,
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
176
|
+
apiRef = _ref5.apiRef,
|
|
177
|
+
options = _ref5.options;
|
|
178
|
+
|
|
179
|
+
var _DEFAULT_OPTIONS$opti = _objectSpread(_objectSpread({}, DEFAULT_OPTIONS), options),
|
|
180
|
+
layersManipulation = _DEFAULT_OPTIONS$opti.layersManipulation,
|
|
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;
|
|
204
|
+
|
|
205
|
+
var isEditMode = mode !== 'viewer';
|
|
206
|
+
var disabled = disabledFromProps || !isEditMode;
|
|
107
207
|
var componentRef = (0, _react.useRef)(null);
|
|
108
208
|
var canvasRef = (0, _react.useRef)(null);
|
|
109
209
|
|
|
210
|
+
var _useState = (0, _react.useState)({
|
|
211
|
+
width: canvasWidth,
|
|
212
|
+
height: canvasHeight,
|
|
213
|
+
scaleRatio: 1
|
|
214
|
+
}),
|
|
215
|
+
_useState2 = (0, _slicedToArray2["default"])(_useState, 2),
|
|
216
|
+
canvasSize = _useState2[0],
|
|
217
|
+
setCanvasSize = _useState2[1];
|
|
218
|
+
|
|
110
219
|
var availableTools = _fp["default"].intersection(DEFAULT_TOOLS, availableToolsFromProps);
|
|
111
220
|
|
|
112
221
|
var _useComponent = (0, _useComponent2["default"])({
|
|
@@ -115,7 +224,7 @@ var App = function App(_ref5) {
|
|
|
115
224
|
}),
|
|
116
225
|
isInsideComponent = _useComponent.isInsideComponent;
|
|
117
226
|
|
|
118
|
-
var
|
|
227
|
+
var _useState3 = (0, _react.useState)({
|
|
119
228
|
style: {
|
|
120
229
|
fillColor: 'transparent',
|
|
121
230
|
strokeColor: 'black',
|
|
@@ -127,46 +236,46 @@ var App = function App(_ref5) {
|
|
|
127
236
|
fontFamily: _style.STYLE_FONT_DEFAULT
|
|
128
237
|
}
|
|
129
238
|
}),
|
|
130
|
-
_useState2 = (0, _slicedToArray2["default"])(_useState, 2),
|
|
131
|
-
defaultConf = _useState2[0],
|
|
132
|
-
setDefaultConf = _useState2[1];
|
|
133
|
-
|
|
134
|
-
var _useState3 = (0, _react.useState)(false),
|
|
135
239
|
_useState4 = (0, _slicedToArray2["default"])(_useState3, 2),
|
|
136
|
-
|
|
137
|
-
|
|
240
|
+
defaultConf = _useState4[0],
|
|
241
|
+
setDefaultConf = _useState4[1];
|
|
138
242
|
|
|
139
|
-
var _useState5 = (0, _react.useState)(
|
|
243
|
+
var _useState5 = (0, _react.useState)(false),
|
|
140
244
|
_useState6 = (0, _slicedToArray2["default"])(_useState5, 2),
|
|
141
|
-
|
|
142
|
-
|
|
245
|
+
isLoading = _useState6[0],
|
|
246
|
+
setIsLoading = _useState6[1];
|
|
143
247
|
|
|
144
|
-
var _useState7 = (0, _react.useState)(
|
|
248
|
+
var _useState7 = (0, _react.useState)(false),
|
|
145
249
|
_useState8 = (0, _slicedToArray2["default"])(_useState7, 2),
|
|
146
|
-
|
|
147
|
-
|
|
250
|
+
isLayoutPanelShown = _useState8[0],
|
|
251
|
+
setIsLayoutPanelShown = _useState8[1];
|
|
148
252
|
|
|
149
|
-
var _useState9 = (0, _react.useState)(
|
|
253
|
+
var _useState9 = (0, _react.useState)([0, 0]),
|
|
150
254
|
_useState10 = (0, _slicedToArray2["default"])(_useState9, 2),
|
|
151
|
-
|
|
152
|
-
|
|
255
|
+
canvasOffset = _useState10[0],
|
|
256
|
+
setCanvasOffset = _useState10[1];
|
|
153
257
|
|
|
154
|
-
var _useState11 = (0, _react.useState)(
|
|
258
|
+
var _useState11 = (0, _react.useState)(undefined),
|
|
155
259
|
_useState12 = (0, _slicedToArray2["default"])(_useState11, 2),
|
|
156
|
-
|
|
157
|
-
|
|
260
|
+
canvasOffsetStartPosition = _useState12[0],
|
|
261
|
+
setCanvasOffsetStartPosition = _useState12[1];
|
|
158
262
|
|
|
159
|
-
var _useState13 = (0, _react.useState)(
|
|
160
|
-
mode: _Mode.SelectionModeLib["default"]
|
|
161
|
-
}),
|
|
263
|
+
var _useState13 = (0, _react.useState)(_Shapes.ToolEnum.selection),
|
|
162
264
|
_useState14 = (0, _slicedToArray2["default"])(_useState13, 2),
|
|
163
|
-
|
|
164
|
-
|
|
265
|
+
activeTool = _useState14[0],
|
|
266
|
+
setActiveTool = _useState14[1];
|
|
165
267
|
|
|
166
|
-
var _useState15 = (0, _react.useState)(
|
|
268
|
+
var _useState15 = (0, _react.useState)({
|
|
269
|
+
mode: _Mode.SelectionModeLib["default"]
|
|
270
|
+
}),
|
|
167
271
|
_useState16 = (0, _slicedToArray2["default"])(_useState15, 2),
|
|
168
|
-
|
|
169
|
-
|
|
272
|
+
selectionMode = _useState16[0],
|
|
273
|
+
setSelectionMode = _useState16[1];
|
|
274
|
+
|
|
275
|
+
var _useState17 = (0, _react.useState)(gridVisible),
|
|
276
|
+
_useState18 = (0, _slicedToArray2["default"])(_useState17, 2),
|
|
277
|
+
withGrid = _useState18[0],
|
|
278
|
+
setWithGrid = _useState18[1];
|
|
170
279
|
|
|
171
280
|
var _useShapes = (0, _useShapes2["default"])(onDataChanged),
|
|
172
281
|
shapesRef = _useShapes.shapesRef,
|
|
@@ -222,17 +331,13 @@ var App = function App(_ref5) {
|
|
|
222
331
|
setIsLoading(true);
|
|
223
332
|
|
|
224
333
|
try {
|
|
225
|
-
var dataURL = canvasRef.current && (0, _file.getCanvasImage)(
|
|
334
|
+
var dataURL = canvasRef.current && (0, _file.getCanvasImage)(shapesRef.current, canvasOffset, canvasWidth, canvasHeight, canvasSelectionPadding);
|
|
226
335
|
|
|
227
336
|
if (!dataURL) {
|
|
228
337
|
throw new Error();
|
|
229
338
|
}
|
|
230
339
|
|
|
231
340
|
(0, _file.downloadFile)(dataURL, 'drawing.png');
|
|
232
|
-
addSnackbar({
|
|
233
|
-
type: _snackbar.SnackbarTypeEnum.Success,
|
|
234
|
-
text: 'Export terminé !'
|
|
235
|
-
});
|
|
236
341
|
setIsLoading(false);
|
|
237
342
|
} catch (e) {
|
|
238
343
|
if (e instanceof Error) {
|
|
@@ -240,13 +345,13 @@ var App = function App(_ref5) {
|
|
|
240
345
|
type: _snackbar.SnackbarTypeEnum.Error,
|
|
241
346
|
text: "L'export a échoué"
|
|
242
347
|
});
|
|
243
|
-
} else {
|
|
244
|
-
console.warn(e);
|
|
245
348
|
}
|
|
349
|
+
|
|
350
|
+
console.warn(e);
|
|
246
351
|
} finally {
|
|
247
352
|
setIsLoading(false);
|
|
248
353
|
}
|
|
249
|
-
}, [addSnackbar]);
|
|
354
|
+
}, [addSnackbar, shapesRef, canvasOffset, canvasWidth, canvasHeight, canvasSelectionPadding]);
|
|
250
355
|
var saveFile = (0, _react.useCallback)(function () {
|
|
251
356
|
setIsLoading(true);
|
|
252
357
|
|
|
@@ -254,53 +359,39 @@ var App = function App(_ref5) {
|
|
|
254
359
|
var content = (0, _file.encodeShapesInString)(shapesRef.current);
|
|
255
360
|
|
|
256
361
|
if (!content) {
|
|
257
|
-
throw new Error("L'
|
|
362
|
+
throw new Error("L'encodage a échoué");
|
|
258
363
|
}
|
|
259
364
|
|
|
260
365
|
(0, _file.downloadFile)(content, 'drawing.json');
|
|
261
|
-
addSnackbar({
|
|
262
|
-
type: _snackbar.SnackbarTypeEnum.Success,
|
|
263
|
-
text: 'Fichier enregistré !'
|
|
264
|
-
});
|
|
265
366
|
setIsLoading(false);
|
|
266
367
|
} catch (e) {
|
|
267
368
|
if (e instanceof Error) {
|
|
268
369
|
addSnackbar({
|
|
269
370
|
type: _snackbar.SnackbarTypeEnum.Error,
|
|
270
|
-
text:
|
|
371
|
+
text: "L'enregistrement a échoué"
|
|
271
372
|
});
|
|
272
|
-
} else {
|
|
273
|
-
console.warn(e);
|
|
274
373
|
}
|
|
374
|
+
|
|
375
|
+
console.warn(e);
|
|
275
376
|
} finally {
|
|
276
377
|
setIsLoading(false);
|
|
277
378
|
}
|
|
278
379
|
}, [shapesRef, addSnackbar]);
|
|
279
380
|
var loadJson = (0, _react.useCallback)( /*#__PURE__*/function () {
|
|
280
381
|
var _ref6 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(json) {
|
|
281
|
-
var
|
|
382
|
+
var shapes;
|
|
282
383
|
return _regenerator["default"].wrap(function _callee$(_context) {
|
|
283
384
|
while (1) {
|
|
284
385
|
switch (_context.prev = _context.next) {
|
|
285
386
|
case 0:
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
if (isValidated) {
|
|
289
|
-
_context.next = 3;
|
|
290
|
-
break;
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
throw new Error('Le fichier est corrompu');
|
|
294
|
-
|
|
295
|
-
case 3:
|
|
296
|
-
_context.next = 5;
|
|
387
|
+
_context.next = 2;
|
|
297
388
|
return (0, _file.decodePicturesInShapes)(json);
|
|
298
389
|
|
|
299
|
-
case
|
|
390
|
+
case 2:
|
|
300
391
|
shapes = _context.sent;
|
|
301
392
|
clearCanvas(shapes, true);
|
|
302
393
|
|
|
303
|
-
case
|
|
394
|
+
case 4:
|
|
304
395
|
case "end":
|
|
305
396
|
return _context.stop();
|
|
306
397
|
}
|
|
@@ -334,7 +425,7 @@ var App = function App(_ref5) {
|
|
|
334
425
|
type: _snackbar.SnackbarTypeEnum.Success,
|
|
335
426
|
text: 'Fichier chargé !'
|
|
336
427
|
});
|
|
337
|
-
_context2.next =
|
|
428
|
+
_context2.next = 14;
|
|
338
429
|
break;
|
|
339
430
|
|
|
340
431
|
case 10:
|
|
@@ -344,23 +435,23 @@ var App = function App(_ref5) {
|
|
|
344
435
|
if (_context2.t0 instanceof Error) {
|
|
345
436
|
addSnackbar({
|
|
346
437
|
type: _snackbar.SnackbarTypeEnum.Error,
|
|
347
|
-
text:
|
|
438
|
+
text: 'Le chargement a échoué'
|
|
348
439
|
});
|
|
349
|
-
} else {
|
|
350
|
-
console.warn(_context2.t0);
|
|
351
440
|
}
|
|
352
441
|
|
|
353
|
-
|
|
354
|
-
|
|
442
|
+
console.warn(_context2.t0);
|
|
443
|
+
|
|
444
|
+
case 14:
|
|
445
|
+
_context2.prev = 14;
|
|
355
446
|
setIsLoading(false);
|
|
356
|
-
return _context2.finish(
|
|
447
|
+
return _context2.finish(14);
|
|
357
448
|
|
|
358
|
-
case
|
|
449
|
+
case 17:
|
|
359
450
|
case "end":
|
|
360
451
|
return _context2.stop();
|
|
361
452
|
}
|
|
362
453
|
}
|
|
363
|
-
}, _callee2, null, [[1, 10,
|
|
454
|
+
}, _callee2, null, [[1, 10, 14, 17]]);
|
|
364
455
|
}));
|
|
365
456
|
|
|
366
457
|
return function (_x2) {
|
|
@@ -377,12 +468,12 @@ var App = function App(_ref5) {
|
|
|
377
468
|
setIsLoading(true);
|
|
378
469
|
_context3.prev = 1;
|
|
379
470
|
_context3.next = 4;
|
|
380
|
-
return addPictureShape(fileOrUrl);
|
|
471
|
+
return addPictureShape(fileOrUrl, canvasWidth, canvasHeight);
|
|
381
472
|
|
|
382
473
|
case 4:
|
|
383
474
|
pictureShape = _context3.sent;
|
|
384
475
|
selectShape(pictureShape);
|
|
385
|
-
_context3.next =
|
|
476
|
+
_context3.next = 12;
|
|
386
477
|
break;
|
|
387
478
|
|
|
388
479
|
case 8:
|
|
@@ -392,29 +483,37 @@ var App = function App(_ref5) {
|
|
|
392
483
|
if (_context3.t0 instanceof Error) {
|
|
393
484
|
addSnackbar({
|
|
394
485
|
type: _snackbar.SnackbarTypeEnum.Error,
|
|
395
|
-
text:
|
|
486
|
+
text: 'Le chargement a échoué'
|
|
396
487
|
});
|
|
397
|
-
} else {
|
|
398
|
-
console.warn(_context3.t0);
|
|
399
488
|
}
|
|
400
489
|
|
|
401
|
-
|
|
402
|
-
|
|
490
|
+
console.warn(_context3.t0);
|
|
491
|
+
|
|
492
|
+
case 12:
|
|
493
|
+
_context3.prev = 12;
|
|
403
494
|
setIsLoading(false);
|
|
404
|
-
return _context3.finish(
|
|
495
|
+
return _context3.finish(12);
|
|
405
496
|
|
|
406
|
-
case
|
|
497
|
+
case 15:
|
|
407
498
|
case "end":
|
|
408
499
|
return _context3.stop();
|
|
409
500
|
}
|
|
410
501
|
}
|
|
411
|
-
}, _callee3, null, [[1, 8,
|
|
502
|
+
}, _callee3, null, [[1, 8, 12, 15]]);
|
|
412
503
|
}));
|
|
413
504
|
|
|
414
505
|
return function (_x3) {
|
|
415
506
|
return _ref8.apply(this, arguments);
|
|
416
507
|
};
|
|
417
|
-
}(), [addPictureShape, selectShape, addSnackbar]);
|
|
508
|
+
}(), [addPictureShape, selectShape, addSnackbar, canvasWidth, canvasHeight]);
|
|
509
|
+
var onResized = (0, _react.useCallback)(function (measuredWidth, measuredHeight) {
|
|
510
|
+
var scaleRatio = measuredWidth / canvasWidth;
|
|
511
|
+
setCanvasSize({
|
|
512
|
+
width: measuredWidth,
|
|
513
|
+
height: canvasHeight * scaleRatio,
|
|
514
|
+
scaleRatio: scaleRatio
|
|
515
|
+
});
|
|
516
|
+
}, [canvasWidth, canvasHeight]);
|
|
418
517
|
(0, _useKeyboard["default"])({
|
|
419
518
|
isInsideComponent: isInsideComponent,
|
|
420
519
|
isEditingText: selectionMode.mode === _Mode.SelectionModeLib.textedition,
|
|
@@ -426,6 +525,10 @@ var App = function App(_ref5) {
|
|
|
426
525
|
backwardShape: backwardShape,
|
|
427
526
|
forwardShape: forwardShape
|
|
428
527
|
});
|
|
528
|
+
(0, _useResizeObserver["default"])({
|
|
529
|
+
element: componentRef,
|
|
530
|
+
onResized: onResized
|
|
531
|
+
});
|
|
429
532
|
(0, _react.useEffect)(function () {
|
|
430
533
|
if (!isInsideComponent) setSelectedShape(undefined);
|
|
431
534
|
}, [isInsideComponent, setSelectedShape]);
|
|
@@ -438,21 +541,34 @@ var App = function App(_ref5) {
|
|
|
438
541
|
if (!apiRef) return;
|
|
439
542
|
apiRef.current = {
|
|
440
543
|
getCurrentImage: function getCurrentImage() {
|
|
441
|
-
return canvasRef.current ? (0, _file.getCanvasImage)(
|
|
544
|
+
return canvasRef.current ? (0, _file.getCanvasImage)(shapesRef.current, canvasOffset, canvasWidth, canvasHeight, canvasSelectionPadding) : undefined;
|
|
442
545
|
},
|
|
443
546
|
getCurrentData: function getCurrentData() {
|
|
444
|
-
return (0,
|
|
547
|
+
return (0, _data.cleanShapesBeforeExport)(shapesRef.current); //TODO : create different types for stored shapes
|
|
445
548
|
}
|
|
446
549
|
};
|
|
447
|
-
}, [apiRef, shapesRef]);
|
|
550
|
+
}, [apiRef, shapesRef, canvasOffset, canvasWidth, canvasHeight, canvasSelectionPadding]);
|
|
448
551
|
var className = "".concat(classNameFromProps !== null && classNameFromProps !== void 0 ? classNameFromProps : '', " ").concat(isLayoutPanelShown ? 'layoutPanelOpened' : '');
|
|
449
552
|
return /*#__PURE__*/_react["default"].createElement(StyledApp, {
|
|
450
553
|
ref: componentRef,
|
|
451
554
|
className: className,
|
|
452
|
-
width: width,
|
|
453
555
|
"data-grow": canGrow,
|
|
454
|
-
"data-shrink": canShrink
|
|
455
|
-
|
|
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
|
|
570
|
+
}, isEditMode && /*#__PURE__*/_react["default"].createElement(_Toolbar["default"], {
|
|
571
|
+
width: canvasSize.width,
|
|
456
572
|
disabled: disabled,
|
|
457
573
|
activeTool: activeTool,
|
|
458
574
|
clearCanvas: clearCanvas,
|
|
@@ -466,11 +582,13 @@ var App = function App(_ref5) {
|
|
|
466
582
|
hasActionToClear: canClear,
|
|
467
583
|
undoAction: undoAction,
|
|
468
584
|
redoAction: redoAction,
|
|
469
|
-
availableTools: availableTools
|
|
585
|
+
availableTools: availableTools,
|
|
586
|
+
withExport: withExport,
|
|
587
|
+
withLoadAndSave: withLoadAndSave
|
|
470
588
|
}), /*#__PURE__*/_react["default"].createElement(StyledRow, {
|
|
471
589
|
"data-grow": canGrow,
|
|
472
|
-
width: width,
|
|
473
|
-
aspectRatio: "calc(".concat(width, " / ").concat(height, ")")
|
|
590
|
+
width: canvasSize.width,
|
|
591
|
+
aspectRatio: "calc(".concat(canvasSize.width, " / ").concat(canvasSize.height, ")")
|
|
474
592
|
}, /*#__PURE__*/_react["default"].createElement(_Canvas["default"], {
|
|
475
593
|
canGrow: canGrow,
|
|
476
594
|
withGrid: withGrid,
|
|
@@ -490,11 +608,14 @@ var App = function App(_ref5) {
|
|
|
490
608
|
defaultConf: defaultConf,
|
|
491
609
|
saveShapes: saveShapes,
|
|
492
610
|
ref: canvasRef,
|
|
493
|
-
|
|
494
|
-
height: height,
|
|
611
|
+
canvasSize: canvasSize,
|
|
495
612
|
selectionMode: selectionMode,
|
|
496
|
-
setSelectionMode: setSelectionMode
|
|
497
|
-
|
|
613
|
+
setSelectionMode: setSelectionMode,
|
|
614
|
+
selectionColor: canvasSelectionColor,
|
|
615
|
+
selectionWidth: canvasSelectionWidth,
|
|
616
|
+
selectionPadding: canvasSelectionPadding,
|
|
617
|
+
isEditMode: isEditMode
|
|
618
|
+
}), isEditMode && layersManipulation && /*#__PURE__*/_react["default"].createElement(_Layouts["default"], {
|
|
498
619
|
withGrid: withGrid,
|
|
499
620
|
setWithGrid: setWithGrid,
|
|
500
621
|
disabled: disabled,
|
|
@@ -505,9 +626,8 @@ var App = function App(_ref5) {
|
|
|
505
626
|
selectShape: selectShape,
|
|
506
627
|
toggleShapeVisibility: toggleShapeVisibility,
|
|
507
628
|
toggleShapeLock: toggleShapeLock,
|
|
508
|
-
withLayouts: withLayouts,
|
|
509
629
|
isLayoutPanelShown: isLayoutPanelShown
|
|
510
|
-
})), /*#__PURE__*/_react["default"].createElement(_SettingsBar["default"], {
|
|
630
|
+
})), isEditMode && /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_SettingsBar["default"], {
|
|
511
631
|
disabled: disabled,
|
|
512
632
|
activeTool: activeTool,
|
|
513
633
|
selectedShape: selectedShape,
|
|
@@ -516,7 +636,7 @@ var App = function App(_ref5) {
|
|
|
516
636
|
defaultConf: defaultConf,
|
|
517
637
|
setDefaultConf: setDefaultConf,
|
|
518
638
|
canvas: canvasRef.current,
|
|
519
|
-
|
|
639
|
+
layersManipulation: layersManipulation,
|
|
520
640
|
toggleLayoutPanel: function toggleLayoutPanel() {
|
|
521
641
|
setIsLayoutPanelShown(function (prev) {
|
|
522
642
|
return !prev;
|
|
@@ -526,7 +646,7 @@ var App = function App(_ref5) {
|
|
|
526
646
|
isLoading: isLoading
|
|
527
647
|
}), /*#__PURE__*/_react["default"].createElement(_Snackbar["default"], {
|
|
528
648
|
snackbarList: snackbarList
|
|
529
|
-
}));
|
|
649
|
+
})));
|
|
530
650
|
};
|
|
531
651
|
|
|
532
652
|
var _default = App;
|