@pie-lib/editable-html 9.0.4 → 9.0.5

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.
@@ -1,9 +1,12 @@
1
1
  import PropTypes from 'prop-types';
2
2
  import React from 'react';
3
3
  import debug from 'debug';
4
+ import ReactDOM from 'react-dom';
4
5
  import { withStyles } from '@material-ui/core/styles';
6
+ import classNames from 'classnames';
5
7
 
6
8
  import { MarkButton } from '../toolbar/toolbar-buttons';
9
+ import AltDialog from './alt-dialog';
7
10
 
8
11
  const log = debug('@pie-lib:editable-html:plugins:image:image-toolbar');
9
12
 
@@ -24,16 +27,36 @@ AlignmentButton.propTypes = {
24
27
  export class ImageToolbar extends React.Component {
25
28
  static propTypes = {
26
29
  onChange: PropTypes.func.isRequired,
27
- classes: PropTypes.object.isRequired
30
+ classes: PropTypes.object.isRequired,
31
+ alignment: PropTypes.string,
32
+ alt: PropTypes.string,
33
+ imageLoaded: PropTypes.bool
34
+ };
35
+
36
+ onAltTextDone = newAlt => {
37
+ log('[onAltTextDone]: alt:', newAlt);
38
+
39
+ this.props.onChange({ alt: newAlt });
28
40
  };
29
41
 
30
42
  onAlignmentClick = alignment => {
31
43
  log('[onAlignmentClick]: alignment:', alignment);
32
- this.props.onChange(alignment);
44
+ this.props.onChange({ alignment });
45
+ };
46
+
47
+ renderDialog = () => {
48
+ const { alt } = this.props;
49
+ const popoverEl = document.createElement('div');
50
+
51
+ const el = <AltDialog alt={alt} onDone={this.onAltTextDone} />;
52
+
53
+ ReactDOM.render(el, popoverEl);
54
+
55
+ document.body.appendChild(popoverEl);
33
56
  };
34
57
 
35
58
  render() {
36
- const { classes, alignment } = this.props;
59
+ const { classes, alignment, imageLoaded } = this.props;
37
60
 
38
61
  return (
39
62
  <div className={classes.holder}>
@@ -52,6 +75,15 @@ export class ImageToolbar extends React.Component {
52
75
  active={alignment === 'right'}
53
76
  onClick={this.onAlignmentClick}
54
77
  />
78
+ <span
79
+ className={classNames({
80
+ [classes.disabled]: !imageLoaded,
81
+ [classes.altButton]: true
82
+ })}
83
+ onMouseDown={event => imageLoaded && this.renderDialog(event)}
84
+ >
85
+ Alt text
86
+ </span>
55
87
  </div>
56
88
  );
57
89
  }
@@ -62,7 +94,15 @@ const styles = theme => ({
62
94
  paddingLeft: theme.spacing.unit,
63
95
  display: 'flex',
64
96
  alignItems: 'center'
65
- }
97
+ },
98
+ disabled: {
99
+ opacity: 0.5
100
+ },
101
+ altButton: {
102
+ borderLeft: '1px solid grey',
103
+ paddingLeft: 8,
104
+ marginLeft: 4,
105
+ },
66
106
  });
67
107
 
68
108
  export default withStyles(styles)(ImageToolbar);
@@ -30,17 +30,21 @@ export default function ImagePlugin(opts) {
30
30
  supports: node => node.object === 'inline' && node.type === 'image',
31
31
  customToolbar: (node, value, onToolbarDone) => {
32
32
  const alignment = node.data.get('alignment');
33
- const onChange = alignment => {
33
+ const alt = node.data.get('alt');
34
+ const imageLoaded = node.data.get('loaded') !== false;
35
+ const onChange = newValues => {
34
36
  const update = {
35
37
  ...node.data.toObject(),
36
- alignment
38
+ ...newValues
37
39
  };
38
40
 
39
41
  const change = value.change().setNodeByKey(node.key, { data: update });
40
42
  onToolbarDone(change, false);
41
43
  };
42
44
 
43
- const Tb = () => <ImageToolbar alignment={alignment || 'left'} onChange={onChange} />;
45
+ const Tb = () => (
46
+ <ImageToolbar alt={alt} imageLoaded={imageLoaded} alignment={alignment || 'left'} onChange={onChange} />
47
+ );
44
48
  return Tb;
45
49
  },
46
50
  showDone: true
@@ -150,7 +154,8 @@ export const serialization = {
150
154
  height,
151
155
  margin: el.style.margin,
152
156
  justifyContent: el.style.justifyContent,
153
- alignment: el.getAttribute('alignment')
157
+ alignment: el.getAttribute('alignment'),
158
+ alt: el.getAttribute('alt')
154
159
  }
155
160
  };
156
161
  log('return object: ', out);
@@ -166,6 +171,7 @@ export const serialization = {
166
171
  const alignment = data.get('alignment');
167
172
  const margin = data.get('margin');
168
173
  const justifyContent = data.get('margin');
174
+ const alt = data.get('alt');
169
175
  const style = {};
170
176
  if (width) {
171
177
  style.width = `${width}px`;
@@ -203,7 +209,8 @@ export const serialization = {
203
209
  const props = {
204
210
  src,
205
211
  style,
206
- alignment
212
+ alignment,
213
+ alt
207
214
  };
208
215
 
209
216
  return <img {...props} />;
@@ -51,7 +51,6 @@ export default function ResponseAreaPlugin(opts) {
51
51
 
52
52
  if (!lastText) {
53
53
  return;
54
-
55
54
  }
56
55
  const parentNode = value.document.getParent(lastText.key);
57
56
 
@@ -79,7 +79,9 @@ TableCell.propTypes = {
79
79
  };
80
80
 
81
81
  export const moveFocusToBeginningOfTable = change => {
82
- const addedTable = change.value.document.findDescendant(d => !!d.data && !!d.data.get('newTable'));
82
+ const addedTable = change.value.document.findDescendant(
83
+ d => !!d.data && !!d.data.get('newTable')
84
+ );
83
85
 
84
86
  if (!addedTable) {
85
87
  return;