@pie-lib/editable-html 7.17.4-next.53 → 7.17.4-next.549

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 (98) hide show
  1. package/CHANGELOG.json +150 -0
  2. package/CHANGELOG.md +421 -0
  3. package/lib/editor.js +385 -172
  4. package/lib/editor.js.map +1 -1
  5. package/lib/index.js +66 -53
  6. package/lib/index.js.map +1 -1
  7. package/lib/parse-html.js.map +1 -1
  8. package/lib/plugins/characters/custom-popper.js +73 -0
  9. package/lib/plugins/characters/custom-popper.js.map +1 -0
  10. package/lib/plugins/characters/index.js +285 -0
  11. package/lib/plugins/characters/index.js.map +1 -0
  12. package/lib/plugins/characters/utils.js +381 -0
  13. package/lib/plugins/characters/utils.js.map +1 -0
  14. package/lib/plugins/image/alt-dialog.js +119 -0
  15. package/lib/plugins/image/alt-dialog.js.map +1 -0
  16. package/lib/plugins/image/component.js +253 -77
  17. package/lib/plugins/image/component.js.map +1 -1
  18. package/lib/plugins/image/image-toolbar.js +95 -61
  19. package/lib/plugins/image/image-toolbar.js.map +1 -1
  20. package/lib/plugins/image/index.js +62 -20
  21. package/lib/plugins/image/index.js.map +1 -1
  22. package/lib/plugins/image/insert-image-handler.js +9 -15
  23. package/lib/plugins/image/insert-image-handler.js.map +1 -1
  24. package/lib/plugins/index.js +20 -12
  25. package/lib/plugins/index.js.map +1 -1
  26. package/lib/plugins/list/index.js +82 -14
  27. package/lib/plugins/list/index.js.map +1 -1
  28. package/lib/plugins/math/index.js +50 -55
  29. package/lib/plugins/math/index.js.map +1 -1
  30. package/lib/plugins/media/index.js +26 -25
  31. package/lib/plugins/media/index.js.map +1 -1
  32. package/lib/plugins/media/media-dialog.js +45 -56
  33. package/lib/plugins/media/media-dialog.js.map +1 -1
  34. package/lib/plugins/media/media-toolbar.js +24 -30
  35. package/lib/plugins/media/media-toolbar.js.map +1 -1
  36. package/lib/plugins/media/media-wrapper.js +28 -35
  37. package/lib/plugins/media/media-wrapper.js.map +1 -1
  38. package/lib/plugins/respArea/drag-in-the-blank/choice.js +68 -46
  39. package/lib/plugins/respArea/drag-in-the-blank/choice.js.map +1 -1
  40. package/lib/plugins/respArea/drag-in-the-blank/index.js +12 -12
  41. package/lib/plugins/respArea/drag-in-the-blank/index.js.map +1 -1
  42. package/lib/plugins/respArea/explicit-constructed-response/index.js +10 -9
  43. package/lib/plugins/respArea/explicit-constructed-response/index.js.map +1 -1
  44. package/lib/plugins/respArea/icons/index.js +11 -11
  45. package/lib/plugins/respArea/icons/index.js.map +1 -1
  46. package/lib/plugins/respArea/index.js +58 -42
  47. package/lib/plugins/respArea/index.js.map +1 -1
  48. package/lib/plugins/respArea/inline-dropdown/index.js +8 -8
  49. package/lib/plugins/respArea/inline-dropdown/index.js.map +1 -1
  50. package/lib/plugins/respArea/utils.js +5 -5
  51. package/lib/plugins/respArea/utils.js.map +1 -1
  52. package/lib/plugins/table/icons/index.js +12 -12
  53. package/lib/plugins/table/icons/index.js.map +1 -1
  54. package/lib/plugins/table/index.js +83 -27
  55. package/lib/plugins/table/index.js.map +1 -1
  56. package/lib/plugins/table/table-toolbar.js +41 -50
  57. package/lib/plugins/table/table-toolbar.js.map +1 -1
  58. package/lib/plugins/toolbar/default-toolbar.js +19 -13
  59. package/lib/plugins/toolbar/default-toolbar.js.map +1 -1
  60. package/lib/plugins/toolbar/done-button.js +5 -5
  61. package/lib/plugins/toolbar/done-button.js.map +1 -1
  62. package/lib/plugins/toolbar/editor-and-toolbar.js +51 -44
  63. package/lib/plugins/toolbar/editor-and-toolbar.js.map +1 -1
  64. package/lib/plugins/toolbar/index.js +5 -5
  65. package/lib/plugins/toolbar/index.js.map +1 -1
  66. package/lib/plugins/toolbar/toolbar-buttons.js +49 -52
  67. package/lib/plugins/toolbar/toolbar-buttons.js.map +1 -1
  68. package/lib/plugins/toolbar/toolbar.js +64 -62
  69. package/lib/plugins/toolbar/toolbar.js.map +1 -1
  70. package/lib/plugins/utils.js +1 -1
  71. package/lib/plugins/utils.js.map +1 -1
  72. package/lib/serialization.js +32 -9
  73. package/lib/serialization.js.map +1 -1
  74. package/lib/theme.js.map +1 -1
  75. package/package.json +7 -6
  76. package/src/editor.jsx +218 -25
  77. package/src/index.jsx +22 -5
  78. package/src/plugins/characters/custom-popper.js +48 -0
  79. package/src/plugins/characters/index.jsx +268 -0
  80. package/src/plugins/characters/utils.js +447 -0
  81. package/src/plugins/image/alt-dialog.jsx +69 -0
  82. package/src/plugins/image/component.jsx +204 -21
  83. package/src/plugins/image/image-toolbar.jsx +68 -22
  84. package/src/plugins/image/index.jsx +47 -9
  85. package/src/plugins/index.jsx +4 -1
  86. package/src/plugins/list/index.jsx +67 -5
  87. package/src/plugins/math/index.jsx +31 -37
  88. package/src/plugins/media/index.jsx +3 -0
  89. package/src/plugins/media/media-dialog.js +1 -1
  90. package/src/plugins/respArea/drag-in-the-blank/choice.jsx +28 -1
  91. package/src/plugins/respArea/explicit-constructed-response/index.jsx +3 -3
  92. package/src/plugins/respArea/index.jsx +50 -31
  93. package/src/plugins/table/index.jsx +63 -14
  94. package/src/plugins/toolbar/default-toolbar.jsx +20 -2
  95. package/src/plugins/toolbar/editor-and-toolbar.jsx +35 -4
  96. package/src/plugins/toolbar/toolbar-buttons.jsx +13 -2
  97. package/src/plugins/toolbar/toolbar.jsx +18 -3
  98. package/src/serialization.jsx +19 -3
