@pie-lib/editable-html 9.3.1-next.53 → 9.4.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.
Files changed (75) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/lib/editor.js +244 -114
  3. package/lib/editor.js.map +1 -1
  4. package/lib/index.js +51 -5
  5. package/lib/index.js.map +1 -1
  6. package/lib/parse-html.js +5 -6
  7. package/lib/parse-html.js.map +1 -1
  8. package/lib/plugins/characters/custom-popper.js +12 -2
  9. package/lib/plugins/characters/custom-popper.js.map +1 -1
  10. package/lib/plugins/characters/index.js +50 -3
  11. package/lib/plugins/characters/index.js.map +1 -1
  12. package/lib/plugins/characters/utils.js.map +1 -1
  13. package/lib/plugins/image/alt-dialog.js +26 -0
  14. package/lib/plugins/image/alt-dialog.js.map +1 -1
  15. package/lib/plugins/image/component.js +82 -29
  16. package/lib/plugins/image/component.js.map +1 -1
  17. package/lib/plugins/image/image-toolbar.js +45 -7
  18. package/lib/plugins/image/image-toolbar.js.map +1 -1
  19. package/lib/plugins/image/index.js +41 -2
  20. package/lib/plugins/image/index.js.map +1 -1
  21. package/lib/plugins/image/insert-image-handler.js +22 -2
  22. package/lib/plugins/image/insert-image-handler.js.map +1 -1
  23. package/lib/plugins/index.js +34 -13
  24. package/lib/plugins/index.js.map +1 -1
  25. package/lib/plugins/list/index.js +42 -13
  26. package/lib/plugins/list/index.js.map +1 -1
  27. package/lib/plugins/math/index.js +75 -30
  28. package/lib/plugins/math/index.js.map +1 -1
  29. package/lib/plugins/media/index.js +75 -18
  30. package/lib/plugins/media/index.js.map +1 -1
  31. package/lib/plugins/media/media-dialog.js +188 -100
  32. package/lib/plugins/media/media-dialog.js.map +1 -1
  33. package/lib/plugins/media/media-toolbar.js +24 -4
  34. package/lib/plugins/media/media-toolbar.js.map +1 -1
  35. package/lib/plugins/media/media-wrapper.js +29 -5
  36. package/lib/plugins/media/media-wrapper.js.map +1 -1
  37. package/lib/plugins/respArea/drag-in-the-blank/choice.js +50 -10
  38. package/lib/plugins/respArea/drag-in-the-blank/choice.js.map +1 -1
  39. package/lib/plugins/respArea/drag-in-the-blank/index.js +18 -4
  40. package/lib/plugins/respArea/drag-in-the-blank/index.js.map +1 -1
  41. package/lib/plugins/respArea/explicit-constructed-response/index.js +8 -2
  42. package/lib/plugins/respArea/explicit-constructed-response/index.js.map +1 -1
  43. package/lib/plugins/respArea/icons/index.js +18 -1
  44. package/lib/plugins/respArea/icons/index.js.map +1 -1
  45. package/lib/plugins/respArea/index.js +47 -1
  46. package/lib/plugins/respArea/index.js.map +1 -1
  47. package/lib/plugins/respArea/inline-dropdown/index.js +8 -1
  48. package/lib/plugins/respArea/inline-dropdown/index.js.map +1 -1
  49. package/lib/plugins/respArea/utils.js +22 -0
  50. package/lib/plugins/respArea/utils.js.map +1 -1
  51. package/lib/plugins/table/icons/index.js +7 -0
  52. package/lib/plugins/table/icons/index.js.map +1 -1
  53. package/lib/plugins/table/index.js +94 -15
  54. package/lib/plugins/table/index.js.map +1 -1
  55. package/lib/plugins/table/table-toolbar.js +43 -11
  56. package/lib/plugins/table/table-toolbar.js.map +1 -1
  57. package/lib/plugins/toolbar/default-toolbar.js +30 -8
  58. package/lib/plugins/toolbar/default-toolbar.js.map +1 -1
  59. package/lib/plugins/toolbar/done-button.js +9 -1
  60. package/lib/plugins/toolbar/done-button.js.map +1 -1
  61. package/lib/plugins/toolbar/editor-and-toolbar.js +48 -18
  62. package/lib/plugins/toolbar/editor-and-toolbar.js.map +1 -1
  63. package/lib/plugins/toolbar/index.js +5 -0
  64. package/lib/plugins/toolbar/index.js.map +1 -1
  65. package/lib/plugins/toolbar/toolbar-buttons.js +39 -8
  66. package/lib/plugins/toolbar/toolbar-buttons.js.map +1 -1
  67. package/lib/plugins/toolbar/toolbar.js +67 -19
  68. package/lib/plugins/toolbar/toolbar.js.map +1 -1
  69. package/lib/plugins/utils.js +15 -0
  70. package/lib/plugins/utils.js.map +1 -1
  71. package/lib/serialization.js +69 -8
  72. package/lib/serialization.js.map +1 -1
  73. package/lib/theme.js.map +1 -1
  74. package/package.json +4 -4
  75. package/src/plugins/media/index.jsx +1 -0
