@pie-lib/editable-html 9.5.13 → 10.0.0-beta.1

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 (144) hide show
  1. package/CHANGELOG.md +0 -302
  2. package/lib/components.js +116 -0
  3. package/lib/components.js.map +1 -0
  4. package/lib/editor.js +418 -103
  5. package/lib/editor.js.map +1 -1
  6. package/lib/index.js +101 -155
  7. package/lib/index.js.map +1 -1
  8. package/lib/new-serialization.js +320 -0
  9. package/lib/new-serialization.js.map +1 -0
  10. package/lib/old-serialization.js +330 -0
  11. package/lib/parse-html.js +1 -1
  12. package/lib/parse-html.js.map +1 -1
  13. package/lib/plugins/characters/custom-popper.js +1 -1
  14. package/lib/plugins/characters/custom-popper.js.map +1 -1
  15. package/lib/plugins/characters/index.js +21 -19
  16. package/lib/plugins/characters/index.js.map +1 -1
  17. package/lib/plugins/characters/utils.js +1 -1
  18. package/lib/plugins/characters/utils.js.map +1 -1
  19. package/lib/plugins/hotKeys/index.js +67 -0
  20. package/lib/plugins/hotKeys/index.js.map +1 -0
  21. package/lib/plugins/image/alt-dialog.js +1 -6
  22. package/lib/plugins/image/alt-dialog.js.map +1 -1
  23. package/lib/plugins/image/component.js +70 -53
  24. package/lib/plugins/image/component.js.map +1 -1
  25. package/lib/plugins/image/image-toolbar.js +7 -9
  26. package/lib/plugins/image/image-toolbar.js.map +1 -1
  27. package/lib/plugins/image/index.js +83 -27
  28. package/lib/plugins/image/index.js.map +1 -1
  29. package/lib/plugins/image/insert-image-handler.js +72 -33
  30. package/lib/plugins/image/insert-image-handler.js.map +1 -1
  31. package/lib/plugins/index.js +23 -41
  32. package/lib/plugins/index.js.map +1 -1
  33. package/lib/plugins/list/index.js +64 -100
  34. package/lib/plugins/list/index.js.map +1 -1
  35. package/lib/plugins/math/index.js +86 -60
  36. package/lib/plugins/math/index.js.map +1 -1
  37. package/lib/plugins/media/index.js +202 -132
  38. package/lib/plugins/media/index.js.map +1 -1
  39. package/lib/plugins/media/media-dialog.js +17 -16
  40. package/lib/plugins/media/media-dialog.js.map +1 -1
  41. package/lib/plugins/media/media-toolbar.js +3 -3
  42. package/lib/plugins/media/media-toolbar.js.map +1 -1
  43. package/lib/plugins/media/media-wrapper.js +21 -58
  44. package/lib/plugins/media/media-wrapper.js.map +1 -1
  45. package/lib/plugins/respArea/drag-in-the-blank/choice.js +3 -3
  46. package/lib/plugins/respArea/drag-in-the-blank/choice.js.map +1 -1
  47. package/lib/plugins/respArea/drag-in-the-blank/index.js +3 -2
  48. package/lib/plugins/respArea/drag-in-the-blank/index.js.map +1 -1
  49. package/lib/plugins/respArea/explicit-constructed-response/index.js +3 -2
  50. package/lib/plugins/respArea/explicit-constructed-response/index.js.map +1 -1
  51. package/lib/plugins/respArea/icons/index.js +13 -15
  52. package/lib/plugins/respArea/icons/index.js.map +1 -1
  53. package/lib/plugins/respArea/index.js +87 -53
  54. package/lib/plugins/respArea/index.js.map +1 -1
  55. package/lib/plugins/respArea/inline-dropdown/index.js +4 -3
  56. package/lib/plugins/respArea/inline-dropdown/index.js.map +1 -1
  57. package/lib/plugins/respArea/utils.js +17 -20
  58. package/lib/plugins/respArea/utils.js.map +1 -1
  59. package/lib/plugins/table/icons/index.js +1 -1
  60. package/lib/plugins/table/icons/index.js.map +1 -1
  61. package/lib/plugins/table/index.js +381 -212
  62. package/lib/plugins/table/index.js.map +1 -1
  63. package/lib/plugins/table/table-toolbar.js +5 -6
  64. package/lib/plugins/table/table-toolbar.js.map +1 -1
  65. package/lib/plugins/toolbar/default-toolbar.js +55 -11
  66. package/lib/plugins/toolbar/default-toolbar.js.map +1 -1
  67. package/lib/plugins/toolbar/done-button.js +1 -1
  68. package/lib/plugins/toolbar/done-button.js.map +1 -1
  69. package/lib/plugins/toolbar/editor-and-toolbar.js +186 -232
  70. package/lib/plugins/toolbar/editor-and-toolbar.js.map +1 -1
  71. package/lib/plugins/toolbar/index.js +1 -2
  72. package/lib/plugins/toolbar/index.js.map +1 -1
  73. package/lib/plugins/toolbar/toolbar-buttons.js +1 -1
  74. package/lib/plugins/toolbar/toolbar-buttons.js.map +1 -1
  75. package/lib/plugins/toolbar/toolbar.js +253 -239
  76. package/lib/plugins/toolbar/toolbar.js.map +1 -1
  77. package/lib/plugins/utils.js +27 -2
  78. package/lib/plugins/utils.js.map +1 -1
  79. package/lib/serialization.js +1 -1
  80. package/lib/serialization.js.map +1 -1
  81. package/lib/slate-editor.js +302 -0
  82. package/lib/test-serializer.js +189 -0
  83. package/lib/test-serializer.js.map +1 -0
  84. package/lib/theme.js +1 -1
  85. package/lib/theme.js.map +1 -1
  86. package/package.json +18 -14
  87. package/playground/image/data.js +20 -20
  88. package/playground/image/index.html +22 -20
  89. package/playground/image/index.jsx +12 -10
  90. package/playground/index.html +25 -23
  91. package/playground/mathquill/index.html +23 -20
  92. package/playground/mathquill/index.jsx +18 -22
  93. package/playground/prod-test/index.html +24 -20
  94. package/playground/prod-test/index.jsx +5 -3
  95. package/playground/schema-override/data.js +10 -10
  96. package/playground/schema-override/image-plugin.jsx +3 -4
  97. package/playground/schema-override/index.html +21 -19
  98. package/playground/schema-override/index.jsx +13 -14
  99. package/playground/serialization/data.js +10 -10
  100. package/playground/serialization/image-plugin.jsx +3 -4
  101. package/playground/serialization/index.html +22 -20
  102. package/playground/table-examples.html +5 -8
  103. package/playground/webpack.config.js +10 -10
  104. package/src/components.js +135 -0
  105. package/src/editor.jsx +478 -141
  106. package/src/index.jsx +71 -95
  107. package/src/new-serialization.jsx +291 -0
  108. package/src/parse-html.js +1 -1
  109. package/src/plugins/characters/custom-popper.js +7 -7
  110. package/src/plugins/characters/index.jsx +33 -34
  111. package/src/plugins/characters/utils.js +81 -81
  112. package/src/plugins/hotKeys/index.js +54 -0
  113. package/src/plugins/image/alt-dialog.jsx +4 -5
  114. package/src/plugins/image/component.jsx +106 -89
  115. package/src/plugins/image/image-toolbar.jsx +27 -19
  116. package/src/plugins/image/index.jsx +75 -43
  117. package/src/plugins/image/insert-image-handler.js +62 -27
  118. package/src/plugins/index.jsx +23 -41
  119. package/src/plugins/list/index.jsx +70 -95
  120. package/src/plugins/math/index.jsx +102 -82
  121. package/src/plugins/media/index.jsx +159 -124
  122. package/src/plugins/media/media-dialog.js +98 -71
  123. package/src/plugins/media/media-toolbar.jsx +8 -8
  124. package/src/plugins/media/media-wrapper.jsx +29 -30
  125. package/src/plugins/respArea/drag-in-the-blank/choice.jsx +21 -19
  126. package/src/plugins/respArea/drag-in-the-blank/index.jsx +14 -11
  127. package/src/plugins/respArea/explicit-constructed-response/index.jsx +7 -6
  128. package/src/plugins/respArea/icons/index.jsx +11 -14
  129. package/src/plugins/respArea/index.jsx +92 -52
  130. package/src/plugins/respArea/inline-dropdown/index.jsx +9 -8
  131. package/src/plugins/respArea/utils.jsx +26 -35
  132. package/src/plugins/table/icons/index.jsx +17 -11
  133. package/src/plugins/table/index.jsx +288 -231
  134. package/src/plugins/table/table-toolbar.jsx +15 -11
  135. package/src/plugins/toolbar/default-toolbar.jsx +65 -19
  136. package/src/plugins/toolbar/done-button.jsx +4 -4
  137. package/src/plugins/toolbar/editor-and-toolbar.jsx +150 -145
  138. package/src/plugins/toolbar/index.jsx +2 -3
  139. package/src/plugins/toolbar/toolbar-buttons.jsx +11 -11
  140. package/src/plugins/toolbar/toolbar.jsx +244 -221
  141. package/src/plugins/utils.js +21 -4
  142. package/src/serialization.jsx +32 -32
  143. package/src/test-serializer.js +139 -0
  144. package/src/test-serializer.js.rej +20 -0