@@ -17,6 +17,7 @@ export class EditorAndToolbar extends React.Component {
17
17
  value: SlatePropTypes.value.isRequired,
18
18
  plugins: PropTypes.array.isRequired,
19
19
  onChange: PropTypes.func.isRequired,
20
+ getFocusedValue: PropTypes.func.isRequired,
20
21
  onDone: PropTypes.func.isRequired,
21
22
  onDataChange: PropTypes.func,
22
23
  toolbarRef: PropTypes.func,
@@ -28,7 +29,8 @@ export class EditorAndToolbar extends React.Component {
28
29
  pluginProps: PropTypes.object,
29
30
  toolbarOpts: PropTypes.shape({
30
31
  position: PropTypes.oneOf(['bottom', 'top']),
31
- alwaysVisible: PropTypes.bool
32
+ alwaysVisible: PropTypes.bool,
33
+ error: PropTypes.string
32
34
  })
33
35
  };
34
36
 
@@ -48,6 +50,7 @@ export class EditorAndToolbar extends React.Component {
48
50
  value,
49
51
  plugins,
50
52
  onChange,
53
+ getFocusedValue,
51
54
  onDone,
52
55
  focusedNode,
53
56
  autoWidth,
@@ -84,9 +87,26 @@ export class EditorAndToolbar extends React.Component {
84
87
  );
85
88
 
86
89
  return (
87
- <div className={classes.root}>
90
+ <div
91
+ className={classNames(
92
+ {
93
+ [classes.noBorder]: toolbarOpts && toolbarOpts.noBorder,
94
+ [classes.error]: toolbarOpts && toolbarOpts.error
95
+ },
96
+ classes.root
97
+ )}
98
+ >
88
99
  <div className={holderNames}>
89
- <div className={classes.children}>{clonedChildren}</div>
100
+ <div
101
+ className={classNames(
102
+ {
103
+ [classes.noPadding]: toolbarOpts && toolbarOpts.noBorder
104
+ },
105
+ classes.children
106
+ )}
107
+ >
108
+ {clonedChildren}
109
+ </div>
90
110
  </div>
91
111
  <Toolbar
92
112
  autoWidth={autoWidth}
@@ -95,6 +115,7 @@ export class EditorAndToolbar extends React.Component {
95
115
  value={value}
96
116
  isFocused={inFocus}
97
117
  onChange={onChange}
118
+ getFocusedValue={getFocusedValue}
98
119
  onDone={onDone}
99
120
  onDataChange={onDataChange}
100
121
  toolbarRef={toolbarRef}
@@ -117,7 +138,8 @@ const style = {
117
138
  wordBreak: 'break-word',
118
139
  overflow: 'visible',
119
140
  maxHeight: '500px',
120
- padding: '5px 0'
141
+ // needed in order to be able to put the focus before a void element when it is the first one in the editor
142
+ padding: '5px'
121
143
  }
122
144
  },
123
145
  children: {
@@ -214,6 +236,15 @@ const style = {
214
236
  backgroundColor: primary
215
237
  }
216
238
  }
239
+ },
240
+ error: {
241
+ border: '2px solid red'
242
+ },
243
+ noBorder: {
244
+ border: 'none'
245
+ },
246
+ noPadding: {
247
+ padding: 0
217
248
  }
218
249
  };
219
250
 
@@ -15,6 +15,13 @@ const styles = () => ({
15
15
  },
16
16
  active: {
17
17
  color: 'black'
18
+ },
19
+ disabled: {
20
+ opacity: 0.7,
21
+ cursor: 'not-allowed',
22
+ '& :hover': {
23
+ color: 'grey'
24
+ }
18
25
  }
19
26
  });
