@pie-element/drawing-response 10.3.4-next.3 → 11.0.0-beta.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.
Files changed (83) hide show
  1. package/configure/lib/button.js +23 -47
  2. package/configure/lib/button.js.map +1 -1
  3. package/configure/lib/defaults.js +2 -3
  4. package/configure/lib/defaults.js.map +1 -1
  5. package/configure/lib/image-container.js +238 -327
  6. package/configure/lib/image-container.js.map +1 -1
  7. package/configure/lib/index.js +115 -182
  8. package/configure/lib/index.js.map +1 -1
  9. package/configure/lib/root.js +194 -260
  10. package/configure/lib/root.js.map +1 -1
  11. package/configure/package.json +9 -7
  12. package/configure/src/__tests__/image-container.test.jsx +101 -37
  13. package/configure/src/__tests__/index.test.js +27 -5
  14. package/configure/src/__tests__/root.test.jsx +37 -21
  15. package/configure/src/button.jsx +14 -24
  16. package/configure/src/image-container.jsx +73 -77
  17. package/configure/src/index.js +12 -2
  18. package/configure/src/root.jsx +24 -25
  19. package/controller/lib/defaults.js +2 -3
  20. package/controller/lib/defaults.js.map +1 -1
  21. package/controller/lib/index.js +39 -65
  22. package/controller/lib/index.js.map +1 -1
  23. package/controller/package.json +1 -1
  24. package/lib/drawing-response/button.js +35 -60
  25. package/lib/drawing-response/button.js.map +1 -1
  26. package/lib/drawing-response/constants.js +2 -3
  27. package/lib/drawing-response/constants.js.map +1 -1
  28. package/lib/drawing-response/container.js +270 -351
  29. package/lib/drawing-response/container.js.map +1 -1
  30. package/lib/drawing-response/drawable-circle.js +65 -104
  31. package/lib/drawing-response/drawable-circle.js.map +1 -1
  32. package/lib/drawing-response/drawable-eraser.js +50 -86
  33. package/lib/drawing-response/drawable-eraser.js.map +1 -1
  34. package/lib/drawing-response/drawable-free-path.js +56 -97
  35. package/lib/drawing-response/drawable-free-path.js.map +1 -1
  36. package/lib/drawing-response/drawable-helper.js +16 -28
  37. package/lib/drawing-response/drawable-helper.js.map +1 -1
  38. package/lib/drawing-response/drawable-image.js +30 -49
  39. package/lib/drawing-response/drawable-image.js.map +1 -1
  40. package/lib/drawing-response/drawable-line.js +60 -99
  41. package/lib/drawing-response/drawable-line.js.map +1 -1
  42. package/lib/drawing-response/drawable-main.js +273 -345
  43. package/lib/drawing-response/drawable-main.js.map +1 -1
  44. package/lib/drawing-response/drawable-palette.js +123 -166
  45. package/lib/drawing-response/drawable-palette.js.map +1 -1
  46. package/lib/drawing-response/drawable-rectangle.js +65 -104
  47. package/lib/drawing-response/drawable-rectangle.js.map +1 -1
  48. package/lib/drawing-response/drawable-text.js +201 -313
  49. package/lib/drawing-response/drawable-text.js.map +1 -1
  50. package/lib/drawing-response/drawable-transformer.js +36 -79
  51. package/lib/drawing-response/drawable-transformer.js.map +1 -1
  52. package/lib/drawing-response/factory.js +6 -19
  53. package/lib/drawing-response/factory.js.map +1 -1
  54. package/lib/drawing-response/icon.js +8 -24
  55. package/lib/drawing-response/icon.js.map +1 -1
  56. package/lib/drawing-response/index.js +74 -116
  57. package/lib/drawing-response/index.js.map +1 -1
  58. package/lib/index.js +51 -102
  59. package/lib/index.js.map +1 -1
  60. package/package.json +13 -12
  61. package/src/__tests__/drawing-index-test.jsx +90 -27
  62. package/src/drawing-response/__tests__/container.test.jsx +56 -36
  63. package/src/drawing-response/__tests__/drawing-main.test.jsx +158 -139
  64. package/src/drawing-response/button.jsx +23 -34
  65. package/src/drawing-response/container.jsx +39 -40
  66. package/src/drawing-response/drawable-image.jsx +17 -20
  67. package/src/drawing-response/drawable-main.jsx +67 -60
  68. package/src/drawing-response/drawable-palette.jsx +48 -54
  69. package/src/drawing-response/drawable-text.jsx +26 -38
  70. package/src/drawing-response/index.jsx +21 -20
  71. package/src/index.js +17 -2
  72. package/configure/src/__tests__/__snapshots__/image-container.test.jsx.snap +0 -45
  73. package/configure/src/__tests__/__snapshots__/root.test.jsx.snap +0 -185
  74. package/esm/configure.js +0 -16151
  75. package/esm/configure.js.map +0 -1
  76. package/esm/controller.js +0 -814
  77. package/esm/controller.js.map +0 -1
  78. package/esm/element.js +0 -54130
  79. package/esm/element.js.map +0 -1
  80. package/esm/package.json +0 -3
  81. package/src/__tests__/__snapshots__/drawing-index-test.jsx.snap +0 -23
  82. package/src/drawing-response/__tests__/__snapshots__/container.test.jsx.snap +0 -396
  83. package/src/drawing-response/__tests__/__snapshots__/drawing-main.test.jsx.snap +0 -247