package/lib/editor.js CHANGED
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
4
5
  var _typeof = require("@babel/runtime/helpers/typeof");
6
+
5
7
  Object.defineProperty(exports, "__esModule", {
6
8
  value: true
7
9
  });
@@ -18,36 +20,67 @@ Object.defineProperty(exports, "DEFAULT_PLUGINS", {
18
20
  }
19
21
  });
20
22
  exports.serialization = exports["default"] = exports.Editor = void 0;
23
+
21
24
  var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
25
+
22
26
  var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
27
+
23
28
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
29
+
24
30
  var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
31
+
25
32
  var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
33
+
26
34
  var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
35
+
27
36
  var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
37
+
28
38
  var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
39
+
29
40
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
41
+
30
42
  var _slateReact = require("slate-react");
43
+
31
44
  var _slatePropTypes = _interopRequireDefault(require("slate-prop-types"));
45
+
32
46
  var _isEqual = _interopRequireDefault(require("lodash/isEqual"));
47
+
33
48
  var serialization = _interopRequireWildcard(require("./serialization"));
49
+
34
50
  exports.serialization = serialization;
51
+
35
52
  var _propTypes = _interopRequireDefault(require("prop-types"));
53
+
36
54
  var _react = _interopRequireDefault(require("react"));
55
+
37
56
  var _slate = require("slate");
57
+
38
58
  var _plugins = require("./plugins");
59
+
39
60
  var _debug = _interopRequireDefault(require("debug"));
61
+
40
62
  var _styles = require("@material-ui/core/styles");
63
+
41
64
  var _classnames = _interopRequireDefault(require("classnames"));
65
+
42
66
  var _renderUi = require("@pie-lib/render-ui");
67
+
43
68
  var _slatePlainSerializer = _interopRequireDefault(require("slate-plain-serializer"));
69
+
44
70
  var _insertImageHandler = _interopRequireDefault(require("./plugins/image/insert-image-handler"));
71
+
45
72
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
73
+
46
74
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
75
+
47
76
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; }
77
+
48
78
  function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
79
+
49
80
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
81
+
50
82
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
83
+
51
84
  var log = (0, _debug["default"])('editable-html:editor');
