@pie-lib/editable-html 7.22.5 → 8.1.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.
@@ -0,0 +1,444 @@
1
+ export const spanishConfig = {
2
+ characters: [
3
+ ['á', 'é', 'í', 'ó', 'ú'],
4
+ ['Á', 'É', 'Í', 'Ó', 'Ú'],
5
+ ['—', '«', '»', 'ñ', 'ü'],
6
+ ['-', '¿', '¡', 'Ñ', 'Ü']
7
+ ],
8
+ autoClose: true
9
+ };
10
+
11
+ export const specialConfig = {
12
+ hasPreview: true,
13
+ characters: [
14
+ [
15
+ {
16
+ unicode: 'U+00A2',
17
+ description: 'CENT SIGN',
18
+ write: '¢',
19
+ label: '¢'
20
+ },
21
+ {
22
+ unicode: 'U+00BF',
23
+ description: 'INVERTED QUESTION MARK',
24
+ write: '¿',
25
+ label: '¿'
26
+ },
27
+ {
28
+ unicode: 'U+00B4',
29
+ description: 'ACUTE ACCENT',
30
+ write: '´',
31
+ label: '´'
32
+ },
33
+ {
34
+ unicode: 'U+00E1',
35
+ description: 'LATIN SMALL LETTER A WITH ACUTE',
36
+ write: 'á',
37
+ label: 'á'
38
+ },
39
+ {
40
+ unicode: 'U+00E9',
41
+ description: 'LATIN SMALL LETTER E WITH ACUTE',
42
+ write: 'é',
43
+ label: 'é'
44
+ },
45
+ {
46
+ unicode: 'U+00ED',
47
+ description: 'LATIN SMALL LETTER I WITH ACUTE',
48
+ write: 'í',
49
+ label: 'í'
50
+ },
51
+ {
52
+ unicode: 'U+00F3',
53
+ description: 'LATIN SMALL LETTER O WITH ACUTE',
54
+ write: 'ó',
55
+ label: 'ó'
56
+ },
57
+ {
58
+ unicode: 'U+00FA',
59
+ description: 'LATIN SMALL LETTER U WITH ACUTE',
60
+ write: 'ú',
61
+ label: 'ú'
62
+ },
63
+ {
64
+ unicode: 'U+00F1',
65
+ description: 'LATIN SMALL LETTER N WITH TILDE',
66
+ write: 'ñ',
67
+ label: 'ñ'
68
+ }
69
+ ],
70
+ [
71
+ {
72
+ unicode: 'U+20AC',
73
+ description: 'EURO SIGN',
74
+ write: '€',
75
+ label: '€'
76
+ },
77
+ {
78
+ unicode: 'U+00A1',
79
+ description: 'INVERTED EXCLAMATION MARK',
80
+ write: '¡',
81
+ label: '¡'
82
+ },
83
+ {
84
+ unicode: 'U+00C1',
85
+ description: 'LATIN CAPITAL LETTER A WITH ACUTE',
86
+ write: 'Á',
87
+ label: 'Á'
88
+ },
89
+ {
90
+ unicode: 'U+00C9',
91
+ description: 'LATIN CAPITAL LETTER E WITH ACUTE',
92
+ write: 'É',
93
+ label: 'É'
94
+ },
95
+ {
96
+ unicode: 'U+00CD',
97
+ description: 'LATIN CAPITAL LETTER I WITH ACUTE',
98
+ write: 'Í',
99
+ label: 'Í'
100
+ },
101
+ {
102
+ unicode: 'U+00D3',
103
+ description: 'LATIN CAPITAL LETTER O WITH ACUTE',
104
+ write: 'Ó',
105
+ label: 'Ó'
106
+ },
107
+ {
108
+ unicode: 'U+00DA',
109
+ description: 'LATIN CAPITAL LETTER U WITH ACUTE',
110
+ write: 'Ú',
111
+ label: 'Ú'
112
+ },
113
+ {
114
+ unicode: 'U+00D1',
115
+ description: 'LATIN CAPITAL LETTER N WITH TILDE',
116
+ write: 'Ñ',
117
+ label: 'Ñ'
118
+ }
119
+ ],
120
+ [
121
+ {
122
+ unicode: 'U+00A3',
123
+ description: 'POUND SIGN',
124
+ write: '£',
125
+ label: '£'
126
+ },
127
+ {
128
+ unicode: 'U+00AB',
129
+ description: 'LEFT-POINTING DOUBLE ANGLE QUOTATION MARK',
130
+ write: '«',
131
+ label: '«'
132
+ },
133
+ {
134
+ unicode: 'U+005E',
135
+ description: 'CIRCUMFLEX ACCENT',
136
+ write: '^',
137
+ label: '^'
138
+ },
139
+ {
140
+ unicode: 'U+00E2',
141
+ description: 'LATIN SMALL LETTER A WITH CIRCUMFLEX',
142
+ write: 'â',
143
+ label: 'â'
144
+ },
145
+ {
146
+ unicode: 'U+00EA',
147
+ description: 'LATIN SMALL LETTER E WITH CIRCUMFLEX',
148
+ write: 'ê',
149
+ label: 'ê'
150
+ },
151
+ {
152
+ unicode: 'U+00EE',
153
+ description: 'LATIN SMALL LETTER I WITH CIRCUMFLEX',
154
+ write: 'î',
155
+ label: 'î'
156
+ },
157
+ {
158
+ unicode: 'U+00F4',
159
+ description: 'LATIN SMALL LETTER O WITH CIRCUMFLEX',
160
+ write: 'ô',
161
+ label: 'ô'
162
+ },
163
+ {
164
+ unicode: 'U+00FB',
165
+ description: 'LATIN SMALL LETTER U WITH CIRCUMFLEX',
166
+ write: 'û',
167
+ label: 'û'
168
+ },
169
+ {
170
+ unicode: 'U+00E7',
171
+ description: 'LATIN SMALL LETTER C WITH CEDILLA',
172
+ write: 'ç',
173
+ label: 'ç'
174
+ }
175
+ ],
176
+ [
177
+ {
178
+ unicode: 'U+00A5',
179
+ description: 'YEN SIGN',
180
+ write: '¥',
181
+ label: '¥'
182
+ },
183
+ {
184
+ unicode: 'U+00BB',
185
+ description: 'RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK',
186
+ write: '»',
187
+ label: '»'
188
+ },
189
+ {
190
+ unicode: 'U+00C2',
191
+ description: 'LATIN CAPITAL LETTER A WITH CIRCUMFLEX',
192
+ write: 'Â',
193
+ label: 'Â'
194
+ },
195
+ {
196
+ unicode: 'U+00CA',
197
+ description: 'LATIN CAPITAL LETTER E WITH CIRCUMFLEX',
198
+ write: 'Ê',
199
+ label: 'Ê'
200
+ },
201
+ {
202
+ unicode: 'U+00CE',
203
+ description: 'LATIN CAPITAL LETTER I WITH CIRCUMFLEX',
204
+ write: 'Î',
205
+ label: 'Î'
206
+ },
207
+ {
208
+ unicode: 'U+00D4',
209
+ description: 'LATIN CAPITAL LETTER O WITH CIRCUMFLEX',
210
+ write: 'Ô',
211
+ label: 'Ô'
212
+ },
213
+ {
214
+ unicode: 'U+00DB',
215
+ description: 'LATIN CAPITAL LETTER U WITH CIRCUMFLEX',
216
+ write: 'Û',
217
+ label: 'Û'
218
+ },
219
+ {
220
+ unicode: 'U+00C7',
221
+ description: 'LATIN CAPITAL LETTER C WITH CEDILLA',
222
+ write: 'Ç',
223
+ label: 'Ç'
224
+ }
225
+ ],
226
+ [
227
+ {
228
+ unicode: 'U+00A0',
229
+ description: 'NO-BREAK SPACE',
230
+ write: String.fromCodePoint('0x00A0'),
231
+ label: ' '
232
+ },
233
+ {
234
+ unicode: 'U+00A7',
235
+ description: 'SECTION SIGN',
236
+ write: '§',
237
+ label: '§'
238
+ },
239
+ {
240
+ unicode: 'U+00A8',
241
+ description: 'DIAERESIS',
242
+ write: '¨',
243
+ label: '¨'
244
+ },
245
+ {
246
+ unicode: 'U+00E4',
247
+ description: 'LATIN SMALL LETTER A WITH DIAERESIS',
248
+ write: 'ä',
249
+ label: 'ä'
250
+ },
251
+ {
252
+ unicode: 'U+00EB',
253
+ description: 'LATIN SMALL LETTER E WITH DIAERESIS',
254
+ write: 'ë',
255
+ label: 'ë'
256
+ },
257
+ {
258
+ unicode: 'U+00EF',
259
+ description: 'LATIN SMALL LETTER I WITH DIAERESIS',
260
+ write: 'ï',
261
+ label: 'ï'
262
+ },
263
+ {
264
+ unicode: 'U+00F6',
265
+ description: 'LATIN SMALL LETTER O WITH DIAERESIS',
266
+ write: 'ö',
267
+ label: 'ö'
268
+ },
269
+ {
270
+ unicode: 'U+00FC',
271
+ description: 'LATIN SMALL LETTER U WITH DIAERESIS',
272
+ write: 'ü',
273
+ label: 'ü'
274
+ },
275
+ {
276
+ unicode: 'U+00DF',
277
+ description: 'LATIN SMALL LETTER SHARP S',
278
+ write: 'ß',
279
+ label: 'ß'
280
+ }
281
+ ],
282
+ [
283
+ {
284
+ unicode: 'U+2009',
285
+ description: 'THIN SPACE',
286
+ write: String.fromCodePoint('0x2009'),
287
+ label: ' '
288
+ },
289
+ {
290
+ unicode: 'U+2026',
291
+ description: 'HORIZONTAL ELLIPSIS',
292
+ write: '…',
293
+ label: '…'
294
+ },
295
+ {
296
+ unicode: 'U+00C4',
297
+ description: 'LATIN CAPITAL LETTER A WITH DIAERESIS',
298
+ write: 'Ä',
299
+ label: 'Ä'
300
+ },
301
+ {
302
+ unicode: 'U+00CB',
303
+ description: 'LATIN CAPITAL LETTER E WITH DIAERESIS',
304
+ write: 'Ë',
305
+ label: 'Ë'
306
+ },
307
+ {
308
+ unicode: 'U+00CF',
309
+ description: 'LATIN CAPITAL LETTER I WITH DIAERESIS',
310
+ write: 'Ï',
311
+ label: 'Ï'
312
+ },
313
+ {
314
+ unicode: 'U+00D6',
315
+ description: 'LATIN CAPITAL LETTER O WITH DIAERESIS',
316
+ write: 'Ö',
317
+ label: 'Ö'
318
+ },
319
+ {
320
+ unicode: 'U+00DC',
321
+ description: 'LATIN CAPITAL LETTER U WITH DIAERESIS',
322
+ write: 'Ü',
323
+ label: 'Ü'
324
+ },
325
+ {
326
+ unicode: 'U+2212',
327
+ description: 'MINUS SIGN',
328
+ write: '−',
329
+ label: '−'
330
+ }
331
+ ],
332
+ [
333
+ {
334
+ unicode: 'U+200A',
335
+ description: 'HAIR SPACE',
336
+ write: String.fromCodePoint('0x200A'),
337
+ label: ' '
338
+ },
339
+ {
340
+ unicode: 'U+2022',
341
+ description: 'BULLET',
342
+ write: '•',
343
+ label: '•'
344
+ },
345
+ {
346
+ unicode: 'U+0060',
347
+ description: 'GRAVE ACCENT',
348
+ write: '`',
349
+ label: '`'
350
+ },
351
+ {
352
+ unicode: 'U+00E0',
353
+ description: 'LATIN SMALL LETTER A WITH GRAVE',
354
+ write: 'à',
355
+ label: 'à'
356
+ },
357
+ {
358
+ unicode: 'U+00E8',
359
+ description: 'LATIN SMALL LETTER E WITH GRAVE',
360
+ write: 'è',
361
+ label: 'è'
362
+ },
363
+ {
364
+ unicode: 'U+00EC',
365
+ description: 'LATIN SMALL LETTER I WITH GRAVE',
366
+ write: 'ì',
367
+ label: 'ì'
368
+ },
369
+ {
370
+ unicode: 'U+00F2',
371
+ description: 'LATIN SMALL LETTER O WITH GRAVE',
372
+ write: 'ò',
373
+ label: 'ò'
374
+ },
375
+ {
376
+ unicode: 'U+00F9',
377
+ description: 'LATIN SMALL LETTER U WITH GRAVE',
378
+ write: 'ù',
379
+ label: 'ù'
380
+ },
381
+ {
382
+ unicode: 'U+2013',
383
+ description: 'EN DASH',
384
+ write: '–',
385
+ label: '–'
386
+ }
387
+ ],
388
+ [
389
+ {
390
+ unicode: 'U+0009',
391
+ description: 'TAB',
392
+ write: String.fromCodePoint('0x0009'),
393
+ label: 'TAB'
394
+ },
395
+ {
396
+ unicode: 'U+25E6',
397
+ description: 'WHITE BULLET',
398
+ write: '◦',
399
+ label: '◦'
400
+ },
401
+ {
402
+ unicode: 'U+00C0',
403
+ description: 'LATIN CAPITAL LETTER A WITH GRAVE',
404
+ write: 'À',
405
+ label: 'À'
406
+ },
407
+ {
408
+ unicode: 'U+00C8',
409
+ description: 'LATIN CAPITAL LETTER E WITH GRAVE',
410
+ write: 'È',
411
+ label: 'È'
412
+ },
413
+ {
414
+ unicode: 'U+00CC',
415
+ description: 'LATIN CAPITAL LETTER I WITH GRAVE',
416
+ write: 'Ì',
417
+ label: 'Ì'
418
+ },
419
+ {
420
+ unicode: 'U+00D2',
421
+ description: 'LATIN CAPITAL LETTER O WITH GRAVE',
422
+ write: 'Ò',
423
+ label: 'Ò'
424
+ },
425
+ {
426
+ unicode: 'U+00D9',
427
+ description: 'LATIN CAPITAL LETTER U WITH GRAVE',
428
+ write: 'Ù',
429
+ label: 'Ù'
430
+ },
431
+ {
432
+ unicode: 'U+2014',
433
+ description: 'EM DASH',
434
+ write: '—',
435
+ label: '—'
436
+ }
437
+ ]
438
+ ]
439
+ };
440
+
441
+ export const characterIcons = {
442
+ spanish: 'ñ',
443
+ special: '€'
444
+ };
@@ -20,7 +20,9 @@ export class Component extends React.Component {
20
20
  classes: PropTypes.object.isRequired,
21
21
  attributes: PropTypes.object,
22
22
  onFocus: PropTypes.func,
23
- onBlur: PropTypes.func
23
+ onBlur: PropTypes.func,
24
+ maxImageWidth: PropTypes.number,
25
+ maxImageHeight: PropTypes.number,
24
26
  };