@@ -1,6 +1,6 @@
1
1
  import React, { Component } from 'react';
2
2
  import PropTypes from 'prop-types';
3
- import { withStyles } from '@material-ui/core/styles';
3
+ import { styled } from '@mui/material/styles';
4
4
  import Translator from '@pie-lib/translator';
5
5
 
6
6
  import constants from './constants';
@@ -13,6 +13,34 @@ import Icon from './icon';
13
13
  const { tools: TOOLS } = constants;
14
14
  const { translator } = Translator;
15
15
 
16
+ const BaseContainer = styled('div')(({ theme }) => ({
17
+ marginTop: theme.spacing(2),
18
+ }));
19
+
20
+ const Box = styled('div')(({ theme }) => ({
21
+ border: '1px solid #E0E1E6',
22
+ borderRadius: '5px',
23
+ marginTop: theme.spacing(2),
24
+ backgroundColor: '#ECEDF1',
25
+ }));
26
+
27
+ const DrawableHeight = styled('div')({
28
+ minHeight: 350,
29
+ backgroundColor: '#fff',
30
+ });
31
+
32
+ const Toolbar = styled('div')(({ theme }) => ({
33
+ borderBottom: '1px solid #E0E1E6',
34
+ borderTopLeftRadius: '5px',
35
+ borderTopRightRadius: '5px',
36
+ padding: '12px 8px 4px',
37
+ boxSizing: 'border-box',
38
+ maxWidth: 'calc(100% - 163px)', // 163px is the width set on undoControls
39
+ '& button': {
40
+ marginBottom: theme.spacing(1),
41
+ },
42
+ }));
43
+
16
44
  const ROGVAIV = ['red', 'orange', 'yellow', 'violet', 'blue', 'green', 'white', 'black'].map((c) => ({
17
45
  value: c,
18
46
  label: c,
@@ -20,7 +48,6 @@ const ROGVAIV = ['red', 'orange', 'yellow', 'violet', 'blue', 'green', 'white',
20
48
 
21
49
  export class Container extends Component {
22
50
  static propTypes = {
23
- classes: PropTypes.object.isRequired,
24
51
  disabled: PropTypes.bool,
25
52
  session: PropTypes.object.isRequired,
26
53
  onSessionChange: PropTypes.func.isRequired,
@@ -192,7 +219,7 @@ export class Container extends Component {
192
219
  }
193
220
 
194
221
  render() {
195
- const { classes, disabled, imageUrl, imageDimensions, onSessionChange, session, backgroundImageEnabled, language } =
222
+ const { disabled, imageUrl, imageDimensions, onSessionChange, session, backgroundImageEnabled, language } =
196
223
  this.props;
197
224
  const {
198
225
  drawableDimensions,
@@ -209,7 +236,7 @@ export class Container extends Component {
209
236
  const heightToUse = drawableDimensions.height * this.state.scale;
210
237
 
211
238
  return (
212
- <div className={classes.base}>
239
+ <BaseContainer>
213
240
  {!disabled && (
214
241
  <DrawablePalette
215
242
  fillColor={fillColor}
@@ -225,8 +252,8 @@ export class Container extends Component {
225
252
  />
226
253
  )}
227
254
 
228
- <div className={classes.box}>
229
- <div className={classes.toolbar}>
255
+ <Box>
256
+ <Toolbar>
230
257
  {TOOLS.map((tool) => {
231
258
  const { type, label, icon } = tool;
232
259
 
@@ -240,13 +267,12 @@ export class Container extends Component {
240
267
  />
241
268
  );
242
269
  })}
243
- </div>
270
+ </Toolbar>
244
271
 
245
- <div
272
+ <DrawableHeight
246
273
  ref={(drawable) => {
247
274
  this.drawable = drawable;
248
275
  }}
249
- className={classes.drawableHeight}
250
276
  style={{ height: heightToUse, maxHeight: heightToUse, overflow: 'scroll' }}
251
277
  >
252
278
  <DrawableMain
@@ -265,38 +291,11 @@ export class Container extends Component {
265
291
  backgroundImageEnabled={backgroundImageEnabled}
266
292
  language={language}
267
293
  />
268
- </div>
269
- </div>
270
- </div>
294
+ </DrawableHeight>
295
+ </Box>
296
+ </BaseContainer>
271
297
  );
272
298
  }
273
299
  }
274
300
 
275
- const styles = (theme) => ({
276
- base: {
277
- marginTop: theme.spacing.unit * 2,
278
- },
279
- box: {
280
- border: '1px solid #E0E1E6',
281
- borderRadius: '5px',
282
- marginTop: theme.spacing.unit * 2,
283
- backgroundColor: '#ECEDF1',
284
- },
285
- drawableHeight: {
286
- minHeight: 350,
287
- backgroundColor: '#fff',
288
- },
289
- toolbar: {
290
- borderBottom: '1px solid #E0E1E6',
291
- borderTopLeftRadius: '5px',
292
- borderTopRightRadius: '5px',
293
- padding: '12px 8px 4px',
294
- boxSizing: 'border-box',
295
- maxWidth: 'calc(100% - 163px)', // 163px is the width set on undoControls
296
- '& button': {
297
- marginBottom: theme.spacing.unit,
298
- },
299
- },
300
- });
301
-
302
- export default withStyles(styles)(Container);
301
+ export default Container;
@@ -1,12 +1,22 @@
1
1
  import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
- import { withStyles } from '@material-ui/core/styles';
3
+ import { styled } from '@mui/material/styles';
4
4
 
5
- const DrawableImage = ({ classes, url, dimensions: { height, width } }) => (
6
- <div className={classes.imageContainer}>
7
- <img
5
+ const ImageContainer = styled('div')({
6
+ position: 'relative',
7
+ width: 'fit-content',
8
+ });
9
+
10
+ const Image = styled('img')({
11
+ alignItems: 'center',
12
+ display: 'flex',
13
+ justifyContent: 'center',
14
+ });
15
+
16
+ const DrawableImage = ({ url, dimensions: { height, width } }) => (
17
+ <ImageContainer>
18
+ <Image
8
19
  alt="drawing-response-image"
9
- className={classes.image}
10
20
  src={url}
11
21
  style={{
12
22
  height,
@@ -15,25 +25,12 @@ const DrawableImage = ({ classes, url, dimensions: { height, width } }) => (
15
25
  width,
16
26
  }}
17
27
  />
18
- </div>
28
+ </ImageContainer>
19
29
  );
20
30
 
21
- const styles = () => ({
22
- image: {
23
- alignItems: 'center',
24
- display: 'flex',
25
- justifyContent: 'center',
26
- },
27
- imageContainer: {
28
- position: 'relative',
29
- width: 'fit-content',
30
- },
31
- });
32
-
33
31
  DrawableImage.propTypes = {
34
- classes: PropTypes.object.isRequired,
35
32
  dimensions: PropTypes.object.isRequired,
36
33
  url: PropTypes.string.isRequired,
37
34
  };
38
35
 
39
- export default withStyles(styles)(DrawableImage);
36
+ export default DrawableImage;
@@ -3,9 +3,8 @@ import PropTypes from 'prop-types';
3
3
  import omit from 'lodash/omit';
4
4
  import cloneDeep from 'lodash/cloneDeep';
5
5
  import isEqual from 'lodash/isEqual';
6
- import classnames from 'classnames';
7
6
  import { Layer, Stage } from 'react-konva';
8
- import { withStyles } from '@material-ui/core/styles';
7
+ import { styled } from '@mui/material/styles';
9
8
  import Translator from '@pie-lib/translator';
10
9
 
11
10
  const { translator } = Translator;
@@ -13,6 +12,23 @@ import ImageBackground from './drawable-image';
13
12
  import Button from './button';
14
13
  import factory from './factory';
15
14
 
15
+ const Wrapper = styled('div')({
16
+ display: 'flex',
17
+ flexWrap: 'wrap',
18
+ justifyContent: 'flex-end',
19
+ });
20
+
21
+ const Base = styled('div')({
22
+ position: 'relative',
23
+ width: '100%',
24
+ });
25
+
26
+ const UndoControls = styled('div')({
27
+ marginTop: -43,
28
+ marginRight: 10,
29
+ position: 'absolute',
30
+ });
31
+
16
32
  export class DrawableMain extends React.Component {
17
33
  constructor(props) {
18
34
  super(props);
@@ -21,6 +37,14 @@ export class DrawableMain extends React.Component {
21
37
  newDrawable: [],
22
38
  textIsSelected: false,
23
39
  };
40
+ this.stage = null;
41
+ this.layer = null;
42
+ }
43
+
44
+ componentWillUnmount() {
45
+ // Clean up refs to prevent React Konva errors
46
+ this.stage = null;
47
+ this.layer = null;
24
48
  }
25
49
 
26
50
  UNSAFE_componentWillReceiveProps(nextProps) {
@@ -90,7 +114,10 @@ export class DrawableMain extends React.Component {
90
114
  const { toolActive, fillColor, outlineColor, scale } = this.props;
91
115
 
92
116
  if (newDrawable.length === 0 && !textIsSelected) {
93
- const { x, y } = e.target.getStage().getPointerPosition();
117
+ const stage = e.target.getStage();
118
+ if (!stage) return;
119
+
120
+ const { x, y } = stage.getPointerPosition();
94
121
 
95
122
  const newDrawable = factory(toolActive.type, {
96
123
  startx: x / scale,
@@ -114,7 +141,10 @@ export class DrawableMain extends React.Component {
114
141
  const { scale } = this.props;
115
142
 
116
143
  if (newDrawable.length === 1) {
117
- const { x, y } = e.target.getStage().getPointerPosition();
144
+ const stage = e.target.getStage();
145
+ if (!stage) return;
146
+
147
+ const { x, y } = stage.getPointerPosition();
118
148
  const drawableToAdd = newDrawable[0];
119
149
 
120
150
  drawableToAdd.registerMovement(x / scale, y / scale);
@@ -135,7 +165,10 @@ export class DrawableMain extends React.Component {
135
165
  const { scale } = this.props;
136
166
 
137
167
  if (newDrawable.length === 1) {
138
- const { x, y } = e.target.getStage().getPointerPosition();
168
+ const stage = e.target.getStage();
169
+ if (!stage) return;
170
+
171
+ const { x, y } = stage.getPointerPosition();
139
172
  const updatedNewDrawable = newDrawable[0];
140
173
 
141
174
  updatedNewDrawable.registerMovement(x / scale, y / scale);
@@ -176,7 +209,6 @@ export class DrawableMain extends React.Component {
176
209
 
177
210
  render() {
178
211
  const {
179
- classes,
180
212
  disabled,
181
213
  drawableDimensions,
182
214
  fillColor,
@@ -232,8 +264,8 @@ export class DrawableMain extends React.Component {
232
264
  const imageWidth = imageDimensions?.width * scale;
233
265
 
234
266
  return (
235
- <div className={classes.wrapper}>
236
- <div className={classes.undoControls}>
267
+ <Wrapper>
268
+ <UndoControls>
237
269
  <Button
238
270
  disabled={disabled}
239
271
  onClick={this.handleUndo}
@@ -244,71 +276,46 @@ export class DrawableMain extends React.Component {
244
276
  onClick={this.handleClearAll}
245
277
  label={translator.t('common:clearAll', { lng: language })}
246
278
  />
247
- </div>
248
- <div className={classes.base}>
279
+ </UndoControls>
280
+ <Base>
249
281
  {backgroundImageEnabled && imageUrl && (
250
282
  <ImageBackground dimensions={{ height: imageHeight, width: imageWidth }} url={imageUrl} />
251
283
  )}
252
284
 
253
285
  {TextEntry.renderTextareas()}
254
286
 
255
- <Stage
256
- scaleX={scale}
257
- scaleY={scale}
258
- ref={(ref) => {
259
- this.stage = ref;
287
+ {/* Wrap Stage in a styled div instead of styling Stage directly */}
288
+ <div
289
+ style={{
290
+ position: 'absolute',
291
+ left: 0,
292
+ top: 0,
293
+ touchAction: 'none',
294
+ cursor: draggable && (isOver || newDrawable.length === 1) ? 'pointer' : 'default',
260
295
  }}
261
- className={classnames(classes.stage, {
262
- [classes.active]: draggable && (isOver || (newDrawable && newDrawable.length === 1)),
263
- })}
264
- height={drawableDimensions.height}
265
- width={drawableDimensions.width}
266
- {...listeners}
267
296
  >
268
- <Layer
269
- ref={(ref) => {
270
- this.layer = ref;
271
- }}
297
+ <Stage
298
+ key="drawing-stage"
299
+ scaleX={scale}
300
+ scaleY={scale}
301
+ ref={(ref) => (this.stage = ref)}
302
+ height={drawableDimensions.height}
303
+ width={drawableDimensions.width}
304
+ {...listeners}
272
305
  >
273
- {drawables.map((drawable, key) => drawable.render({ ...drawableProps, key }))}
274
- {/* Text Entry is a special case */}
275
- {TextEntry.render(drawableProps)}
276
- </Layer>
277
- </Stage>
278
- </div>
279
- </div>
306
+ <Layer ref={(ref) => (this.layer = ref)}>
307
+ {drawables.map((drawable, key) => drawable.render({ ...drawableProps, key }))}
308
+ {TextEntry.render(drawableProps)}
309
+ </Layer>
310
+ </Stage>
311
+ </div>
312
+ </Base>
313
+ </Wrapper>
280
314
  );
281
315
  }
282
316
  }
283
317
 
284
- const styles = () => ({
285
- wrapper: {
286
- display: 'flex',
287
- flexWrap: 'wrap',
288
- justifyContent: 'flex-end',
289
- },
290
- base: {
291
- position: 'relative',
292
- width: '100%',
293
- },
294
- stage: {
295
- left: 0,
296
- position: 'absolute',
297
- touchAction: 'none',
298
- top: 0,
299
- },
300
- active: {
301
- cursor: 'pointer',
302
- },
303
- undoControls: {
304
- marginTop: -43,
305
- marginRight: 10,
306
- position: 'absolute',
307
- },
308
- });
309
-
310
318
  DrawableMain.propTypes = {
311
- classes: PropTypes.object.isRequired,
312
319
  disabled: PropTypes.bool,
313
320
  drawableDimensions: PropTypes.object.isRequired,
314
321
  imageDimensions: PropTypes.object.isRequired,
@@ -325,4 +332,4 @@ DrawableMain.propTypes = {
325
332
  language: PropTypes.string,
326
333
  };
327
334
 
328
- export default withStyles(styles)(DrawableMain);
335
+ export default DrawableMain;
@@ -1,14 +1,41 @@
1
1
  import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
3
  import { InputContainer } from '@pie-lib/render-ui';
4
- import Select from '@material-ui/core/Select';
5
- import MenuItem from '@material-ui/core/MenuItem';
6
- import { withStyles } from '@material-ui/core/styles';
7
- import classnames from 'classnames';
4
+ import Select from '@mui/material/Select';
5
+ import MenuItem from '@mui/material/MenuItem';
6
+ import { styled } from '@mui/material/styles';
8
7
  import Translator from '@pie-lib/translator';
9
8
 
10
9
  const { translator } = Translator;
11
10
 
11
+ const BaseContainer = styled('div')(({ theme }) => ({
12
+ marginTop: theme.spacing(2),
13
+ display: 'flex',
14
+ }));
15
+
16
+ const StyledInputContainer = styled(InputContainer)({
17
+ flex: 1,
18
+ fontSize: 'inherit',
19
+ width: '90%',
20
+ });
21
+
22
+ const StyledMenuItem = styled(MenuItem)(({ theme, isBlackColor }) => ({
23
+ borderRadius: '2px',
24
+ fontSize: 'inherit',
25
+ height: '22px',
26
+ marginLeft: theme.spacing(2),
27
+ marginRight: theme.spacing(2),
28
+ marginTop: theme.spacing(2),
29
+ ...(isBlackColor && {
30
+ color: theme.palette.background.paper,
31
+ }),
32
+ }));
33
+
34
+ const StyledSelect = styled(Select)({
35
+ fontSize: 'inherit',
36
+ transform: 'translate(0%, 40%)',
37
+ });
38
+
12
39
  // TODO: Change Palette so will render inputs and colors dynamically
13
40
  class Palette extends React.Component {
14
41
  onChange = (name) => (event) => {
@@ -25,73 +52,40 @@ class Palette extends React.Component {
25
52
  };
26
53
 
27
54
  render() {
28
- const { classes, fillColor, outlineColor, fillList, outlineList, language } = this.props;
55
+ const { fillColor, outlineColor, fillList, outlineList, language } = this.props;
29
56
 
30
57
  return (
31
- <div className={classes.base}>
32
- <InputContainer label={translator.t('drawingResponse.fillColor', { lng: language })} className={classes.input}>
33
- <Select className={classes.select} onChange={this.onChange('fill')} value={fillColor}>
58
+ <BaseContainer>
59
+ <StyledInputContainer label={translator.t('drawingResponse.fillColor', { lng: language })}>
60
+ <StyledSelect onChange={this.onChange('fill')} value={fillColor} variant='standard' MenuProps={{ transitionDuration: { enter: 225, exit: 195 } }}>
34
61
  {fillList.map(({ value, label }) => (
35
- <MenuItem
62
+ <StyledMenuItem
36
63
  key={value}
37
64
  value={value}
38
- className={classnames(classes.item, {
39
- [classes.blackColorItem]: value === 'black',
40
- })}
65
+ isBlackColor={value === 'black'}
41
66
  style={{ backgroundColor: value }}
42
67
  >
43
68
  {label}
44
- </MenuItem>
69
+ </StyledMenuItem>
45
70
  ))}
46
- </Select>
47
- </InputContainer>
71
+ </StyledSelect>
72
+ </StyledInputContainer>
48
73
 
49
- <InputContainer
50
- label={translator.t('drawingResponse.outlineColor', { lng: language })}
51
- className={classes.input}
52
- >
53
- <Select className={classes.select} onChange={this.onChange('outline')} value={outlineColor}>
74
+ <StyledInputContainer label={translator.t('drawingResponse.outlineColor', { lng: language })}>
75
+ <StyledSelect onChange={this.onChange('outline')} value={outlineColor} variant='standard' MenuProps={{ transitionDuration: { enter: 225, exit: 195 } }}>
54
76
  {outlineList.map(({ value, label }) => (
55
- <MenuItem key={value} value={value} className={classes.item} style={{ border: `2px solid ${value}` }}>
77
+ <StyledMenuItem key={value} value={value} style={{ border: `2px solid ${value}` }}>
56
78
  {label}
57
- </MenuItem>
79
+ </StyledMenuItem>
58
80
  ))}
59
- </Select>
60
- </InputContainer>
61
- </div>
81
+ </StyledSelect>
82
+ </StyledInputContainer>
83
+ </BaseContainer>
62
84
  );
63
85
  }
64
86
  }
65
87
 
66
- const styles = (theme) => ({
67
- base: {
68
- marginTop: theme.spacing.unit * 2,
69
- display: 'flex',
70
- },
71
- input: {
72
- flex: 1,
73
- fontSize: 'inherit',
74
- width: '90%',
75
- },
76
- item: {
77
- borderRadius: '2px',
78
- fontSize: 'inherit',
79
- height: '22px',
80
- marginLeft: theme.spacing.unit * 2,
81
- marginRight: theme.spacing.unit * 2,
82
- marginTop: theme.spacing.unit * 2,
83
- },
84
- blackColorItem: {
85
- color: theme.palette.background.paper,
86
- },
87
- select: {
88
- fontSize: 'inherit',
89
- transform: 'translate(0%, 40%)',
90
- },
91
- });
92
-
93
88
  Palette.propTypes = {
94
- classes: PropTypes.object.isRequired,
95
89
  fillColor: PropTypes.string.isRequired,
96
90
  fillList: PropTypes.array.isRequired,
97
91
  onFillColorChange: PropTypes.func.isRequired,
@@ -102,4 +96,4 @@ Palette.propTypes = {
102
96
  language: PropTypes.string,
103
97
  };
104
98
 
105
- export default withStyles(styles)(Palette);
99
+ export default Palette;
@@ -38,6 +38,7 @@ export default class TextDrawable {
38
38
 
39
39
  all.push({
40
40
  id: id,
41
+ text: '',
41
42
  isDefault: true,
42
43
  label: translator.t('drawingResponse.onDoubleClick', { lng: language }),
43
44
  width: 200,
@@ -83,15 +84,19 @@ export default class TextDrawable {
83
84
  }
84
85
  }
85
86
 
86
- saveValue(id, textNode, textareaNode) {
87
- if (textareaNode.value) {
88
- textNode.text(textareaNode.value);
89
- } else {
90
- this.all = this.all.filter((text) => text.id !== id);
91
- this.props.forceUpdate();
87
+ saveValue(id, textareaNode) {
88
+ const value = textareaNode.value;
89
+ this.all = this.all.map((t) =>
90
+ t.id === id ? { ...t, text: value } : t
91
+ );
92
+
93
+ if (!value) {
94
+ this.all = this.all.filter((t) => t.id !== id);
92
95
  }
93
96
 
97
+ this.toggleTextarea(id, false);
94
98
  this.props.handleSessionChange();
99
+ this.props.forceUpdate();
95
100
  }
96
101
 
97
102
  handleMouseDown = () => this.props.toggleTextSelected(true);
@@ -110,9 +115,11 @@ export default class TextDrawable {
110
115
  const textNode = this[TextDrawable.getTextNode(id)];
111
116
  const textareaNode = this[TextDrawable.getTextareaNode(id)];
112
117
 
113
- const areaPosition = textNode._lastPos;
118
+ if (!textNode || !textareaNode) return;
114
119
 
115
- textareaNode.value = isDefault ? '' : textNode.text();
120
+ const areaPosition = textNode.getAbsolutePosition();
121
+
122
+ textareaNode.value = text.text || '';
116
123
  textareaNode.style.position = 'absolute';
117
124
  textareaNode.style.top = areaPosition.y + 'px';
118
125
  textareaNode.style.left = areaPosition.x + 'px';
@@ -131,53 +138,34 @@ export default class TextDrawable {
131
138
  textareaNode.style.transformOrigin = 'left top';
132
139
  textareaNode.style.textAlign = textNode.align();
133
140
  textareaNode.style.color = textNode.fill();
141
+ textareaNode.style.display = 'block';
134
142
 
135
143
  let rotation = textNode.rotation();
136
- let transform = '';
137
- if (rotation) {
138
- transform += 'rotateZ(' + rotation + 'deg)';
139
- }
140
-
141
- let px = 0;
142
- const isFirefox = navigator.userAgent.toLowerCase().indexOf('firefox') > -1;
143
-
144
- if (isFirefox) {
145
- px += 2 + Math.round(textNode.fontSize() / 20);
146
- }
147
-
148
- transform += 'translateY(-' + px + 'px)';
149
-
150
- textareaNode.style.transform = transform;
151
- textareaNode.style.height = 'auto';
152
- textareaNode.style.height = textareaNode.scrollHeight + 3 + 'px';
144
+ textareaNode.style.transform = rotation ? `rotateZ(${rotation}deg)` : '';
153
145
 
154
146
  textareaNode.focus();
155
147
 
156
148
  const keyDownHandler = (e) => {
157
- // hide on enter but don't hide on shift + enter
158
- if (e.keyCode === 13 && !e.shiftKey) {
159
- this.toggleTextarea(id, false);
160
- this.saveValue(id, textNode, textareaNode);
149
+ if (e.key === 'Enter' && !e.shiftKey) {
150
+ this.saveValue(id, textareaNode);
161
151
  }
162
-
163
- // on esc do not set value back to node
164
- if (e.keyCode === 27) {
152
+ if (e.key === 'Escape') {
165
153
  this.toggleTextarea(id, false);
166
154
  }
167
155
  };
168
156
 
169
- textareaNode.addEventListener('keydown', keyDownHandler);
170
-
171
- this.eventListenersDetachArray.push(() => textareaNode.removeEventListener('keydown', keyDownHandler));
172
-
173
157
  const blurHandler = () => {
174
158
  this.showOnlyTextNodes();
175
- this.saveValue(id, textNode, textareaNode);
159
+ this.saveValue(id, textareaNode);
176
160
  };
177
161
 
162
+ textareaNode.addEventListener('keydown', keyDownHandler);
178
163
  textareaNode.addEventListener('blur', blurHandler);
179
164
 
180
- this.eventListenersDetachArray.push(() => textareaNode.removeEventListener('blur', blurHandler));
165
+ this.eventListenersDetachArray.push(() => {
166
+ textareaNode.removeEventListener('keydown', keyDownHandler);
167
+ textareaNode.removeEventListener('blur', blurHandler);
168
+ });
181
169
 
182
170
  this.initializeDefault(id, isDefault);
183
171
  this.props.forceUpdate();