@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.
- package/CHANGELOG.md +8 -0
- package/lib/editor.js +1 -1
- package/lib/editor.js.map +1 -1
- package/lib/index.js +3 -1
- package/lib/index.js.map +1 -1
- package/lib/plugins/image/alt-dialog.js +119 -0
- package/lib/plugins/image/alt-dialog.js.map +1 -0
- package/lib/plugins/image/component.js +3 -1
- package/lib/plugins/image/component.js.map +1 -1
- package/lib/plugins/image/image-toolbar.js +52 -4
- package/lib/plugins/image/image-toolbar.js.map +1 -1
- package/lib/plugins/image/index.js +11 -6
- package/lib/plugins/image/index.js.map +1 -1
- package/lib/plugins/respArea/index.js.map +1 -1
- package/lib/plugins/table/index.js.map +1 -1
- package/package.json +3 -3
- package/src/editor.jsx +1 -1
- package/src/index.jsx +2 -2
- package/src/plugins/image/alt-dialog.jsx +69 -0
- package/src/plugins/image/component.jsx +2 -0
- package/src/plugins/image/image-toolbar.jsx +44 -4
- package/src/plugins/image/index.jsx +12 -5
- package/src/plugins/respArea/index.jsx +0 -1
- package/src/plugins/table/index.jsx +3 -1
|
@@ -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
|
|
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
|
-
|
|
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 = () =>
|
|
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} />;
|
|
@@ -79,7 +79,9 @@ TableCell.propTypes = {
|
|
|
79
79
|
};
|
|
80
80
|
|
|
81
81
|
export const moveFocusToBeginningOfTable = change => {
|
|
82
|
-
const addedTable = change.value.document.findDescendant(
|
|
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;
|