25
27
 
26
28
  getWidth = percent => {
@@ -41,30 +43,33 @@ export class Component extends React.Component {
41
43
  applySizeData = () => {
42
44
  const { node, editor } = this.props;
43
45
 
44
- const resizePercent = node.data.get('resizePercent');
45
- log('[applySizeData]: resizePercent: ', resizePercent);
46
-
47
46
  let update = node.data;
48
47
 
49
- if (resizePercent) {
50
- update = update.set('width', this.getWidth(resizePercent));
51
- update = update.set('height', this.getHeight(resizePercent));
52
- } else {
53
- const w = update.get('width');
54
- if (w) {
55
- update = update.set('resizePercent', this.getPercentFromWidth(w));
56
- }
48
+ const w = update.get('width');
49
+ if (w) {
50
+ update = update.set('resizePercent', this.getPercentFromWidth(w));
57
51
  }
58
52
 
59
- log('[applySizeData] update: ', update);
53
+ log("[applySizeData] update: ", update);
60
54
 
61
55
  if (!update.equals(node.data)) {
62
56
  editor.change(c => c.setNodeByKey(node.key, { data: update }));
63
57
  }
64
58
  };
65
59
 
60
+ initialiseResize = () => {
61
+ window.addEventListener('mousemove', this.startResizing, false);
62
+ window.addEventListener('mouseup', this.stopResizing, false);
63
+ };
64
+
66
65
  componentDidMount() {
67
66
  this.applySizeData();
67
+
68
+ const resizeHandle = this.resize;
69
+
70
+ if (resizeHandle) {
71
+ resizeHandle.addEventListener('mousedown', this.initialiseResize, false);
72
+ }
68
73
  }
69
74
 
70
75
  componentDidUpdate() {
@@ -79,6 +84,117 @@ export class Component extends React.Component {
79
84
  };
80
85
  }
81
86
 
87
+ loadImage = () => {
88
+ let { maxImageWidth, maxImageHeight } = this.props || {};
89
+ maxImageWidth = maxImageWidth || 700;
90
+ maxImageHeight = maxImageHeight || 900;
91
+
92
+ const box = this.img;
93
+
94
+ //on first load
95
+ if (!box.style.width || box.style.width === 'auto') {
96
+ const dimensions = { width: box && box.naturalWidth || 100, height: box && box.naturalHeight || 100 };
97
+
98
+ const { width, height } = this.updateImageDimensions(
99
+ dimensions,
100
+ {
101
+ width: dimensions.width < maxImageWidth ? dimensions.width : maxImageWidth,
102
+ height: dimensions.height < maxImageHeight ? dimensions.height : maxImageHeight
103
+ },
104
+ true
105
+ );
106
+
107
+ box.style.width = `${width}px`;
108
+ box.style.height = `${height}px`;
109
+
110
+ this.setState({
111
+ dimensions: { height: height, width: width },
112
+ });
113
+
114
+ const { node, editor } = this.props;
115
+
116
+ let update = node.data;
117
+
118
+ update = update.set('width', width);
119
+ update = update.set('height', height);
120
+
121
+ if (!update.equals(node.data)) {
122
+ editor.change(c => c.setNodeByKey(node.key, { data: update }));
123
+ }
124
+ }
125
+ };
126
+
127
+ startResizing = (e) => {
128
+ const bounds = e.target.getBoundingClientRect();
129
+ const box = this.img;
130
+ const dimensions = { width: box && box.naturalWidth || 100, height: box && box.naturalHeight || 100};
131
+
132
+ const { width, height } = this.updateImageDimensions(
133
+ dimensions,
134
+ {
135
+ width: e.clientX - bounds.left,
136
+ height: e.clientY - bounds.top
137
+ },
138
+ true
139
+ );
140
+
141
+ const hasMinimumWidth = width > 50 && height > 50;
142
+ const hasDimensionsConstraints = width <= 700 && height <= 900;
143
+
144
+ if (hasMinimumWidth && hasDimensionsConstraints && box) {
145
+ box.style.width = `${width}px`;
146
+ box.style.height = `${height}px`;
147
+
148
+ this.setState({
149
+ dimensions: { height: height, width: width }
150
+ });
151
+
152
+ const { node, editor } = this.props;
153
+
154
+ let update = node.data;
155
+
156
+ update = update.set('width', width);
157
+ update = update.set('height', height);
158
+
159
+ if (!update.equals(node.data)) {
160
+ editor.change(c => c.setNodeByKey(node.key, { data: update }));
161
+ }
162
+ }
163
+ };
164
+
165
+ stopResizing = () => {
166
+ window.removeEventListener('mousemove', this.startResizing, false);
167
+ window.removeEventListener('mouseup', this.stopResizing, false);
168
+ };
169
+
170
+ updateImageDimensions = (initialDim, nextDim, keepAspectRatio, resizeType) => {
171
+ // if we want to keep image aspect ratio
172
+ if (keepAspectRatio) {
173
+ const imageAspectRatio = initialDim.width / initialDim.height;
174
+
175
+ if (resizeType === 'height') {
176
+ // if we want to change image height => we update the width accordingly
177
+ return {
178
+ width: nextDim.height * imageAspectRatio,
179
+ height: nextDim.height
180
+ }
181
+ }
182
+
183
+ // if we want to change image width => we update the height accordingly
184
+ return {
185
+ width: nextDim.width,
186
+ height: nextDim.width / imageAspectRatio
187
+ }
188
+ }
189
+
190
+ // if we don't want to keep aspect ratio, we just update both values
191
+ return {
192
+ width: nextDim.width,
193
+ height: nextDim.height
194
+ }
195
+ };
196
+
197
+
82
198
  render() {
83
199
  const { node, editor, classes, attributes, onFocus } = this.props;
84
200
  const active = editor.value.isFocused && editor.value.selection.hasEdgeIn(node);
@@ -95,7 +211,6 @@ export class Component extends React.Component {
95
211
 
96
212
  const className = classNames(
97
213
  classes.root,
98
- active && classes.active,
99
214
  !loaded && classes.loading,
100
215
  deleteStatus === 'pending' && classes.pendingDelete
101
216
  );
@@ -110,7 +225,21 @@ export class Component extends React.Component {
110
225
  value={percent > 0 ? percent : 0}
111
226
  className={progressClasses}
112
227
  />
113
- <img src={src} {...attributes} ref={r => (this.img = r)} style={size} />
228
+ <div className={classes.imageContainer}>
229
+ <img
230
+ {...attributes}
231
+ className={classNames(classes.image, active && classes.active)}
232
+ ref={ref => {
233
+ this.img = ref;
234
+ }}
235
+ src={src}
236
+ style={size}
237
+ onLoad={this.loadImage}
238
+ />
239
+ <div ref={ref => {
240
+ this.resize = ref;
241
+ }} className={classNames(classes.resize, 'resize')}/>
242
+ </div>
114
243
  </div>,
115
244
  <span key={'sp2'}>&nbsp;</span>
116
245
  ];
@@ -154,13 +283,36 @@ const styles = theme => ({
154
283
  display: 'inline-block',
155
284
  transition: 'opacity 200ms linear'
156
285
  },
157
- active: {
158
- border: `solid 1px ${theme.palette.primary.main}`
159
- },
160
286
  delete: {
161
287
  position: 'absolute',
162
288
  right: 0
163
- }
289
+ },
290
+ imageContainer: {
291
+ position: 'relative',
292
+ width: 'fit-content',
293
+ display: 'flex',
294
+ alignItems: 'center',
295
+
296
+ '&&:hover > .resize': {
297
+ display: 'block'
298
+ }
299
+ },
300
+ active: {
301
+ border: `solid 1px ${theme.palette.primary.main}`
302
+ },
303
+ resize: {
304
+ backgroundColor: theme.palette.primary.main,
305
+ cursor: 'col-resize',
306
+ height: '35px',
307
+ width: '5px',
308
+ borderRadius: 8,
309
+ marginLeft: '5px',
310
+ marginRight: '10px',
311
+ display: 'none'
312
+ },
313
+ drawableHeight: {
314
+ minHeight: 350,
315
+ },
164
316
  });
165
317
 
166
318
  export default withStyles(styles)(Component);