@@ -8,24 +8,26 @@ import { PureToolbar } from '@pie-lib/math-toolbar';
8
8
  import CustomPopper from './custom-popper';
9
9
  import { insertSnackBar } from '../respArea/utils';
10
10
  import { characterIcons, spanishConfig, specialConfig } from './utils';
11
+ import { ReactEditor } from 'slate-react';
12
+ import { Editor } from 'slate';
11
13
  const log = debug('@pie-lib:editable-html:plugins:characters');
12
14
 
13
15
  const removePopOvers = () => {
14
16
  const prevPopOvers = document.querySelectorAll('#mouse-over-popover');
15
17
 
16
18
  log('[characters:removePopOvers]');
17
- prevPopOvers.forEach((s) => s.remove());
19
+ prevPopOvers.forEach(s => s.remove());
18
20
  };
19
21
 
20
22
  export const removeDialogs = () => {
21
23
  const prevDialogs = document.querySelectorAll('.insert-character-dialog');
22
24
 
23
25
  log('[characters:removeDialogs]');
24
- prevDialogs.forEach((s) => s.remove());
26
+ prevDialogs.forEach(s => s.remove());
25
27
  removePopOvers();
26
28
  };
27
29
 
28
- const insertDialog = ({ editorDOM, value, callback, opts }) => {
30
+ const insertDialog = ({ editor, callback, opts }) => {
29
31
  const newEl = document.createElement('div');
30
32
 
31
33
  log('[characters:insertDialog]');
@@ -60,7 +62,7 @@ const insertDialog = ({ editorDOM, value, callback, opts }) => {
60
62
 
61
63
  return obj;
62
64
  },
63
- { rows: configToUse.characters.length, columns: 0 },
65
+ { rows: configToUse.characters.length, columns: 0 }
64
66
  );
65
67
 
66
68
  let popoverEl;
@@ -91,7 +93,7 @@ const insertDialog = ({ editorDOM, value, callback, opts }) => {
91
93
 
92
94
  <div style={infoStyle}>{el.unicode}</div>
93
95
  </CustomPopper>,
94
- popoverEl,
96
+ popoverEl
95
97
  );
96
98
 
97
99
  document.body.appendChild(newEl);
@@ -99,12 +101,14 @@ const insertDialog = ({ editorDOM, value, callback, opts }) => {
99
101
 
100
102
  let firstCallMade = false;
101
103
 
102
- const listener = (e) => {
104
+ const listener = e => {
103
105
  // this will be triggered right after setting it because
104
106
  // this toolbar is added on the mousedown event
105
107
  // so right after mouseup, the click will be triggered
106
108
  if (firstCallMade) {
107
- const focusIsInModals = newEl.contains(e.target) || (popoverEl && popoverEl.contains(e.target));
109
+ const focusIsInModals =
110
+ newEl.contains(e.target) || (popoverEl && popoverEl.contains(e.target));
111
+ const editorDOM = ReactEditor.toDOMNode(editor, editor);
108
112
  const focusIsInEditor = editorDOM.contains(e.target);
109
113
 
110
114
  if (!(focusIsInModals || focusIsInEditor)) {
@@ -122,7 +126,7 @@ const insertDialog = ({ editorDOM, value, callback, opts }) => {
122
126
  document.body.removeEventListener('click', listener);
123
127
  };
124
128
 
125
- const handleChange = (val) => {
129
+ const handleChange = val => {
126
130
  if (typeof val === 'string') {
127
131
  callback(val, true);
128
132
  }
@@ -138,7 +142,7 @@ const insertDialog = ({ editorDOM, value, callback, opts }) => {
138
142
  additionalKeys={configToUse.characters.reduce((arr, n) => {
139
143
  arr = [
140
144
  ...arr,
141
- ...n.map((k) => ({
145
+ ...n.map(k => ({
142
146
  name: get(k, 'name') || k,
143
147
  write: get(k, 'write') || k,
144
148
  label: get(k, 'label') || k,
@@ -148,15 +152,15 @@ const insertDialog = ({ editorDOM, value, callback, opts }) => {
148
152
  ...(k.extraProps || {}),
149
153
  style: {
150
154
  ...(k.extraProps || {}).style,
151
- border: '1px solid #000',
152
- },
155
+ border: '1px solid #000'
156
+ }
153
157
  },
154
158
  ...(configToUse.hasPreview
155
159
  ? {
156
- actions: { onMouseEnter: (ev) => renderPopOver(ev, k), onMouseLeave: closePopOver },
160
+ actions: { onMouseEnter: ev => renderPopOver(ev, k), onMouseLeave: closePopOver }
157
161
  }
158
- : {}),
159
- })),
162
+ : {})
163
+ }))
160
164
  ];
161
165
 
162
166
  return arr;
@@ -168,7 +172,8 @@ const insertDialog = ({ editorDOM, value, callback, opts }) => {
168
172
  );
169
173
 
170
174
  ReactDOM.render(el, newEl, () => {
171
- const cursorItem = document.querySelector(`[data-key="${value.anchorKey}"]`);
175
+ const [nodeAtSelection] = Editor.node(editor, editor.selection);
176
+ const cursorItem = ReactEditor.toDOMNode(editor, nodeAtSelection);
172
177
 
173
178
  if (cursorItem) {
174
179
  const bodyRect = document.body.getBoundingClientRect();
@@ -179,7 +184,10 @@ const insertDialog = ({ editorDOM, value, callback, opts }) => {
179
184
  newEl.style.top = `${boundRect.top + Math.abs(bodyRect.top) - newEl.offsetHeight - 10}px`;
180
185
  newEl.style.zIndex = 99999;
181
186
 
182
- const leftValue = `${boundRect.left + Math.abs(bodyRect.left) + cursorItem.offsetWidth + 10}px`;
187
+ const leftValue = `${boundRect.left +
188
+ Math.abs(bodyRect.left) +
189
+ cursorItem.offsetWidth +
190
+ 10}px`;
183
191
 
184
192
  const rightValue = `${boundRect.x}px`;
185
193
 
@@ -210,7 +218,7 @@ const CharacterIcon = ({ letter }) => (
210
218
  <div
211
219
  style={{
212
220
  fontSize: '25px',
213
- lineHeight: '15px',
221
+ lineHeight: '15px'
214
222
  }}
215
223
  >
216
224
  {letter}
@@ -223,40 +231,31 @@ export default function CharactersPlugin(opts) {
223
231
  name: 'characters',
224
232
  toolbar: {
225
233
  icon: <CharacterIcon letter={opts.characterIcon || characterIcons[opts.language] || 'ñ'} />,
226
- onClick: (value, onChange, getFocusedValue) => {
227
- const editorDOM = document.querySelector(`[data-key="${value.document.key}"]`);
228
- let valueToUse = value;
234
+ onClick: editor => {
229
235
  const callback = (char, focus) => {
230
- valueToUse = getFocusedValue();
231
-
232
236
  if (char) {
233
- const change = valueToUse.change().insertTextByKey(valueToUse.anchorKey, valueToUse.anchorOffset, char);
234
-
235
- valueToUse = change.value;
236
- log('[characters:insert]: ', value);
237
- onChange(change);
237
+ log('[characters:insert]: ', char);
238
+ editor.insertText(char);
238
239
  }
239
240
 
240
241
  log('[characters:click]');
241
242
 
242
243
  if (focus) {
243
- if (editorDOM) {
244
- editorDOM.focus();
245
- }
244
+ ReactEditor.focus(editor);
246
245
  }
247
246
  };
248
247
 
249
- insertDialog({ editorDOM, value: valueToUse, callback, opts });
250
- },
248
+ insertDialog({ editor, callback, opts });
249
+ }
251
250
  },
252
251
 
253
252
  pluginStyles: (node, parentNode, p) => {
254
253
  if (p) {
255
254
  return {
256
255
  position: 'absolute',
257
- top: 'initial',
256
+ top: 'initial'
258
257
  };
259
258
  }
260
- },
259
+ }
261
260
  };
262
261
  }