52
85
  var defaultToolbarOpts = {
53
86
  position: 'bottom',
@@ -62,20 +95,26 @@ var defaultResponseAreaProps = {
62
95
  onHandleAreaChange: function onHandleAreaChange() {}
63
96
  };
64
97
  var defaultLanguageCharactersProps = [];
98
+
65
99
  var createToolbarOpts = function createToolbarOpts(toolbarOpts, error) {
66
100
  return _objectSpread(_objectSpread(_objectSpread({}, defaultToolbarOpts), toolbarOpts), {}, {
67
101
  error: error
68
102
  });
69
103
  };
104
+
70
105
  var Editor = /*#__PURE__*/function (_React$Component) {
71
106
  (0, _inherits2["default"])(Editor, _React$Component);
107
+
72
108
  var _super = _createSuper(Editor);
109
+
73
110
  function Editor(_props) {
74
111
  var _this;
112
+
75
113
  (0, _classCallCheck2["default"])(this, Editor);
76
114
  _this = _super.call(this, _props);
77
115
  (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "handlePlugins", function (props) {
78
116
  var normalizedResponseAreaProps = _objectSpread(_objectSpread({}, defaultResponseAreaProps), props.responseAreaProps);
117
+
79
118
  _this.plugins = (0, _plugins.buildPlugins)(props.activePlugins, {
80
119
  math: {
81
120
  onClick: _this.onMathClick,
@@ -114,13 +153,17 @@ var Editor = /*#__PURE__*/function (_React$Component) {
114
153
  autoWidth: props.autoWidthToolbar,
115
154
  onDone: function onDone() {
116
155
  var _this$state$value$sta, _this$state$value$sta2;
156
+
117
157
  var nonEmpty = props.nonEmpty;
118
158
  log('[onDone]');
159
+
119
160
  _this.setState({
120
161
  toolbarInFocus: false,
121
162
  focusedNode: null
122
163
  });
164
+
123
165
  _this.editor.blur();
166
+
124
167
  if (nonEmpty && ((_this$state$value$sta = _this.state.value.startText) === null || _this$state$value$sta === void 0 ? void 0 : (_this$state$value$sta2 = _this$state$value$sta.text) === null || _this$state$value$sta2 === void 0 ? void 0 : _this$state$value$sta2.length) === 0) {
125
168
  _this.resetValue(true).then(function () {
126
169
  _this.onEditingDone();
@@ -133,10 +176,12 @@ var Editor = /*#__PURE__*/function (_React$Component) {
133
176
  table: {
134
177
  onFocus: function onFocus() {
135
178
  log('[table:onFocus]...');
179
+
136
180
  _this.onPluginFocus();
137
181
  },
138
182
  onBlur: function onBlur() {
139
183
  log('[table:onBlur]...');
184
+
140
185
  _this.onPluginBlur();
141
186
  }
142
187
  },
@@ -149,10 +194,12 @@ var Editor = /*#__PURE__*/function (_React$Component) {
149
194
  error: normalizedResponseAreaProps.error,
150
195
  onFocus: function onFocus() {
151
196
  log('[table:onFocus]...');
197
+
152
198
  _this.onPluginFocus();
153
199
  },
154
200
  onBlur: function onBlur() {
155
201
  log('[table:onBlur]...');
202
+
156
203
  _this.onPluginBlur();
157
204
  }
158
205
  },
@@ -172,6 +219,7 @@ var Editor = /*#__PURE__*/function (_React$Component) {
172
219
  var target = e && e.relatedTarget;
173
220
  var node = target ? (0, _slateReact.findNode)(target, _this.state.value) : null;
174
221
  log('[onPluginBlur] node: ', node);
222
+
175
223
  _this.setState({
176
224
  focusedNode: node
177
225
  }, function () {
@@ -181,10 +229,12 @@ var Editor = /*#__PURE__*/function (_React$Component) {
181
229
  (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "onPluginFocus", function (e) {
182
230
  log('[onPluginFocus]', e && e.target);
183
231
  var target = e && e.target;
232
+
184
233
  if (target) {
185
234
  var node = (0, _slateReact.findNode)(target, _this.state.value);
186
235
  log('[onPluginFocus] node: ', node);
187
236
  var stashedValue = _this.state.stashedValue || _this.state.value;
237
+
188
238
  _this.setState({
189
239
  focusedNode: node,
190
240
  stashedValue: stashedValue
@@ -194,44 +244,55 @@ var Editor = /*#__PURE__*/function (_React$Component) {
194
244
  focusedNode: null
195
245
  });
196
246
  }
247
+
197
248
  _this.stashValue();
198
249
  });
199
250
  (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "onMathClick", function (node) {
200
251
  _this.editor.change(function (c) {
201
252
  return c.collapseToStartOf(node);
202
253
  });
254
+
203
255
  _this.setState({
204
256
  selectedNode: node
205
257
  });
206
258
  });
207
259
  (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "onEditingDone", function () {
208
260
  log('[onEditingDone]');
261
+
209
262
  _this.setState({
210
263
  stashedValue: null,
211
264
  focusedNode: null
212
265
  });
266
+
213
267
  log('[onEditingDone] value: ', _this.state.value);
268
+
214
269
  _this.props.onChange(_this.state.value, true);
215
270
  });
216
271
  (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "handleBlur", function (resolve) {
217
272
  var nonEmpty = _this.props.nonEmpty;
218
273
  var doneOn = _this.state.toolbarOpts.doneOn;
274
+
219
275
  _this.setState({
220
276
  toolbarInFocus: false,
221
277
  focusedNode: null
222
278
  });
279
+
223
280
  if (_this.editor) {
224
281
  _this.editor.blur();
225
282
  }
283
+
226
284
  if (doneOn === 'blur') {
227
285
  var _this$state$value$sta3, _this$state$value$sta4;
286
+
228
287
  if (nonEmpty && ((_this$state$value$sta3 = _this.state.value.startText) === null || _this$state$value$sta3 === void 0 ? void 0 : (_this$state$value$sta4 = _this$state$value$sta3.text) === null || _this$state$value$sta4 === void 0 ? void 0 : _this$state$value$sta4.length) === 0) {
229
288
  _this.resetValue(true).then(function () {
230
289
  _this.onEditingDone();
290
+
231
291
  resolve();
232
292
  });
233
293
  } else {
234
294
  _this.onEditingDone();
295
+
235
296
  resolve();
236
297
  }
237
298
  }
@@ -246,6 +307,7 @@ var Editor = /*#__PURE__*/function (_React$Component) {
246
307
  preBlurValue: _this.state.value,
247
308
  focusedNode: !node ? null : node
248
309
  }, _this.handleBlur.bind((0, _assertThisInitialized2["default"])(_this), resolve));
310
+
249
311
  _this.props.onBlur(event);
250
312
  });
251
313
  });
@@ -253,14 +315,19 @@ var Editor = /*#__PURE__*/function (_React$Component) {
253
315
  var editorDOM = document.querySelector("[data-key=\"".concat(_this.state.value.document.key, "\"]"));
254
316
  setTimeout(function () {
255
317
  var stateValue = _this.state.value;
318
+
256
319
  if (!_this.wrapperRef) {
257
320
  return;
258
321
  }
322
+
259
323
  var editorElement = !editorDOM || document.activeElement.closest("[class*=\"".concat(editorDOM.className, "\"]"));
260
324
  var toolbarElement = !_this.toolbarRef || document.activeElement.closest("[class*=\"".concat(_this.toolbarRef.className, "\"]"));
325
+
261
326
  var isInCurrentComponent = _this.wrapperRef.contains(editorElement) || _this.wrapperRef.contains(toolbarElement);
327
+
262
328
  if (!isInCurrentComponent) {
263
329
  editorDOM.removeEventListener('blur', _this.handleDomBlur);
330
+
264
331
  if (stateValue.isFocused) {
265
332
  _this.onBlur(e);
266
333
  }
@@ -271,19 +338,21 @@ var Editor = /*#__PURE__*/function (_React$Component) {
271
338
  return new Promise(function (resolve) {
272
339
  var editorDOM = document.querySelector("[data-key=\"".concat(_this.state.value.document.key, "\"]"));
273
340
  log('[onFocus]', document.activeElement);
274
-
275
341
  /**
276
342
  * This is a temporary hack - @see changeData below for some more information.
277
343
  */
344
+
278
345
  if (_this.__TEMPORARY_CHANGE_DATA) {
279
346
  var _this$__TEMPORARY_CHA = _this.__TEMPORARY_CHANGE_DATA,
280
- key = _this$__TEMPORARY_CHA.key,
281
- data = _this$__TEMPORARY_CHA.data;
347
+ key = _this$__TEMPORARY_CHA.key,
348
+ data = _this$__TEMPORARY_CHA.data;
282
349
  var domEl = document.querySelector("[data-key=\"".concat(key, "\"]"));
350
+
283
351
  if (domEl) {
284
352
  var change = _this.state.value.change().setNodeByKey(key, {
285
353
  data: data
286
354
  });
355
+
287
356
  _this.setState({
288
357
  value: change.value
289
358
  }, function () {
@@ -291,24 +360,29 @@ var Editor = /*#__PURE__*/function (_React$Component) {
291
360
  });
292
361
  }
293
362
  }
294
-
295
363
  /**
296
364
  * This is needed just in case the browser decides to make the editor
297
365
  * lose focus without triggering the onBlur event (can happen in a few cases).
298
366
  * This will also trigger onBlur if the user clicks outside of the page when the editor
299
367
  * is focused.
300
368
  */
369
+
370
+
301
371
  if (editorDOM === document.activeElement) {
302
372
  editorDOM.removeEventListener('blur', _this.handleDomBlur);
303
373
  editorDOM.addEventListener('blur', _this.handleDomBlur);
304
374
  }
375
+
305
376
  _this.stashValue();
377
+
306
378
  _this.props.onFocus();
379
+
307
380
  resolve();
308
381
  });
309
382
  });
310
383
  (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "stashValue", function () {
311
384
  log('[stashValue]');
385
+
312
386
  if (!_this.state.stashedValue) {
313
387
  _this.setState({
314
388
  stashedValue: _this.state.value
@@ -317,17 +391,22 @@ var Editor = /*#__PURE__*/function (_React$Component) {
317
391
  });
318
392
  (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "resetValue", function (force) {
319
393
  var _this$state = _this.state,
320
- value = _this$state.value,
321
- focusedNode = _this$state.focusedNode;
394
+ value = _this$state.value,
395
+ focusedNode = _this$state.focusedNode;
396
+
322
397
  var stopReset = _this.plugins.reduce(function (s, p) {
323
398
  return s || p.stopReset && p.stopReset(_this.state.value);
324
399
  }, false);
400
+
325
401
  log('[resetValue]', value.isFocused, focusedNode, 'stopReset: ', stopReset);
402
+
326
403
  if (_this.state.stashedValue && !value.isFocused && !focusedNode && !stopReset || force) {
327
404
  log('[resetValue] resetting...');
328
405
  log('stashed', _this.state.stashedValue.document.toObject());
329
406
  log('current', _this.state.value.document.toObject());
407
+
330
408
  var newValue = _slate.Value.fromJSON(_this.state.stashedValue.toJSON());
409
+
331
410
  log('newValue: ', newValue.document);
332
411
  return new Promise(function (resolve) {
333
412
  setTimeout(function () {
@@ -348,13 +427,16 @@ var Editor = /*#__PURE__*/function (_React$Component) {
348
427
  log('[onChange]');
349
428
  var value = change.value;
350
429
  var charactersLimit = _this.props.charactersLimit;
430
+
351
431
  if (value && value.document && value.document.text && value.document.text.length > charactersLimit) {
352
432
  return;
353
433
  }
434
+
354
435
  _this.setState({
355
436
  value: value
356
437
  }, function () {
357
438
  log('[onChange], call done()');
439
+
358
440
  if (done) {
359
441
  done();
360
442
  }
@@ -364,12 +446,14 @@ var Editor = /*#__PURE__*/function (_React$Component) {
364
446
  if (_this.state.value.isFocused) {
365
447
  return _this.state.value;
366
448
  }
449
+
367
450
  return _this.state.preBlurValue;
368
451
  });
369
452
  (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "valueToSize", function (v) {
370
453
  if (!v) {
371
454
  return;
372
455
  }
456
+
373
457
  if (typeof v === 'string') {
374
458
  if (v.endsWith('%')) {
375
459
  return undefined;
@@ -380,9 +464,11 @@ var Editor = /*#__PURE__*/function (_React$Component) {
380
464
  return isNaN(value) ? value : "".concat(value, "px");
381
465
  }
382
466
  }
467
+
383
468
  if (typeof v === 'number') {
384
469
  return "".concat(v, "px");
385
470
  }
471
+
386
472
  return;
387
473
  });
388
474
  (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "validateNode", function (node) {
@@ -392,13 +478,14 @@ var Editor = /*#__PURE__*/function (_React$Component) {
392
478
  if (last.type !== 'image') return;
393
479
  log('[validateNode] last is image..');
394
480
  var parent = last.getParent(last.key);
481
+
395
482
  var p = _slate.Block.getParent(last.key);
483
+
396
484
  log('[validateNode] parent:', parent, p);
397
485
  return undefined;
398
486
  });
399
487
  (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "changeData", function (key, data) {
400
488
  log('[changeData]. .. ', key, data);
401
-
402
489
  /**
403
490
  * HACK ALERT: We should be calling setState here and storing the change data:
404
491
  *
@@ -408,7 +495,6 @@ var Editor = /*#__PURE__*/function (_React$Component) {
408
495
  * brings it's own problems. A major clean up is planned for this component so I've decided to temporarily settle
409
496
  * on this hack rather than spend more time on this.
410
497
  */
411
-
412
498
  // Uncomment this line to see the bug described above.
413
499
  // this.setState({changeData: {key, data}})
414
500
 
@@ -419,106 +505,135 @@ var Editor = /*#__PURE__*/function (_React$Component) {
419
505
  });
420
506
  (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "focus", function (pos, node) {
421
507
  var position = pos || 'end';
508
+
422
509
  _this.props.focus(position, node);
423
510
  });
424
511
  (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "onDropPaste", /*#__PURE__*/function () {
425
512
  var _ref = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(event, change, dropContext) {
426
513
  var editor, transfer, file, type, fragment, text, src, inline, range, ch, handler, _change$value, _document, selection, startBlock, defaultBlock, defaultMarks, frag;
514
+
427
515
  return _regenerator["default"].wrap(function _callee$(_context) {
428
- while (1) switch (_context.prev = _context.next) {
429
- case 0:
430
- editor = change.editor;
431
- transfer = (0, _slateReact.getEventTransfer)(event);
432
- file = transfer.files && transfer.files[0];
433
- type = transfer.type;
434
- fragment = transfer.fragment;
435
- text = transfer.text;
436
- if (!(file && (file.type === 'image/jpeg' || file.type === 'image/jpg' || file.type === 'image/png'))) {
437
- _context.next = 27;
438
- break;
439
- }
440
- if (_this.props.imageSupport) {
441
- _context.next = 9;
442
- break;
443
- }
444
- return _context.abrupt("return");
445
- case 9:
446
- _context.prev = 9;
447
- log('[onDropPaste]');
448
- _context.next = 13;
449
- return (0, serialization.getBase64)(file);
450
- case 13:
451
- src = _context.sent;
452
- inline = _slate.Inline.create({
453
- type: 'image',
454
- isVoid: true,
455
- data: {
456
- loading: false,
457
- src: src
516
+ while (1) {
517
+ switch (_context.prev = _context.next) {
518
+ case 0:
519
+ editor = change.editor;
520
+ transfer = (0, _slateReact.getEventTransfer)(event);
521
+ file = transfer.files && transfer.files[0];
522
+ type = transfer.type;
523
+ fragment = transfer.fragment;
524
+ text = transfer.text;
525
+
526
+ if (!(file && (file.type === 'image/jpeg' || file.type === 'image/jpg' || file.type === 'image/png'))) {
527
+ _context.next = 27;
528
+ break;
458
529
  }
459
- });
460
- if (dropContext) {
461
- _this.focus();
462
- } else {
463
- range = (0, _slateReact.getEventRange)(event, editor);
464
- if (range) {
465
- change.select(range);
530
+
531
+ if (_this.props.imageSupport) {
532
+ _context.next = 9;
533
+ break;
466
534
  }
467
- }
468
- ch = change.insertInline(inline);
469
- _this.onChange(ch);
470
- handler = new _insertImageHandler["default"](inline, function () {
471
- return _this.state.value;
472
- }, _this.onChange, true);
473
- _this.props.imageSupport.add(handler);
474
- _context.next = 25;
475
- break;
476
- case 22:
477
- _context.prev = 22;
478
- _context.t0 = _context["catch"](9);
479
- log('[onDropPaste] error: ', _context.t0);
480
- case 25:
481
- _context.next = 41;
482
- break;
483
- case 27:
484
- if (!(type === 'fragment')) {
485
- _context.next = 31;
535
+
536
+ return _context.abrupt("return");
537
+
538
+ case 9:
539
+ _context.prev = 9;
540
+ log('[onDropPaste]');
541
+ _context.next = 13;
542
+ return (0, serialization.getBase64)(file);
543
+
544
+ case 13:
545
+ src = _context.sent;
546
+ inline = _slate.Inline.create({
547
+ type: 'image',
548
+ isVoid: true,
549
+ data: {
550
+ loading: false,
551
+ src: src
552
+ }
553
+ });
554
+
555
+ if (dropContext) {
556
+ _this.focus();
557
+ } else {
558
+ range = (0, _slateReact.getEventRange)(event, editor);
559
+
560
+ if (range) {
561
+ change.select(range);
562
+ }
563
+ }
564
+
565
+ ch = change.insertInline(inline);
566
+
567
+ _this.onChange(ch);
568
+
569
+ handler = new _insertImageHandler["default"](inline, function () {
570
+ return _this.state.value;
571
+ }, _this.onChange, true);
572
+
573
+ _this.props.imageSupport.add(handler);
574
+
575
+ _context.next = 25;
486
576
  break;
487
- }
488
- change.insertFragment(fragment);
489
- _context.next = 41;
490
- break;
491
- case 31:
492
- if (!(type === 'text' || type === 'html')) {
577
+
578
+ case 22:
579
+ _context.prev = 22;
580
+ _context.t0 = _context["catch"](9);
581
+ log('[onDropPaste] error: ', _context.t0);
582
+
583
+ case 25:
493
584
  _context.next = 41;
494
585
  break;
495
- }
496
- if (text) {
497
- _context.next = 34;
498
- break;
499
- }
500
- return _context.abrupt("return");
501
- case 34:
502
- _change$value = change.value, _document = _change$value.document, selection = _change$value.selection, startBlock = _change$value.startBlock;
503
- if (!startBlock.isVoid) {
504
- _context.next = 37;
586
+
587
+ case 27:
588
+ if (!(type === 'fragment')) {
589
+ _context.next = 31;
590
+ break;
591
+ }
592
+
593
+ change.insertFragment(fragment);
594
+ _context.next = 41;
505
595
  break;
506
- }
507
- return _context.abrupt("return");
508
- case 37:
509
- defaultBlock = startBlock;
510
- defaultMarks = _document.getInsertMarksAtRange(selection);
511
- frag = _slatePlainSerializer["default"].deserialize(text, {
512
- defaultBlock: defaultBlock,
513
- defaultMarks: defaultMarks
514
- }).document;
515
- change.insertFragment(frag);
516
- case 41:
517
- case "end":
518
- return _context.stop();
596
+
597
+ case 31:
598
+ if (!(type === 'text' || type === 'html')) {
599
+ _context.next = 41;
600
+ break;
601
+ }
602
+
603
+ if (text) {
604
+ _context.next = 34;
605
+ break;
606
+ }
607
+
608
+ return _context.abrupt("return");
609
+
610
+ case 34:
611
+ _change$value = change.value, _document = _change$value.document, selection = _change$value.selection, startBlock = _change$value.startBlock;
612
+
613
+ if (!startBlock.isVoid) {
614
+ _context.next = 37;
615
+ break;
616
+ }
617
+
618
+ return _context.abrupt("return");
619
+
620
+ case 37:
621
+ defaultBlock = startBlock;
622
+ defaultMarks = _document.getInsertMarksAtRange(selection);
623
+ frag = _slatePlainSerializer["default"].deserialize(text, {
624
+ defaultBlock: defaultBlock,
625
+ defaultMarks: defaultMarks
626
+ }).document;
627
+ change.insertFragment(frag);
628
+
629
+ case 41:
630
+ case "end":
631
+ return _context.stop();
632
+ }
519
633
  }
520
634
  }, _callee, null, [[9, 22]]);
521
635
  }));
636
+
522
637
  return function (_x, _x2, _x3) {
523
638
  return _ref.apply(this, arguments);
524
639
  };
@@ -526,9 +641,11 @@ var Editor = /*#__PURE__*/function (_React$Component) {
526
641
  (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "renderPlaceholder", function (props) {
527
642
  var editor = props.editor;
528
643
  var document = editor.value.document;
644
+
529
645
  if (!editor.props.placeholder || document.text !== '' || document.nodes.size !== 1) {
530
646
  return false;
531
647
  }
648
+
532
649
  return /*#__PURE__*/_react["default"].createElement("span", {
533
650
  contentEditable: false,
534
651
  style: {
@@ -547,24 +664,32 @@ var Editor = /*#__PURE__*/function (_React$Component) {
547
664
  value: _props.value,
548
665
  toolbarOpts: createToolbarOpts(_props.toolbarOpts, _props.error)
549
666
  };
667
+
550
668
  _this.onResize = function () {
551
669
  _props.onChange(_this.state.value, true);
552
670
  };
671
+
553
672
  _this.handlePlugins(_this.props);
673
+
554
674
  return _this;
555
675
  }
676
+
556
677
  (0, _createClass2["default"])(Editor, [{
557
678
  key: "componentDidMount",
558
679
  value: function componentDidMount() {
559
680
  var _this2 = this;
681
+
560
682
  // onRef is needed to get the ref of the component because we export it using withStyles
561
683
  this.props.onRef(this);
562
684
  window.addEventListener('resize', this.onResize);
685
+
563
686
  if (this.editor && this.props.autoFocus) {
564
687
  Promise.resolve().then(function () {
565
688
  if (_this2.editor) {
566
689
  var editorDOM = document.querySelector("[data-key=\"".concat(_this2.editor.value.document.key, "\"]"));
690
+
567
691
  _this2.editor.focus();
692
+
568
693
  if (editorDOM) {
569
694
  editorDOM.focus();
570
695
  }
@@ -577,11 +702,13 @@ var Editor = /*#__PURE__*/function (_React$Component) {
577
702
  value: function componentWillReceiveProps(nextProps) {
578
703
  var toolbarOpts = this.state.toolbarOpts;
579
704
  var newToolbarOpts = createToolbarOpts(nextProps.toolbarOpts, nextProps.error);
705
+
580
706
  if (!(0, _isEqual["default"])(newToolbarOpts, toolbarOpts)) {
581
707
  this.setState({
582
708
  toolbarOpts: newToolbarOpts
583
709
  });
584
710
  }
711
+
585
712
  if (!(0, _isEqual["default"])(nextProps.languageCharactersProps, this.props.languageCharactersProps)) {
586
713
  this.handlePlugins(nextProps);
587
714
  }
@@ -605,9 +732,8 @@ var Editor = /*#__PURE__*/function (_React$Component) {
605
732
  */
606
733
  function componentWillUnmount() {
607
734
  window.removeEventListener('resize', this.onResize);
608
- }
735
+ } // Allowing time for onChange to take effect if it is called
609
736
 
610
- // Allowing time for onChange to take effect if it is called
611
737
  }, {
612
738
  key: "UNSAFE_componentWillReceiveProps",
613
739
  value: function UNSAFE_componentWillReceiveProps(props) {
@@ -622,10 +748,10 @@ var Editor = /*#__PURE__*/function (_React$Component) {
622
748
  key: "buildSizeStyle",
623
749
  value: function buildSizeStyle() {
624
750
  var _this$props = this.props,
625
- width = _this$props.width,
626
- minHeight = _this$props.minHeight,
627
- height = _this$props.height,
628
- maxHeight = _this$props.maxHeight;
751
+ width = _this$props.width,
752
+ minHeight = _this$props.minHeight,
753
+ height = _this$props.height,
754
+ maxHeight = _this$props.maxHeight;
629
755
  return {
630
756
  width: this.valueToSize(width),
631
757
  height: this.valueToSize(height),
@@ -637,20 +763,21 @@ var Editor = /*#__PURE__*/function (_React$Component) {
637
763
  key: "render",
638
764
  value: function render() {
639
765
  var _classNames,
640
- _this3 = this;
766
+ _this3 = this;
767
+
641
768
  var _this$props2 = this.props,
642
- disabled = _this$props2.disabled,
643
- spellCheck = _this$props2.spellCheck,
644
- highlightShape = _this$props2.highlightShape,
645
- classes = _this$props2.classes,
646
- className = _this$props2.className,
647
- placeholder = _this$props2.placeholder,
648
- pluginProps = _this$props2.pluginProps,
649
- onKeyDown = _this$props2.onKeyDown;
769
+ disabled = _this$props2.disabled,
770
+ spellCheck = _this$props2.spellCheck,
771
+ highlightShape = _this$props2.highlightShape,
772
+ classes = _this$props2.classes,
773
+ className = _this$props2.className,
774
+ placeholder = _this$props2.placeholder,
775
+ pluginProps = _this$props2.pluginProps,
776
+ onKeyDown = _this$props2.onKeyDown;
650
777
  var _this$state2 = this.state,
651
- value = _this$state2.value,
652
- focusedNode = _this$state2.focusedNode,
653
- toolbarOpts = _this$state2.toolbarOpts;
778
+ value = _this$state2.value,
779
+ focusedNode = _this$state2.focusedNode,
780
+ toolbarOpts = _this$state2.toolbarOpts;
654
781
  log('[render] value: ', value);
655
782
  var sizeStyle = this.buildSizeStyle();
656
783
  var names = (0, _classnames["default"])((_classNames = {}, (0, _defineProperty2["default"])(_classNames, classes.withBg, highlightShape), (0, _defineProperty2["default"])(_classNames, classes.toolbarOnTop, toolbarOpts.alwaysVisible && toolbarOpts.position === 'top'), _classNames), className);
@@ -712,6 +839,8 @@ var Editor = /*#__PURE__*/function (_React$Component) {
712
839
  }]);
713
840
  return Editor;
714
841
  }(_react["default"].Component); // TODO color - hardcoded gray background and keypad colors will need to change too
842
+
843
+
715
844
  exports.Editor = Editor;
716
845
  (0, _defineProperty2["default"])(Editor, "propTypes", {
717
846
  autoFocus: _propTypes["default"].bool,
@@ -795,13 +924,12 @@ var styles = {
795
924
  backgroundColor: _renderUi.color.background()
796
925
  },
797
926
  '& table:not([border="1"]) tr': {
798
- borderTop: '1px solid #dfe2e5'
799
- // TODO perhaps secondary color for background, for now disable
927
+ borderTop: '1px solid #dfe2e5' // TODO perhaps secondary color for background, for now disable
800
928
  // '&:nth-child(2n)': {
801
929
  // backgroundColor: '#f6f8fa'
802
930
  // }
803
- },
804
931
 
932
+ },
805
933
  '& td, th': {
806
934
  padding: '.6em 1em',
807
935
  textAlign: 'center'
@@ -817,6 +945,8 @@ var styles = {
817
945
  padding: '0 !important'
818
946
  }
819
947
  };
948
+
820
949
  var _default = (0, _styles.withStyles)(styles)(Editor);
950
+
821
951
  exports["default"] = _default;
822
952
  //# sourceMappingURL=editor.js.map