@yorab/react-paint 0.2.2 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Changelog.md +24 -0
- package/LICENSE.txt +21 -0
- package/README.md +6 -89
- package/dist/components/App.js +125 -102
- package/dist/components/Canvas.js +17 -14
- 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 +3 -2
- package/dist/components/toolbox/MenuGroup.js +1 -0
- package/dist/components/toolbox/PictureUrlInput.js +8 -7
- package/dist/hooks/useDrawableCanvas.js +19 -17
- package/dist/hooks/useResizeObserver.js +40 -0
- package/dist/hooks/useShapes.js +12 -8
- package/dist/styles.css +16 -17
- package/dist/utils/data.js +71 -19
- package/dist/utils/draw.js +53 -44
- package/dist/utils/file.js +26 -60
- package/dist/utils/intersect.js +18 -14
- package/dist/utils/selection.js +3 -3
- package/dist/utils/transform.js +18 -2
- 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/Changelog.md
CHANGED
|
@@ -1,3 +1,27 @@
|
|
|
1
|
+
# V.0.3.0 :
|
|
2
|
+
|
|
3
|
+
- prevent picture from url submit to reload page
|
|
4
|
+
- add gridVisible prop and default to false
|
|
5
|
+
- rename withLayouts to layersManipulation and reduce possible values
|
|
6
|
+
- move every options inside options prop
|
|
7
|
+
- remove ajv and any kind of json validation
|
|
8
|
+
- limit snackbar use on success and always log errors
|
|
9
|
+
- fit size and center uploaded picture
|
|
10
|
+
- Add new viewer mode
|
|
11
|
+
- add borders on bars
|
|
12
|
+
- display shape id in layer panel
|
|
13
|
+
- Export : round values to 2 decimal points
|
|
14
|
+
- Export and import : remove temporary values (id) from stored file
|
|
15
|
+
- Clean unknown shape format from imported data
|
|
16
|
+
- Use ref for onDataChanged prop to avoid rerender if callback changes
|
|
17
|
+
- Calculate container size to resize canvas instead of CSS
|
|
18
|
+
- use requestAnimationFrame to improve perf
|
|
19
|
+
- fix TextEdit position and size not working with canvas resized
|
|
20
|
+
- fix anchors area becoming too small after rezsize
|
|
21
|
+
- add MIT license to project
|
|
22
|
+
- other minor fixes
|
|
23
|
+
- minor design improvements
|
|
24
|
+
|
|
1
25
|
# V.0.2.2 :
|
|
2
26
|
|
|
3
27
|
- Migrate to react 18
|
package/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Yohann Rabatel
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,99 +1,16 @@
|
|
|
1
|
-
## To regenerate schema :
|
|
2
|
-
|
|
3
|
-
typescript-json-schema "src/types/Shapes.ts" DrawableShapeJson --out 'src/schemas/drawableShape.json'
|
|
4
|
-
|
|
5
1
|
# known issues :
|
|
6
2
|
|
|
7
|
-
##
|
|
3
|
+
## critical
|
|
8
4
|
|
|
9
|
-
-
|
|
10
|
-
- double click not working with touch
|
|
5
|
+
- Text tool broken since 0.2.2
|
|
6
|
+
- double click not working with touch (fix: fake it countinng delay between touch)
|
|
11
7
|
|
|
12
|
-
##
|
|
8
|
+
## mobile/touch
|
|
13
9
|
|
|
14
|
-
-
|
|
15
|
-
- anchors become too small MAJOR (possible fix : increase size with current canvas ratio )
|
|
10
|
+
- dnd layout on mobile not working (fix : use dnd lib, or add touch listener to fake dnd, or provide alt UI)
|
|
16
11
|
|
|
17
12
|
## other
|
|
18
13
|
|
|
19
14
|
- TextEdit cursor overflow MINOR (quick fix : edit on modale)
|
|
15
|
+
- TextEdit copy/paste contains html and breaks display
|
|
20
16
|
- circle resizing only goes one direction
|
|
21
|
-
|
|
22
|
-
# Remarques de thomas :
|
|
23
|
-
|
|
24
|
-
## done
|
|
25
|
-
|
|
26
|
-
- les options (épaisseurs, style de trait...) ont une UI très peu utilisable (on sait pas quel option fait quoi et comment, on teste au pif)
|
|
27
|
-
l'option de changement de couleur :
|
|
28
|
-
ne s'applique qu'à la validation, c'est pas top pour savoir quelle couleur on veut parce qu'on est obligé de validé, voir que c'est pas beau, rouvrir... et ainsi de suite
|
|
29
|
-
- a un petit bug : j'ouvre la modale de sélection, je clique à côté (ça unselect la forme), je change la couleur et valide : il ne se passe rien. Je comprends la logique derrière, mais à l'usage ça n'a pas trop de sens
|
|
30
|
-
- pas de possibilité de setter l'opacité des objets, dommage je pense qu'il y a une vraie utilité à ça
|
|
31
|
-
- croix qui efface le canvas
|
|
32
|
-
il faut une confirmation ! :D
|
|
33
|
-
|
|
34
|
-
## remaining
|
|
35
|
-
|
|
36
|
-
- pas de possibilité de sélectionner plusieurs objets avec un press/trace une zone avec la souris/relache (mécanique assez courante quand il y a de la manipulation d'objets)
|
|
37
|
-
- pas de possibilité de zoom/dezoom dans le canvas, et ça c'est super utile amha
|
|
38
|
-
|
|
39
|
-
### pinceau
|
|
40
|
-
|
|
41
|
-
- certains outils lisse le trait une fois que tu valides le tracé, et ça donne un rendu plus naturel et propre que ce qu'on trace au pad/souris. Du nice to have loin d'être prioritaire
|
|
42
|
-
- avoir plusieurs style de pinceau (mode surligneur par exemple). ca serait utile sur des exo et techniquement c'est peut-être juste des preset de taille/couleur/opacité de l'outil actuel
|
|
43
|
-
- je ne sais pas pourquoi, mais il a l'air moins fluide/smooth au tracé que marker.js (peut-être une illusion)
|
|
44
|
-
|
|
45
|
-
### trait
|
|
46
|
-
|
|
47
|
-
- j'ai été surpris que ça me trace la "forme" dans un rectangle plutôt que d'avoir juste les 2 points sélectionnés (sans le cadre autour quoi)
|
|
48
|
-
|
|
49
|
-
### polygone
|
|
50
|
-
|
|
51
|
-
- démarrer avec un polygone à 2 côté, c'est pas possible ça :sourire:
|
|
52
|
-
quand on change le nombre de côté ça reste un truc plat et ensuite on tire des points :
|
|
53
|
-
c'est pas du tout évident
|
|
54
|
-
ça donne des formes qui ne sont pas des polygones (genre un noeuf papillon)
|
|
55
|
-
idéalement, il faudrait démarrer avec un pentagone parfait -5 côtés de même longueur- (en dessous se sont des polygones trop communs) et quand on change le nombre de côté ça reset la forme sur un polygone parfait de X côtés
|
|
56
|
-
|
|
57
|
-
### Texte
|
|
58
|
-
|
|
59
|
-
- options trop limitée, il faudrait à minima pouvoir changer la taille de la police, choisir plus de police, et faire un peu de mise en forme (i, b, u)
|
|
60
|
-
|
|
61
|
-
## bof
|
|
62
|
-
|
|
63
|
-
- avoir les options dans un tooltip-like, au dessus de la forme, serait merveilleux (comme sur Miro, ou comme sur nos manuels avec la barre de mise en forme de texte)
|
|
64
|
-
- rectangle: pas de carré avec maj, snif
|
|
65
|
-
une option de la forme pour bloqué le ratio en "carré" ?
|
|
66
|
-
- cercle/elipse
|
|
67
|
-
redondant, la diff des outils me parait too much et pas clair
|
|
68
|
-
bloqué en ratio cercle avec maj ou une option de forme (cf rectangle/carré) ?
|
|
69
|
-
|
|
70
|
-
# En prévision / Future MAJ
|
|
71
|
-
|
|
72
|
-
- fix text
|
|
73
|
-
|
|
74
|
-
- Migrer sous Vite +
|
|
75
|
-
|
|
76
|
-
- configurer npm publish
|
|
77
|
-
|
|
78
|
-
- possibility to have presets
|
|
79
|
-
- possibility to provide presets in props
|
|
80
|
-
- add presets
|
|
81
|
-
|
|
82
|
-
- add more settings
|
|
83
|
-
- settings ui
|
|
84
|
-
- add settings customization
|
|
85
|
-
|
|
86
|
-
# A prévoir
|
|
87
|
-
|
|
88
|
-
- ladle (wait for windows support https://github.com/tajo/ladle/issues/67)
|
|
89
|
-
- get rid of enum for better typescript
|
|
90
|
-
- add shortcuts (for tools) and show it in titles
|
|
91
|
-
- Menu contextuel au clic droit (changement de plan, supprimer, duplicate, copy, lock)
|
|
92
|
-
- bordure des traits à revoir
|
|
93
|
-
- améliorer perfs avec précalculs + usage de path
|
|
94
|
-
- lissage de traits
|
|
95
|
-
- Move + zoom functionnality
|
|
96
|
-
- UI customization
|
|
97
|
-
- Tests !
|
|
98
|
-
- fix remaining issues
|
|
99
|
-
- fullscreen mode ?
|
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,29 @@ 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
|
+
|
|
54
60
|
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
61
|
|
|
56
62
|
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
63
|
|
|
64
|
+
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; }
|
|
65
|
+
|
|
66
|
+
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; }
|
|
67
|
+
|
|
58
68
|
var StyledApp = /*#__PURE__*/(0, _react2.styled)("div")({
|
|
59
69
|
name: "StyledApp",
|
|
60
70
|
"class": "s1v9piyg",
|
|
61
71
|
vars: {
|
|
62
72
|
"s1v9piyg-0": [function (_ref) {
|
|
63
|
-
var
|
|
64
|
-
return "min(100%, ".concat(
|
|
73
|
+
var canvaswidth = _ref.canvaswidth;
|
|
74
|
+
return "min(100%, ".concat(canvaswidth, "px)");
|
|
65
75
|
}],
|
|
66
76
|
"s1v9piyg-1": [function (_ref2) {
|
|
67
|
-
var
|
|
68
|
-
return
|
|
77
|
+
var canvaswidth = _ref2.canvaswidth;
|
|
78
|
+
return canvaswidth;
|
|
69
79
|
}, "px"]
|
|
70
80
|
}
|
|
71
81
|
});
|
|
@@ -84,29 +94,50 @@ var StyledRow = /*#__PURE__*/(0, _react2.styled)("div")({
|
|
|
84
94
|
}
|
|
85
95
|
});
|
|
86
96
|
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
|
+
var DEFAULT_OPTIONS = {
|
|
98
|
+
layersManipulation: true,
|
|
99
|
+
gridVisible: false
|
|
100
|
+
};
|
|
87
101
|
|
|
88
102
|
var App = function App(_ref5) {
|
|
89
103
|
var _ref5$width = _ref5.width,
|
|
90
|
-
|
|
104
|
+
canvasWidth = _ref5$width === void 0 ? 1000 : _ref5$width,
|
|
91
105
|
_ref5$height = _ref5.height,
|
|
92
|
-
|
|
106
|
+
canvasHeight = _ref5$height === void 0 ? 600 : _ref5$height,
|
|
93
107
|
_ref5$canGrow = _ref5.canGrow,
|
|
94
108
|
canGrow = _ref5$canGrow === void 0 ? false : _ref5$canGrow,
|
|
95
109
|
_ref5$canShrink = _ref5.canShrink,
|
|
96
110
|
canShrink = _ref5$canShrink === void 0 ? true : _ref5$canShrink,
|
|
97
|
-
_ref5$withLayouts = _ref5.withLayouts,
|
|
98
|
-
withLayouts = _ref5$withLayouts === void 0 ? 'hidden' : _ref5$withLayouts,
|
|
99
111
|
shapesFromProps = _ref5.shapes,
|
|
100
112
|
classNameFromProps = _ref5.className,
|
|
113
|
+
_ref5$mode = _ref5.mode,
|
|
114
|
+
mode = _ref5$mode === void 0 ? 'editor' : _ref5$mode,
|
|
101
115
|
_ref5$disabled = _ref5.disabled,
|
|
102
|
-
|
|
116
|
+
disabledFromProps = _ref5$disabled === void 0 ? false : _ref5$disabled,
|
|
103
117
|
onDataChanged = _ref5.onDataChanged,
|
|
104
118
|
_ref5$availableTools = _ref5.availableTools,
|
|
105
119
|
availableToolsFromProps = _ref5$availableTools === void 0 ? DEFAULT_TOOLS : _ref5$availableTools,
|
|
106
|
-
apiRef = _ref5.apiRef
|
|
120
|
+
apiRef = _ref5.apiRef,
|
|
121
|
+
options = _ref5.options;
|
|
122
|
+
|
|
123
|
+
var _DEFAULT_OPTIONS$opti = _objectSpread(_objectSpread({}, DEFAULT_OPTIONS), options),
|
|
124
|
+
layersManipulation = _DEFAULT_OPTIONS$opti.layersManipulation,
|
|
125
|
+
gridVisible = _DEFAULT_OPTIONS$opti.gridVisible;
|
|
126
|
+
|
|
127
|
+
var isEditMode = mode !== 'viewer';
|
|
128
|
+
var disabled = disabledFromProps || !isEditMode;
|
|
107
129
|
var componentRef = (0, _react.useRef)(null);
|
|
108
130
|
var canvasRef = (0, _react.useRef)(null);
|
|
109
131
|
|
|
132
|
+
var _useState = (0, _react.useState)({
|
|
133
|
+
width: canvasWidth,
|
|
134
|
+
height: canvasHeight,
|
|
135
|
+
scaleRatio: 1
|
|
136
|
+
}),
|
|
137
|
+
_useState2 = (0, _slicedToArray2["default"])(_useState, 2),
|
|
138
|
+
canvasSize = _useState2[0],
|
|
139
|
+
setCanvasSize = _useState2[1];
|
|
140
|
+
|
|
110
141
|
var availableTools = _fp["default"].intersection(DEFAULT_TOOLS, availableToolsFromProps);
|
|
111
142
|
|
|
112
143
|
var _useComponent = (0, _useComponent2["default"])({
|
|
@@ -115,7 +146,7 @@ var App = function App(_ref5) {
|
|
|
115
146
|
}),
|
|
116
147
|
isInsideComponent = _useComponent.isInsideComponent;
|
|
117
148
|
|
|
118
|
-
var
|
|
149
|
+
var _useState3 = (0, _react.useState)({
|
|
119
150
|
style: {
|
|
120
151
|
fillColor: 'transparent',
|
|
121
152
|
strokeColor: 'black',
|
|
@@ -127,46 +158,46 @@ var App = function App(_ref5) {
|
|
|
127
158
|
fontFamily: _style.STYLE_FONT_DEFAULT
|
|
128
159
|
}
|
|
129
160
|
}),
|
|
130
|
-
_useState2 = (0, _slicedToArray2["default"])(_useState, 2),
|
|
131
|
-
defaultConf = _useState2[0],
|
|
132
|
-
setDefaultConf = _useState2[1];
|
|
133
|
-
|
|
134
|
-
var _useState3 = (0, _react.useState)(false),
|
|
135
161
|
_useState4 = (0, _slicedToArray2["default"])(_useState3, 2),
|
|
136
|
-
|
|
137
|
-
|
|
162
|
+
defaultConf = _useState4[0],
|
|
163
|
+
setDefaultConf = _useState4[1];
|
|
138
164
|
|
|
139
|
-
var _useState5 = (0, _react.useState)(
|
|
165
|
+
var _useState5 = (0, _react.useState)(false),
|
|
140
166
|
_useState6 = (0, _slicedToArray2["default"])(_useState5, 2),
|
|
141
|
-
|
|
142
|
-
|
|
167
|
+
isLoading = _useState6[0],
|
|
168
|
+
setIsLoading = _useState6[1];
|
|
143
169
|
|
|
144
|
-
var _useState7 = (0, _react.useState)(
|
|
170
|
+
var _useState7 = (0, _react.useState)(false),
|
|
145
171
|
_useState8 = (0, _slicedToArray2["default"])(_useState7, 2),
|
|
146
|
-
|
|
147
|
-
|
|
172
|
+
isLayoutPanelShown = _useState8[0],
|
|
173
|
+
setIsLayoutPanelShown = _useState8[1];
|
|
148
174
|
|
|
149
|
-
var _useState9 = (0, _react.useState)(
|
|
175
|
+
var _useState9 = (0, _react.useState)([0, 0]),
|
|
150
176
|
_useState10 = (0, _slicedToArray2["default"])(_useState9, 2),
|
|
151
|
-
|
|
152
|
-
|
|
177
|
+
canvasOffset = _useState10[0],
|
|
178
|
+
setCanvasOffset = _useState10[1];
|
|
153
179
|
|
|
154
|
-
var _useState11 = (0, _react.useState)(
|
|
180
|
+
var _useState11 = (0, _react.useState)(undefined),
|
|
155
181
|
_useState12 = (0, _slicedToArray2["default"])(_useState11, 2),
|
|
156
|
-
|
|
157
|
-
|
|
182
|
+
canvasOffsetStartPosition = _useState12[0],
|
|
183
|
+
setCanvasOffsetStartPosition = _useState12[1];
|
|
158
184
|
|
|
159
|
-
var _useState13 = (0, _react.useState)(
|
|
160
|
-
mode: _Mode.SelectionModeLib["default"]
|
|
161
|
-
}),
|
|
185
|
+
var _useState13 = (0, _react.useState)(_Shapes.ToolEnum.selection),
|
|
162
186
|
_useState14 = (0, _slicedToArray2["default"])(_useState13, 2),
|
|
163
|
-
|
|
164
|
-
|
|
187
|
+
activeTool = _useState14[0],
|
|
188
|
+
setActiveTool = _useState14[1];
|
|
165
189
|
|
|
166
|
-
var _useState15 = (0, _react.useState)(
|
|
190
|
+
var _useState15 = (0, _react.useState)({
|
|
191
|
+
mode: _Mode.SelectionModeLib["default"]
|
|
192
|
+
}),
|
|
167
193
|
_useState16 = (0, _slicedToArray2["default"])(_useState15, 2),
|
|
168
|
-
|
|
169
|
-
|
|
194
|
+
selectionMode = _useState16[0],
|
|
195
|
+
setSelectionMode = _useState16[1];
|
|
196
|
+
|
|
197
|
+
var _useState17 = (0, _react.useState)(gridVisible),
|
|
198
|
+
_useState18 = (0, _slicedToArray2["default"])(_useState17, 2),
|
|
199
|
+
withGrid = _useState18[0],
|
|
200
|
+
setWithGrid = _useState18[1];
|
|
170
201
|
|
|
171
202
|
var _useShapes = (0, _useShapes2["default"])(onDataChanged),
|
|
172
203
|
shapesRef = _useShapes.shapesRef,
|
|
@@ -222,17 +253,13 @@ var App = function App(_ref5) {
|
|
|
222
253
|
setIsLoading(true);
|
|
223
254
|
|
|
224
255
|
try {
|
|
225
|
-
var dataURL = canvasRef.current && (0, _file.getCanvasImage)(
|
|
256
|
+
var dataURL = canvasRef.current && (0, _file.getCanvasImage)(shapesRef.current, canvasOffset, canvasWidth, canvasHeight);
|
|
226
257
|
|
|
227
258
|
if (!dataURL) {
|
|
228
259
|
throw new Error();
|
|
229
260
|
}
|
|
230
261
|
|
|
231
262
|
(0, _file.downloadFile)(dataURL, 'drawing.png');
|
|
232
|
-
addSnackbar({
|
|
233
|
-
type: _snackbar.SnackbarTypeEnum.Success,
|
|
234
|
-
text: 'Export terminé !'
|
|
235
|
-
});
|
|
236
263
|
setIsLoading(false);
|
|
237
264
|
} catch (e) {
|
|
238
265
|
if (e instanceof Error) {
|
|
@@ -240,13 +267,13 @@ var App = function App(_ref5) {
|
|
|
240
267
|
type: _snackbar.SnackbarTypeEnum.Error,
|
|
241
268
|
text: "L'export a échoué"
|
|
242
269
|
});
|
|
243
|
-
} else {
|
|
244
|
-
console.warn(e);
|
|
245
270
|
}
|
|
271
|
+
|
|
272
|
+
console.warn(e);
|
|
246
273
|
} finally {
|
|
247
274
|
setIsLoading(false);
|
|
248
275
|
}
|
|
249
|
-
}, [addSnackbar]);
|
|
276
|
+
}, [addSnackbar, shapesRef, canvasOffset, canvasWidth, canvasHeight]);
|
|
250
277
|
var saveFile = (0, _react.useCallback)(function () {
|
|
251
278
|
setIsLoading(true);
|
|
252
279
|
|
|
@@ -254,53 +281,39 @@ var App = function App(_ref5) {
|
|
|
254
281
|
var content = (0, _file.encodeShapesInString)(shapesRef.current);
|
|
255
282
|
|
|
256
283
|
if (!content) {
|
|
257
|
-
throw new Error("L'
|
|
284
|
+
throw new Error("L'encodage a échoué");
|
|
258
285
|
}
|
|
259
286
|
|
|
260
287
|
(0, _file.downloadFile)(content, 'drawing.json');
|
|
261
|
-
addSnackbar({
|
|
262
|
-
type: _snackbar.SnackbarTypeEnum.Success,
|
|
263
|
-
text: 'Fichier enregistré !'
|
|
264
|
-
});
|
|
265
288
|
setIsLoading(false);
|
|
266
289
|
} catch (e) {
|
|
267
290
|
if (e instanceof Error) {
|
|
268
291
|
addSnackbar({
|
|
269
292
|
type: _snackbar.SnackbarTypeEnum.Error,
|
|
270
|
-
text:
|
|
293
|
+
text: "L'enregistrement a échoué"
|
|
271
294
|
});
|
|
272
|
-
} else {
|
|
273
|
-
console.warn(e);
|
|
274
295
|
}
|
|
296
|
+
|
|
297
|
+
console.warn(e);
|
|
275
298
|
} finally {
|
|
276
299
|
setIsLoading(false);
|
|
277
300
|
}
|
|
278
301
|
}, [shapesRef, addSnackbar]);
|
|
279
302
|
var loadJson = (0, _react.useCallback)( /*#__PURE__*/function () {
|
|
280
303
|
var _ref6 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(json) {
|
|
281
|
-
var
|
|
304
|
+
var shapes;
|
|
282
305
|
return _regenerator["default"].wrap(function _callee$(_context) {
|
|
283
306
|
while (1) {
|
|
284
307
|
switch (_context.prev = _context.next) {
|
|
285
308
|
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;
|
|
309
|
+
_context.next = 2;
|
|
297
310
|
return (0, _file.decodePicturesInShapes)(json);
|
|
298
311
|
|
|
299
|
-
case
|
|
312
|
+
case 2:
|
|
300
313
|
shapes = _context.sent;
|
|
301
314
|
clearCanvas(shapes, true);
|
|
302
315
|
|
|
303
|
-
case
|
|
316
|
+
case 4:
|
|
304
317
|
case "end":
|
|
305
318
|
return _context.stop();
|
|
306
319
|
}
|
|
@@ -334,7 +347,7 @@ var App = function App(_ref5) {
|
|
|
334
347
|
type: _snackbar.SnackbarTypeEnum.Success,
|
|
335
348
|
text: 'Fichier chargé !'
|
|
336
349
|
});
|
|
337
|
-
_context2.next =
|
|
350
|
+
_context2.next = 14;
|
|
338
351
|
break;
|
|
339
352
|
|
|
340
353
|
case 10:
|
|
@@ -344,23 +357,23 @@ var App = function App(_ref5) {
|
|
|
344
357
|
if (_context2.t0 instanceof Error) {
|
|
345
358
|
addSnackbar({
|
|
346
359
|
type: _snackbar.SnackbarTypeEnum.Error,
|
|
347
|
-
text:
|
|
360
|
+
text: 'Le chargement a échoué'
|
|
348
361
|
});
|
|
349
|
-
} else {
|
|
350
|
-
console.warn(_context2.t0);
|
|
351
362
|
}
|
|
352
363
|
|
|
353
|
-
|
|
354
|
-
|
|
364
|
+
console.warn(_context2.t0);
|
|
365
|
+
|
|
366
|
+
case 14:
|
|
367
|
+
_context2.prev = 14;
|
|
355
368
|
setIsLoading(false);
|
|
356
|
-
return _context2.finish(
|
|
369
|
+
return _context2.finish(14);
|
|
357
370
|
|
|
358
|
-
case
|
|
371
|
+
case 17:
|
|
359
372
|
case "end":
|
|
360
373
|
return _context2.stop();
|
|
361
374
|
}
|
|
362
375
|
}
|
|
363
|
-
}, _callee2, null, [[1, 10,
|
|
376
|
+
}, _callee2, null, [[1, 10, 14, 17]]);
|
|
364
377
|
}));
|
|
365
378
|
|
|
366
379
|
return function (_x2) {
|
|
@@ -377,12 +390,12 @@ var App = function App(_ref5) {
|
|
|
377
390
|
setIsLoading(true);
|
|
378
391
|
_context3.prev = 1;
|
|
379
392
|
_context3.next = 4;
|
|
380
|
-
return addPictureShape(fileOrUrl);
|
|
393
|
+
return addPictureShape(fileOrUrl, canvasWidth, canvasHeight);
|
|
381
394
|
|
|
382
395
|
case 4:
|
|
383
396
|
pictureShape = _context3.sent;
|
|
384
397
|
selectShape(pictureShape);
|
|
385
|
-
_context3.next =
|
|
398
|
+
_context3.next = 12;
|
|
386
399
|
break;
|
|
387
400
|
|
|
388
401
|
case 8:
|
|
@@ -392,29 +405,37 @@ var App = function App(_ref5) {
|
|
|
392
405
|
if (_context3.t0 instanceof Error) {
|
|
393
406
|
addSnackbar({
|
|
394
407
|
type: _snackbar.SnackbarTypeEnum.Error,
|
|
395
|
-
text:
|
|
408
|
+
text: 'Le chargement a échoué'
|
|
396
409
|
});
|
|
397
|
-
} else {
|
|
398
|
-
console.warn(_context3.t0);
|
|
399
410
|
}
|
|
400
411
|
|
|
401
|
-
|
|
402
|
-
|
|
412
|
+
console.warn(_context3.t0);
|
|
413
|
+
|
|
414
|
+
case 12:
|
|
415
|
+
_context3.prev = 12;
|
|
403
416
|
setIsLoading(false);
|
|
404
|
-
return _context3.finish(
|
|
417
|
+
return _context3.finish(12);
|
|
405
418
|
|
|
406
|
-
case
|
|
419
|
+
case 15:
|
|
407
420
|
case "end":
|
|
408
421
|
return _context3.stop();
|
|
409
422
|
}
|
|
410
423
|
}
|
|
411
|
-
}, _callee3, null, [[1, 8,
|
|
424
|
+
}, _callee3, null, [[1, 8, 12, 15]]);
|
|
412
425
|
}));
|
|
413
426
|
|
|
414
427
|
return function (_x3) {
|
|
415
428
|
return _ref8.apply(this, arguments);
|
|
416
429
|
};
|
|
417
|
-
}(), [addPictureShape, selectShape, addSnackbar]);
|
|
430
|
+
}(), [addPictureShape, selectShape, addSnackbar, canvasWidth, canvasHeight]);
|
|
431
|
+
var onResized = (0, _react.useCallback)(function (measuredWidth, measuredHeight) {
|
|
432
|
+
var scaleRatio = measuredWidth / canvasWidth;
|
|
433
|
+
setCanvasSize({
|
|
434
|
+
width: measuredWidth,
|
|
435
|
+
height: canvasHeight * scaleRatio,
|
|
436
|
+
scaleRatio: scaleRatio
|
|
437
|
+
});
|
|
438
|
+
}, [canvasWidth, canvasHeight]);
|
|
418
439
|
(0, _useKeyboard["default"])({
|
|
419
440
|
isInsideComponent: isInsideComponent,
|
|
420
441
|
isEditingText: selectionMode.mode === _Mode.SelectionModeLib.textedition,
|
|
@@ -426,6 +447,10 @@ var App = function App(_ref5) {
|
|
|
426
447
|
backwardShape: backwardShape,
|
|
427
448
|
forwardShape: forwardShape
|
|
428
449
|
});
|
|
450
|
+
(0, _useResizeObserver["default"])({
|
|
451
|
+
element: componentRef,
|
|
452
|
+
onResized: onResized
|
|
453
|
+
});
|
|
429
454
|
(0, _react.useEffect)(function () {
|
|
430
455
|
if (!isInsideComponent) setSelectedShape(undefined);
|
|
431
456
|
}, [isInsideComponent, setSelectedShape]);
|
|
@@ -438,21 +463,21 @@ var App = function App(_ref5) {
|
|
|
438
463
|
if (!apiRef) return;
|
|
439
464
|
apiRef.current = {
|
|
440
465
|
getCurrentImage: function getCurrentImage() {
|
|
441
|
-
return canvasRef.current ? (0, _file.getCanvasImage)(
|
|
466
|
+
return canvasRef.current ? (0, _file.getCanvasImage)(shapesRef.current, canvasOffset, canvasWidth, canvasHeight) : undefined;
|
|
442
467
|
},
|
|
443
468
|
getCurrentData: function getCurrentData() {
|
|
444
|
-
return (0,
|
|
469
|
+
return (0, _data.cleanShapesBeforeExport)(shapesRef.current); //TODO : create different types for stored shapes
|
|
445
470
|
}
|
|
446
471
|
};
|
|
447
|
-
}, [apiRef, shapesRef]);
|
|
472
|
+
}, [apiRef, shapesRef, canvasOffset, canvasWidth, canvasHeight]);
|
|
448
473
|
var className = "".concat(classNameFromProps !== null && classNameFromProps !== void 0 ? classNameFromProps : '', " ").concat(isLayoutPanelShown ? 'layoutPanelOpened' : '');
|
|
449
474
|
return /*#__PURE__*/_react["default"].createElement(StyledApp, {
|
|
450
475
|
ref: componentRef,
|
|
451
476
|
className: className,
|
|
452
|
-
|
|
477
|
+
canvaswidth: canvasWidth,
|
|
453
478
|
"data-grow": canGrow,
|
|
454
479
|
"data-shrink": canShrink
|
|
455
|
-
}, /*#__PURE__*/_react["default"].createElement(_Toolbar["default"], {
|
|
480
|
+
}, isEditMode && /*#__PURE__*/_react["default"].createElement(_Toolbar["default"], {
|
|
456
481
|
disabled: disabled,
|
|
457
482
|
activeTool: activeTool,
|
|
458
483
|
clearCanvas: clearCanvas,
|
|
@@ -469,8 +494,8 @@ var App = function App(_ref5) {
|
|
|
469
494
|
availableTools: availableTools
|
|
470
495
|
}), /*#__PURE__*/_react["default"].createElement(StyledRow, {
|
|
471
496
|
"data-grow": canGrow,
|
|
472
|
-
width: width,
|
|
473
|
-
aspectRatio: "calc(".concat(width, " / ").concat(height, ")")
|
|
497
|
+
width: canvasSize.width,
|
|
498
|
+
aspectRatio: "calc(".concat(canvasSize.width, " / ").concat(canvasSize.height, ")")
|
|
474
499
|
}, /*#__PURE__*/_react["default"].createElement(_Canvas["default"], {
|
|
475
500
|
canGrow: canGrow,
|
|
476
501
|
withGrid: withGrid,
|
|
@@ -490,11 +515,10 @@ var App = function App(_ref5) {
|
|
|
490
515
|
defaultConf: defaultConf,
|
|
491
516
|
saveShapes: saveShapes,
|
|
492
517
|
ref: canvasRef,
|
|
493
|
-
|
|
494
|
-
height: height,
|
|
518
|
+
canvasSize: canvasSize,
|
|
495
519
|
selectionMode: selectionMode,
|
|
496
520
|
setSelectionMode: setSelectionMode
|
|
497
|
-
}), /*#__PURE__*/_react["default"].createElement(_Layouts["default"], {
|
|
521
|
+
}), isEditMode && layersManipulation && /*#__PURE__*/_react["default"].createElement(_Layouts["default"], {
|
|
498
522
|
withGrid: withGrid,
|
|
499
523
|
setWithGrid: setWithGrid,
|
|
500
524
|
disabled: disabled,
|
|
@@ -505,9 +529,8 @@ var App = function App(_ref5) {
|
|
|
505
529
|
selectShape: selectShape,
|
|
506
530
|
toggleShapeVisibility: toggleShapeVisibility,
|
|
507
531
|
toggleShapeLock: toggleShapeLock,
|
|
508
|
-
withLayouts: withLayouts,
|
|
509
532
|
isLayoutPanelShown: isLayoutPanelShown
|
|
510
|
-
})), /*#__PURE__*/_react["default"].createElement(_SettingsBar["default"], {
|
|
533
|
+
})), isEditMode && /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_SettingsBar["default"], {
|
|
511
534
|
disabled: disabled,
|
|
512
535
|
activeTool: activeTool,
|
|
513
536
|
selectedShape: selectedShape,
|
|
@@ -516,7 +539,7 @@ var App = function App(_ref5) {
|
|
|
516
539
|
defaultConf: defaultConf,
|
|
517
540
|
setDefaultConf: setDefaultConf,
|
|
518
541
|
canvas: canvasRef.current,
|
|
519
|
-
|
|
542
|
+
layersManipulation: layersManipulation,
|
|
520
543
|
toggleLayoutPanel: function toggleLayoutPanel() {
|
|
521
544
|
setIsLayoutPanelShown(function (prev) {
|
|
522
545
|
return !prev;
|
|
@@ -526,7 +549,7 @@ var App = function App(_ref5) {
|
|
|
526
549
|
isLoading: isLoading
|
|
527
550
|
}), /*#__PURE__*/_react["default"].createElement(_Snackbar["default"], {
|
|
528
551
|
snackbarList: snackbarList
|
|
529
|
-
}));
|
|
552
|
+
})));
|
|
530
553
|
};
|
|
531
554
|
|
|
532
555
|
var _default = App;
|