@pie-lib/editable-html 7.17.4-next.371 → 7.17.4-next.414
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/lib/editor.js +116 -110
- package/lib/editor.js.map +1 -1
- package/lib/index.js +30 -42
- package/lib/index.js.map +1 -1
- package/lib/plugins/characters/custom-popover.js +8 -11
- package/lib/plugins/characters/custom-popover.js.map +1 -1
- package/lib/plugins/characters/index.js +8 -18
- package/lib/plugins/characters/index.js.map +1 -1
- package/lib/plugins/image/component.js +65 -54
- package/lib/plugins/image/component.js.map +1 -1
- package/lib/plugins/image/image-toolbar.js +65 -27
- package/lib/plugins/image/image-toolbar.js.map +1 -1
- package/lib/plugins/image/index.js +47 -12
- package/lib/plugins/image/index.js.map +1 -1
- package/lib/plugins/image/insert-image-handler.js +8 -12
- package/lib/plugins/image/insert-image-handler.js.map +1 -1
- package/lib/plugins/index.js +6 -15
- package/lib/plugins/index.js.map +1 -1
- package/lib/plugins/list/index.js +2 -2
- package/lib/plugins/list/index.js.map +1 -1
- package/lib/plugins/math/index.js +8 -8
- package/lib/plugins/math/index.js.map +1 -1
- package/lib/plugins/media/index.js +15 -20
- package/lib/plugins/media/index.js.map +1 -1
- package/lib/plugins/media/media-dialog.js +26 -41
- package/lib/plugins/media/media-dialog.js.map +1 -1
- package/lib/plugins/media/media-toolbar.js +15 -25
- package/lib/plugins/media/media-toolbar.js.map +1 -1
- package/lib/plugins/media/media-wrapper.js +22 -35
- package/lib/plugins/media/media-wrapper.js.map +1 -1
- package/lib/plugins/respArea/drag-in-the-blank/choice.js +24 -37
- package/lib/plugins/respArea/drag-in-the-blank/choice.js.map +1 -1
- package/lib/plugins/respArea/drag-in-the-blank/index.js +8 -8
- package/lib/plugins/respArea/drag-in-the-blank/index.js.map +1 -1
- package/lib/plugins/respArea/explicit-constructed-response/index.js +5 -5
- package/lib/plugins/respArea/explicit-constructed-response/index.js.map +1 -1
- package/lib/plugins/respArea/icons/index.js +5 -5
- package/lib/plugins/respArea/icons/index.js.map +1 -1
- package/lib/plugins/respArea/index.js +2 -2
- package/lib/plugins/respArea/index.js.map +1 -1
- package/lib/plugins/respArea/inline-dropdown/index.js +5 -5
- package/lib/plugins/respArea/inline-dropdown/index.js.map +1 -1
- package/lib/plugins/respArea/utils.js +2 -2
- package/lib/plugins/respArea/utils.js.map +1 -1
- package/lib/plugins/table/icons/index.js +9 -9
- package/lib/plugins/table/icons/index.js.map +1 -1
- package/lib/plugins/table/index.js +11 -11
- package/lib/plugins/table/index.js.map +1 -1
- package/lib/plugins/table/table-toolbar.js +25 -36
- package/lib/plugins/table/table-toolbar.js.map +1 -1
- package/lib/plugins/toolbar/default-toolbar.js +5 -5
- package/lib/plugins/toolbar/default-toolbar.js.map +1 -1
- package/lib/plugins/toolbar/done-button.js +2 -2
- package/lib/plugins/toolbar/done-button.js.map +1 -1
- package/lib/plugins/toolbar/editor-and-toolbar.js +18 -30
- package/lib/plugins/toolbar/editor-and-toolbar.js.map +1 -1
- package/lib/plugins/toolbar/index.js +5 -5
- package/lib/plugins/toolbar/index.js.map +1 -1
- package/lib/plugins/toolbar/toolbar-buttons.js +25 -43
- package/lib/plugins/toolbar/toolbar-buttons.js.map +1 -1
- package/lib/plugins/toolbar/toolbar.js +30 -49
- package/lib/plugins/toolbar/toolbar.js.map +1 -1
- package/lib/serialization.js +2 -2
- package/lib/serialization.js.map +1 -1
- package/package.json +5 -5
- package/src/editor.jsx +48 -25
- package/src/plugins/image/component.jsx +49 -20
- package/src/plugins/image/image-toolbar.jsx +37 -2
- package/src/plugins/image/index.jsx +38 -9
|
@@ -22,7 +22,7 @@ export class Component extends React.Component {
|
|
|
22
22
|
onFocus: PropTypes.func,
|
|
23
23
|
onBlur: PropTypes.func,
|
|
24
24
|
maxImageWidth: PropTypes.number,
|
|
25
|
-
maxImageHeight: PropTypes.number
|
|
25
|
+
maxImageHeight: PropTypes.number
|
|
26
26
|
};
|
|
27
27
|
|
|
28
28
|
getWidth = percent => {
|
|
@@ -50,7 +50,7 @@ export class Component extends React.Component {
|
|
|
50
50
|
update = update.set('resizePercent', this.getPercentFromWidth(w));
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
log(
|
|
53
|
+
log('[applySizeData] update: ', update);
|
|
54
54
|
|
|
55
55
|
if (!update.equals(node.data)) {
|
|
56
56
|
editor.change(c => c.setNodeByKey(node.key, { data: update }));
|
|
@@ -93,7 +93,10 @@ export class Component extends React.Component {
|
|
|
93
93
|
|
|
94
94
|
//on first load
|
|
95
95
|
if (!box.style.width || box.style.width === 'auto') {
|
|
96
|
-
const dimensions = {
|
|
96
|
+
const dimensions = {
|
|
97
|
+
width: (box && box.naturalWidth) || 100,
|
|
98
|
+
height: (box && box.naturalHeight) || 100
|
|
99
|
+
};
|
|
97
100
|
|
|
98
101
|
const { width, height } = this.updateImageDimensions(
|
|
99
102
|
dimensions,
|
|
@@ -108,7 +111,7 @@ export class Component extends React.Component {
|
|
|
108
111
|
box.style.height = `${height}px`;
|
|
109
112
|
|
|
110
113
|
this.setState({
|
|
111
|
-
dimensions: { height: height, width: width }
|
|
114
|
+
dimensions: { height: height, width: width }
|
|
112
115
|
});
|
|
113
116
|
|
|
114
117
|
const { node, editor } = this.props;
|
|
@@ -124,10 +127,13 @@ export class Component extends React.Component {
|
|
|
124
127
|
}
|
|
125
128
|
};
|
|
126
129
|
|
|
127
|
-
startResizing =
|
|
130
|
+
startResizing = e => {
|
|
128
131
|
const bounds = e.target.getBoundingClientRect();
|
|
129
132
|
const box = this.img;
|
|
130
|
-
const dimensions = {
|
|
133
|
+
const dimensions = {
|
|
134
|
+
width: (box && box.naturalWidth) || 100,
|
|
135
|
+
height: (box && box.naturalHeight) || 100
|
|
136
|
+
};
|
|
131
137
|
|
|
132
138
|
const { width, height } = this.updateImageDimensions(
|
|
133
139
|
dimensions,
|
|
@@ -177,32 +183,52 @@ export class Component extends React.Component {
|
|
|
177
183
|
return {
|
|
178
184
|
width: nextDim.height * imageAspectRatio,
|
|
179
185
|
height: nextDim.height
|
|
180
|
-
}
|
|
186
|
+
};
|
|
181
187
|
}
|
|
182
188
|
|
|
183
189
|
// if we want to change image width => we update the height accordingly
|
|
184
190
|
return {
|
|
185
191
|
width: nextDim.width,
|
|
186
192
|
height: nextDim.width / imageAspectRatio
|
|
187
|
-
}
|
|
193
|
+
};
|
|
188
194
|
}
|
|
189
195
|
|
|
190
196
|
// if we don't want to keep aspect ratio, we just update both values
|
|
191
197
|
return {
|
|
192
198
|
width: nextDim.width,
|
|
193
199
|
height: nextDim.height
|
|
194
|
-
}
|
|
200
|
+
};
|
|
195
201
|
};
|
|
196
202
|
|
|
197
|
-
|
|
198
203
|
render() {
|
|
199
204
|
const { node, editor, classes, attributes, onFocus } = this.props;
|
|
200
205
|
const active = editor.value.isFocused && editor.value.selection.hasEdgeIn(node);
|
|
201
206
|
const src = node.data.get('src');
|
|
202
|
-
const percent = node.data.get('percent');
|
|
203
207
|
const loaded = node.data.get('loaded') !== false;
|
|
204
208
|
const deleteStatus = node.data.get('deleteStatus');
|
|
205
|
-
|
|
209
|
+
const alignment = node.data.get('alignment');
|
|
210
|
+
const percent = node.data.get('percent');
|
|
211
|
+
let margin;
|
|
212
|
+
let justifyContent;
|
|
213
|
+
|
|
214
|
+
switch (alignment) {
|
|
215
|
+
case 'left':
|
|
216
|
+
justifyContent = 'flex-start';
|
|
217
|
+
margin = '0';
|
|
218
|
+
break;
|
|
219
|
+
case 'center':
|
|
220
|
+
justifyContent = 'center';
|
|
221
|
+
margin = '0 auto';
|
|
222
|
+
break;
|
|
223
|
+
case 'right':
|
|
224
|
+
justifyContent = 'flex-end';
|
|
225
|
+
margin = 'auto 0 0 auto ';
|
|
226
|
+
break;
|
|
227
|
+
default:
|
|
228
|
+
justifyContent = 'flex-start';
|
|
229
|
+
margin = '0';
|
|
230
|
+
break;
|
|
231
|
+
}
|
|
206
232
|
log('[render] node.data:', node.data);
|
|
207
233
|
|
|
208
234
|
const size = this.getSize(node.data);
|
|
@@ -219,7 +245,7 @@ export class Component extends React.Component {
|
|
|
219
245
|
|
|
220
246
|
return [
|
|
221
247
|
<span key={'sp1'}> </span>,
|
|
222
|
-
<div key={'comp'} onFocus={onFocus} className={className}>
|
|
248
|
+
<div key={'comp'} onFocus={onFocus} className={className} style={{ justifyContent }}>
|
|
223
249
|
<LinearProgress
|
|
224
250
|
mode="determinate"
|
|
225
251
|
value={percent > 0 ? percent : 0}
|
|
@@ -236,9 +262,12 @@ export class Component extends React.Component {
|
|
|
236
262
|
style={size}
|
|
237
263
|
onLoad={this.loadImage}
|
|
238
264
|
/>
|
|
239
|
-
<div
|
|
240
|
-
|
|
241
|
-
|
|
265
|
+
<div
|
|
266
|
+
ref={ref => {
|
|
267
|
+
this.resize = ref;
|
|
268
|
+
}}
|
|
269
|
+
className={classNames(classes.resize, 'resize')}
|
|
270
|
+
/>
|
|
242
271
|
</div>
|
|
243
272
|
</div>,
|
|
244
273
|
<span key={'sp2'}> </span>
|
|
@@ -264,7 +293,7 @@ const styles = theme => ({
|
|
|
264
293
|
progress: {
|
|
265
294
|
position: 'absolute',
|
|
266
295
|
left: '0',
|
|
267
|
-
width: '
|
|
296
|
+
width: 'fit-content',
|
|
268
297
|
top: '0%',
|
|
269
298
|
transition: 'opacity 200ms linear'
|
|
270
299
|
},
|
|
@@ -280,7 +309,7 @@ const styles = theme => ({
|
|
|
280
309
|
root: {
|
|
281
310
|
position: 'relative',
|
|
282
311
|
border: 'solid 1px white',
|
|
283
|
-
display: '
|
|
312
|
+
display: 'flex',
|
|
284
313
|
transition: 'opacity 200ms linear'
|
|
285
314
|
},
|
|
286
315
|
delete: {
|
|
@@ -311,8 +340,8 @@ const styles = theme => ({
|
|
|
311
340
|
display: 'none'
|
|
312
341
|
},
|
|
313
342
|
drawableHeight: {
|
|
314
|
-
minHeight: 350
|
|
315
|
-
}
|
|
343
|
+
minHeight: 350
|
|
344
|
+
}
|
|
316
345
|
});
|
|
317
346
|
|
|
318
347
|
export default withStyles(styles)(Component);
|
|
@@ -2,20 +2,55 @@ import PropTypes from 'prop-types';
|
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import debug from 'debug';
|
|
4
4
|
import { withStyles } from '@material-ui/core/styles';
|
|
5
|
+
import { MarkButton } from '../toolbar/toolbar-buttons';
|
|
5
6
|
|
|
6
7
|
const log = debug('@pie-lib:editable-html:plugins:image:image-toolbar');
|
|
7
8
|
|
|
9
|
+
const AlignmentButton = ({ alignment, active, onClick }) => {
|
|
10
|
+
return (
|
|
11
|
+
<MarkButton active={active} onToggle={() => onClick(alignment)} label={alignment}>
|
|
12
|
+
{alignment}
|
|
13
|
+
</MarkButton>
|
|
14
|
+
);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
AlignmentButton.propTypes = {
|
|
18
|
+
alignment: PropTypes.string.isRequired,
|
|
19
|
+
active: PropTypes.bool.isRequired,
|
|
20
|
+
onClick: PropTypes.func.isRequired
|
|
21
|
+
};
|
|
22
|
+
|
|
8
23
|
export class ImageToolbar extends React.Component {
|
|
9
24
|
static propTypes = {
|
|
10
25
|
onChange: PropTypes.func.isRequired,
|
|
11
26
|
classes: PropTypes.object.isRequired
|
|
12
27
|
};
|
|
13
28
|
|
|
29
|
+
onAlignmentClick = alignment => {
|
|
30
|
+
log('[onAlignmentClick]: alignment:', alignment);
|
|
31
|
+
this.props.onChange(alignment);
|
|
32
|
+
};
|
|
33
|
+
|
|
14
34
|
render() {
|
|
15
|
-
|
|
16
|
-
|
|
35
|
+
const { classes, alignment } = this.props;
|
|
36
|
+
|
|
17
37
|
return (
|
|
18
38
|
<div className={classes.holder}>
|
|
39
|
+
<AlignmentButton
|
|
40
|
+
alignment={'left'}
|
|
41
|
+
active={alignment === 'left'}
|
|
42
|
+
onClick={this.onAlignmentClick}
|
|
43
|
+
/>
|
|
44
|
+
<AlignmentButton
|
|
45
|
+
alignment={'center'}
|
|
46
|
+
active={alignment === 'center'}
|
|
47
|
+
onClick={this.onAlignmentClick}
|
|
48
|
+
/>
|
|
49
|
+
<AlignmentButton
|
|
50
|
+
alignment={'right'}
|
|
51
|
+
active={alignment === 'right'}
|
|
52
|
+
onClick={this.onAlignmentClick}
|
|
53
|
+
/>
|
|
19
54
|
</div>
|
|
20
55
|
);
|
|
21
56
|
}
|
|
@@ -29,19 +29,18 @@ export default function ImagePlugin(opts) {
|
|
|
29
29
|
},
|
|
30
30
|
supports: node => node.object === 'inline' && node.type === 'image',
|
|
31
31
|
customToolbar: (node, value, onToolbarDone) => {
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
const onChange = resizePercent => {
|
|
32
|
+
const alignment = node.data.get('alignment');
|
|
33
|
+
const onChange = alignment => {
|
|
35
34
|
const update = {
|
|
36
35
|
...node.data.toObject(),
|
|
37
|
-
|
|
36
|
+
alignment
|
|
38
37
|
};
|
|
39
38
|
|
|
40
39
|
const change = value.change().setNodeByKey(node.key, { data: update });
|
|
41
40
|
onToolbarDone(change, false);
|
|
42
41
|
};
|
|
43
42
|
|
|
44
|
-
const Tb = () => <ImageToolbar
|
|
43
|
+
const Tb = () => <ImageToolbar alignment={alignment || 'left'} onChange={onChange} />;
|
|
45
44
|
return Tb;
|
|
46
45
|
},
|
|
47
46
|
showDone: true
|
|
@@ -92,7 +91,7 @@ export default function ImagePlugin(opts) {
|
|
|
92
91
|
onFocus: opts.onFocus,
|
|
93
92
|
onBlur: opts.onBlur,
|
|
94
93
|
maxImageWidth: opts.maxImageWidth,
|
|
95
|
-
maxImageHeight: opts.maxImageHeight
|
|
94
|
+
maxImageHeight: opts.maxImageHeight
|
|
96
95
|
},
|
|
97
96
|
props
|
|
98
97
|
);
|
|
@@ -137,7 +136,7 @@ export const serialization = {
|
|
|
137
136
|
if (name !== 'img') return;
|
|
138
137
|
|
|
139
138
|
log('deserialize: ', name);
|
|
140
|
-
const style = el.style || { width: '', height: '' };
|
|
139
|
+
const style = el.style || { width: '', height: '', margin: '', justifyContent: '' };
|
|
141
140
|
const width = parseInt(style.width.replace('px', ''), 10) || null;
|
|
142
141
|
const height = parseInt(style.height.replace('px', ''), 10) || null;
|
|
143
142
|
|
|
@@ -148,7 +147,10 @@ export const serialization = {
|
|
|
148
147
|
data: {
|
|
149
148
|
src: el.getAttribute('src'),
|
|
150
149
|
width,
|
|
151
|
-
height
|
|
150
|
+
height,
|
|
151
|
+
margin: el.style.margin,
|
|
152
|
+
justifyContent: el.style.justifyContent,
|
|
153
|
+
alignment: el.getAttribute('alignment')
|
|
152
154
|
}
|
|
153
155
|
};
|
|
154
156
|
log('return object: ', out);
|
|
@@ -161,6 +163,9 @@ export const serialization = {
|
|
|
161
163
|
const src = data.get('src');
|
|
162
164
|
const width = data.get('width');
|
|
163
165
|
const height = data.get('height');
|
|
166
|
+
const alignment = data.get('alignment');
|
|
167
|
+
const margin = data.get('margin');
|
|
168
|
+
const justifyContent = data.get('margin');
|
|
164
169
|
const style = {};
|
|
165
170
|
if (width) {
|
|
166
171
|
style.width = `${width}px`;
|
|
@@ -170,11 +175,35 @@ export const serialization = {
|
|
|
170
175
|
style.height = `${height}px`;
|
|
171
176
|
}
|
|
172
177
|
|
|
178
|
+
style.margin = margin;
|
|
179
|
+
style.justifyContent = justifyContent;
|
|
180
|
+
|
|
181
|
+
if (alignment) {
|
|
182
|
+
switch (alignment) {
|
|
183
|
+
case 'left':
|
|
184
|
+
style.justifyContent = 'flex-start';
|
|
185
|
+
style.margin = '0';
|
|
186
|
+
break;
|
|
187
|
+
case 'center':
|
|
188
|
+
style.justifyContent = 'center';
|
|
189
|
+
style.margin = '0 auto';
|
|
190
|
+
break;
|
|
191
|
+
case 'right':
|
|
192
|
+
style.justifyContent = 'flex-end';
|
|
193
|
+
style.margin = 'auto 0 0 auto';
|
|
194
|
+
break;
|
|
195
|
+
default:
|
|
196
|
+
style.justifyContent = 'flex-start';
|
|
197
|
+
break;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
173
201
|
style.objectFit = 'contain';
|
|
174
202
|
|
|
175
203
|
const props = {
|
|
176
204
|
src,
|
|
177
|
-
style
|
|
205
|
+
style,
|
|
206
|
+
alignment
|
|
178
207
|
};
|
|
179
208
|
|
|
180
209
|
return <img {...props} />;
|