20
27
 
@@ -26,6 +33,7 @@ export class RawButton extends React.Component {
26
33
  classes: PropTypes.object.isRequired,
27
34
  children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]).isRequired,
28
35
  active: PropTypes.bool,
36
+ disabled: PropTypes.bool,
29
37
  extraStyles: PropTypes.object
30
38
  };
31
39
 
@@ -41,8 +49,11 @@ export class RawButton extends React.Component {
41
49
  };
42
50
 
43
51
  render() {
44
- const { active, classes, children, extraStyles } = this.props;
45
- const names = classNames(classes.button, active && classes.active);
52
+ const { active, classes, children, disabled, extraStyles } = this.props;
53
+ const names = classNames(classes.button, {
54
+ [classes.active]: active,
55
+ [classes.disabled]: disabled
56
+ });
46
57
 
47
58
  return (
48
59
  <div style={extraStyles} className={names} onMouseDown={this.onClick}>
@@ -1,16 +1,19 @@
1
- import { DoneButton } from './done-button';
1
+ import React from 'react';
2
+ import { Change } from 'slate';
2
3
  import Delete from '@material-ui/icons/Delete';
3
4
  import IconButton from '@material-ui/core/IconButton';
4
5
  import PropTypes from 'prop-types';
5
- import React from 'react';
6
6
  import classNames from 'classnames';
7
7
  import debug from 'debug';
8
8
  import SlatePropTypes from 'slate-prop-types';
9
9
  import debounce from 'lodash/debounce';
10
10
 
11
+ import { DoneButton } from './done-button';
12
+
11
13
  import { findSingleNode, findParentNode } from '../utils';
12
14
  import { withStyles } from '@material-ui/core/styles';
13
15
  import DefaultToolbar from './default-toolbar';
16
+ import { removeDialogs as removeCharacterDialogs } from '../characters';
14
17
 
15
18
  const log = debug('@pie-lib:editable-html:plugins:toolbar');
16
19
 
@@ -48,12 +51,13 @@ export class Toolbar extends React.Component {
48
51
  isFocused: PropTypes.bool,
49
52
  autoWidth: PropTypes.bool,
50
53
  onChange: PropTypes.func.isRequired,
54
+ getFocusedValue: PropTypes.func.isRequired,
51
55
  pluginProps: PropTypes.object,
52
56
  toolbarOpts: PropTypes.shape({
53
57
  position: PropTypes.oneOf(['bottom', 'top']),
54
58
  alignment: PropTypes.oneOf(['left', 'right']),
55
59
  alwaysVisible: PropTypes.bool,
56
- ref: PropTypes.obj,
60
+ ref: PropTypes.func,
57
61
  showDone: PropTypes.bool
58
62
  }),
59
63
  onDataChange: PropTypes.func
@@ -66,6 +70,10 @@ export class Toolbar extends React.Component {
66
70
  };
67
71
  }
68
72
 
73
+ componentWillUnmount() {
74
+ removeCharacterDialogs();
75
+ }
76
+
69
77
  hasMark = type => {
70
78
  const { value } = this.props;
71
79
  return value.marks.some(mark => mark.type == type);
@@ -134,6 +142,7 @@ export class Toolbar extends React.Component {
134
142
  value,
135
143
  autoWidth,
136
144
  onChange,
145
+ getFocusedValue,
137
146
  isFocused,
138
147
  onDone,
139
148
  toolbarRef
@@ -167,6 +176,11 @@ export class Toolbar extends React.Component {
167
176
  log('[render] plugin: ', plugin);
168
177
 
169
178
  const handleDone = (change, done) => {
179
+ // use handler only if this is an actual Slate Change
180
+ if (!(change instanceof Change)) {
181
+ return;
182
+ }
183
+
170
184
  let handler = onDone;
171
185
 
172
186
  if (plugin && plugin.toolbar && plugin.toolbar.customToolbar) {
@@ -241,6 +255,7 @@ export class Toolbar extends React.Component {
241
255
  pluginProps={pluginProps}
242
256
  value={value}
243
257
  onChange={onChange}
258
+ getFocusedValue={getFocusedValue}
244
259
  showDone={defaultToolbarShowDone}
245
260
  onDone={handleDone}
246
261
  deletable={deletable}
@@ -58,7 +58,16 @@ export const parseStyleString = s => {
58
58
  return result;
59
59
  };
60
60
 
61
- export const reactAttributes = o => toStyleObject(o, { camelize: true });
61
+ export const getBase64 = file => {
62
+ return new Promise((resolve, reject) => {
63
+ const reader = new FileReader();
64
+ reader.readAsDataURL(file);
65
+ reader.onload = () => resolve(reader.result);
66
+ reader.onerror = error => reject(error);
67
+ });
68
+ };
69
+
70
+ export const reactAttributes = o => toStyleObject(o, { camelize: true, addUnits: false });
62
71
 
63
72
  const attributesToMap = el => (acc, attribute) => {
64
73
  const value = el.getAttribute(attribute);
@@ -340,7 +349,7 @@ serializer.deserialize = function deserialize(html) {
340
349
 
341
350
  let i;
342
351
 
343
- for (i = 0; i < 1000; i++) {
352
+ for (i = 0; i < 3000; i++) {
344
353
  json.schema.rules.push({
345
354
  match: { object: 'document' },
346
355
  nodes: [{ match: { object: 'block' } }]
@@ -356,7 +365,14 @@ serializer.deserialize = function deserialize(html) {
356
365
  return null;
357
366
  };
358
367
 
359
- export const htmlToValue = html => serializer.deserialize(html);
368
+ export const htmlToValue = html => {
369
+ try {
370
+ return serializer.deserialize(html);
371
+ } catch (e) {
372
+ console.log("Couldn't parse html: ", e);
373
+ return {};
374
+ }
375
+ };
360
376
 
361
377
  export const valueToHtml = value => serializer.serialize(value);
362
378