@pie-lib/editable-html 7.17.4-next.45 → 7.17.4-next.454

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 +165 -0
  2. package/CHANGELOG.md +286 -0
  3. package/lib/editor.js +373 -178
  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-popover.js +70 -0
  9. package/lib/plugins/characters/custom-popover.js.map +1 -0
  10. package/lib/plugins/characters/index.js +266 -0
  11. package/lib/plugins/characters/index.js.map +1 -0
  12. package/lib/plugins/characters/utils.js +382 -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 +14 -11
  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 +43 -43
  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 +60 -64
  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 +196 -31
  77. package/src/index.jsx +22 -5
  78. package/src/plugins/characters/custom-popover.js +45 -0
  79. package/src/plugins/characters/index.jsx +244 -0
  80. package/src/plugins/characters/utils.js +448 -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 +8 -0
  95. package/src/plugins/toolbar/editor-and-toolbar.jsx +12 -4
  96. package/src/plugins/toolbar/toolbar-buttons.jsx +13 -2
  97. package/src/plugins/toolbar/toolbar.jsx +14 -4
  98. package/src/serialization.jsx +19 -3
package/lib/editor.js CHANGED
@@ -1,5 +1,9 @@
1
1
  "use strict";
2
2
 
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ var _typeof = require("@babel/runtime/helpers/typeof");
6
+
3
7
  Object.defineProperty(exports, "__esModule", {
4
8
  value: true
5
9
  });
@@ -17,6 +21,24 @@ Object.defineProperty(exports, "DEFAULT_PLUGINS", {
17
21
  });
18
22
  exports.serialization = exports["default"] = exports.Editor = void 0;
19
23
 
24
+ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
25
+
26
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
27
+
28
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
29
+
30
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
31
+
32
+ var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
33
+
34
+ var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
35
+
36
+ var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
37
+
38
+ var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
39
+
40
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
41
+
20
42
  var _slateReact = require("slate-react");
21
43
 
22
44
  var _slatePropTypes = _interopRequireDefault(require("slate-prop-types"));
@@ -43,33 +65,19 @@ var _classnames = _interopRequireDefault(require("classnames"));
43
65
 
44
66
  var _renderUi = require("@pie-lib/render-ui");
45
67
 
46
- function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj["default"] = obj; return newObj; } }
47
-
48
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
49
-
50
- function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
51
-
52
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
53
-
54
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
68
+ var _slatePlainSerializer = _interopRequireDefault(require("slate-plain-serializer"));
55
69
 
56
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
70
+ 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); }
57
71
 
58
- function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
72
+ 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; }
59
73
 
60
- function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
74
+ 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); }; }
61
75
 
62
- function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
76
+ 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; } }
63
77
 
64
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
78
+ 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; }
65
79
 
66
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
67
-
68
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
69
-
70
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
71
-
72
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
80
+ 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; }
73
81
 
74
82
  var log = (0, _debug["default"])('editable-html:editor');
75
83
  var defaultToolbarOpts = {
@@ -79,24 +87,127 @@ var defaultToolbarOpts = {
79
87
  showDone: true,
80
88
  doneOn: 'blur'
81
89
  };
90
+ var defaultResponseAreaProps = {
91
+ options: {},
92
+ respAreaToolbar: function respAreaToolbar() {},
93
+ onHandleAreaChange: function onHandleAreaChange() {}
94
+ };
95
+ var defaultLanguageCharactersProps = [];
82
96
 
83
97
  var createToolbarOpts = function createToolbarOpts(toolbarOpts) {
84
- return _objectSpread({}, defaultToolbarOpts, {}, toolbarOpts);
98
+ return _objectSpread(_objectSpread({}, defaultToolbarOpts), toolbarOpts);
85
99
  };
86
100
 
87
- var Editor =
88
- /*#__PURE__*/
89
- function (_React$Component) {
90
- _inherits(Editor, _React$Component);
101
+ var Editor = /*#__PURE__*/function (_React$Component) {
102
+ (0, _inherits2["default"])(Editor, _React$Component);
91
103
 
92
- function Editor(props) {
104
+ var _super = _createSuper(Editor);
105
+
106
+ function Editor(_props) {
93
107
  var _this;
94
108
 
95
- _classCallCheck(this, Editor);
109
+ (0, _classCallCheck2["default"])(this, Editor);
110
+ _this = _super.call(this, _props);
111
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "handlePlugins", function (props) {
112
+ var normalizedResponseAreaProps = _objectSpread(_objectSpread({}, defaultResponseAreaProps), props.responseAreaProps);
113
+
114
+ _this.plugins = (0, _plugins.buildPlugins)(props.activePlugins, {
115
+ math: {
116
+ onClick: _this.onMathClick,
117
+ onFocus: _this.onPluginFocus,
118
+ onBlur: _this.onPluginBlur
119
+ },
120
+ image: {
121
+ onDelete: props.imageSupport && props.imageSupport["delete"] && function (src, done) {
122
+ props.imageSupport["delete"](src, function (e) {
123
+ done(e, _this.state.value);
124
+ });
125
+ },
126
+ insertImageRequested: props.imageSupport && function (getHandler) {
127
+ /**
128
+ * The handler is the object through which the outer context
129
+ * communicates file upload events like: fileChosen, cancel, progress
130
+ */
131
+ var handler = getHandler(function () {
132
+ return _this.state.value;
133
+ });
134
+ props.imageSupport.add(handler);
135
+ },
136
+ onFocus: _this.onPluginFocus,
137
+ onBlur: _this.onPluginBlur,
138
+ maxImageWidth: _this.props.maxImageWidth,
139
+ maxImageHeight: _this.props.maxImageHeight
140
+ },
141
+ toolbar: {
142
+ /**
143
+ * To minimize converting html -> state -> html
144
+ * We only emit markup once 'done' is clicked.
145
+ */
146
+ disableUnderline: props.disableUnderline,
147
+ autoWidth: props.autoWidthToolbar,
148
+ onDone: function onDone() {
149
+ var _this$state$value$sta, _this$state$value$sta2;
96
150
 
97
- _this = _possibleConstructorReturn(this, _getPrototypeOf(Editor).call(this, props));
151
+ var nonEmpty = props.nonEmpty;
152
+ log('[onDone]');
98
153
 
99
- _defineProperty(_assertThisInitialized(_this), "onPluginBlur", function (e) {
154
+ _this.setState({
155
+ toolbarInFocus: false,
156
+ focusedNode: null
157
+ });
158
+
159
+ _this.editor.blur();
160
+
161
+ 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) {
162
+ _this.resetValue(true).then(function () {
163
+ _this.onEditingDone();
164
+ });
165
+ } else {
166
+ _this.onEditingDone();
167
+ }
168
+ }
169
+ },
170
+ table: {
171
+ onFocus: function onFocus() {
172
+ log('[table:onFocus]...');
173
+
174
+ _this.onPluginFocus();
175
+ },
176
+ onBlur: function onBlur() {
177
+ log('[table:onBlur]...');
178
+
179
+ _this.onPluginBlur();
180
+ }
181
+ },
182
+ responseArea: {
183
+ type: normalizedResponseAreaProps.type,
184
+ options: normalizedResponseAreaProps.options,
185
+ maxResponseAreas: normalizedResponseAreaProps.maxResponseAreas,
186
+ respAreaToolbar: normalizedResponseAreaProps.respAreaToolbar,
187
+ onHandleAreaChange: normalizedResponseAreaProps.onHandleAreaChange,
188
+ error: normalizedResponseAreaProps.error,
189
+ onFocus: function onFocus() {
190
+ log('[table:onFocus]...');
191
+
192
+ _this.onPluginFocus();
193
+ },
194
+ onBlur: function onBlur() {
195
+ log('[table:onBlur]...');
196
+
197
+ _this.onPluginBlur();
198
+ }
199
+ },
200
+ languageCharacters: props.languageCharactersProps,
201
+ media: {
202
+ focus: _this.focus,
203
+ createChange: function createChange() {
204
+ return _this.state.value.change();
205
+ },
206
+ onChange: _this.onChange
207
+ }
208
+ });
209
+ });
210
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "onPluginBlur", function (e) {
100
211
  log('[onPluginBlur]', e && e.relatedTarget);
101
212
  var target = e && e.relatedTarget;
102
213
  var node = target ? (0, _slateReact.findNode)(target, _this.state.value) : null;
@@ -108,8 +219,7 @@ function (_React$Component) {
108
219
  _this.resetValue();
109
220
  });
110
221
  });
111
-
112
- _defineProperty(_assertThisInitialized(_this), "onPluginFocus", function (e) {
222
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "onPluginFocus", function (e) {
113
223
  log('[onPluginFocus]', e && e.target);
114
224
  var target = e && e.target;
115
225
 
@@ -130,8 +240,7 @@ function (_React$Component) {
130
240
 
131
241
  _this.stashValue();
132
242
  });
133
-
134
- _defineProperty(_assertThisInitialized(_this), "onMathClick", function (node) {
243
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "onMathClick", function (node) {
135
244
  _this.editor.change(function (c) {
136
245
  return c.collapseToStartOf(node);
137
246
  });
@@ -140,8 +249,7 @@ function (_React$Component) {
140
249
  selectedNode: node
141
250
  });
142
251
  });
143
-
144
- _defineProperty(_assertThisInitialized(_this), "onEditingDone", function () {
252
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "onEditingDone", function () {
145
253
  log('[onEditingDone]');
146
254
 
147
255
  _this.setState({
@@ -153,8 +261,7 @@ function (_React$Component) {
153
261
 
154
262
  _this.props.onChange(_this.state.value, true);
155
263
  });
156
-
157
- _defineProperty(_assertThisInitialized(_this), "handleBlur", function (resolve) {
264
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "handleBlur", function (resolve) {
158
265
  var nonEmpty = _this.props.nonEmpty;
159
266
  var doneOn = _this.state.toolbarOpts.doneOn;
160
267
 
@@ -168,7 +275,9 @@ function (_React$Component) {
168
275
  }
169
276
 
170
277
  if (doneOn === 'blur') {
171
- if (nonEmpty && _this.state.value.startText.text.length === 0) {
278
+ var _this$state$value$sta3, _this$state$value$sta4;
279
+
280
+ 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) {
172
281
  _this.resetValue(true).then(function () {
173
282
  _this.onEditingDone();
174
283
 
@@ -181,22 +290,39 @@ function (_React$Component) {
181
290
  }
182
291
  }
183
292
  });
184
-
185
- _defineProperty(_assertThisInitialized(_this), "onBlur", function (event) {
293
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "onBlur", function (event) {
186
294
  log('[onBlur]');
187
295
  var target = event.relatedTarget;
188
296
  var node = target ? (0, _slateReact.findNode)(target, _this.state.value) : null;
189
297
  log('[onBlur] node: ', node);
190
298
  return new Promise(function (resolve) {
191
299
  _this.setState({
192
- focusedNode: node
193
- }, _this.handleBlur.bind(_assertThisInitialized(_this), resolve));
300
+ focusedNode: !node ? null : node
301
+ }, _this.handleBlur.bind((0, _assertThisInitialized2["default"])(_this), resolve));
194
302
 
195
303
  _this.props.onBlur(event);
196
304
  });
197
305
  });
306
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "handleDomBlur", function (e) {
307
+ var editorDOM = document.querySelector("[data-key=\"".concat(_this.state.value.document.key, "\"]"));
308
+ setTimeout(function () {
309
+ if (!_this.wrapperRef) {
310
+ return;
311
+ }
312
+
313
+ var editorElement = !editorDOM || document.activeElement.closest("[class*=\"".concat(editorDOM.className, "\"]"));
314
+ var toolbarElement = !_this.toolbarRef || document.activeElement.closest("[class*=\"".concat(_this.toolbarRef.className, "\"]"));
315
+
316
+ var isInCurrentComponent = _this.wrapperRef.contains(editorElement) || _this.wrapperRef.contains(toolbarElement);
317
+
318
+ if (!isInCurrentComponent) {
319
+ editorDOM.removeEventListener('blur', _this.handleDomBlur);
198
320
 
199
- _defineProperty(_assertThisInitialized(_this), "onFocus", function () {
321
+ _this.onBlur(e);
322
+ }
323
+ }, 50);
324
+ });
325
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "onFocus", function () {
200
326
  return new Promise(function (resolve) {
201
327
  var editorDOM = document.querySelector("[data-key=\"".concat(_this.state.value.document.key, "\"]"));
202
328
  log('[onFocus]', document.activeElement);
@@ -231,13 +357,8 @@ function (_React$Component) {
231
357
 
232
358
 
233
359
  if (editorDOM === document.activeElement) {
234
- var handleDomBlur = function handleDomBlur(e) {
235
- editorDOM.removeEventListener('blur', handleDomBlur);
236
-
237
- _this.onBlur(e);
238
- };
239
-
240
- editorDOM.addEventListener('blur', handleDomBlur);
360
+ editorDOM.removeEventListener('blur', _this.handleDomBlur);
361
+ editorDOM.addEventListener('blur', _this.handleDomBlur);
241
362
  }
242
363
 
243
364
  _this.stashValue();
@@ -247,8 +368,7 @@ function (_React$Component) {
247
368
  resolve();
248
369
  });
249
370
  });
250
-
251
- _defineProperty(_assertThisInitialized(_this), "stashValue", function () {
371
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "stashValue", function () {
252
372
  log('[stashValue]');
253
373
 
254
374
  if (!_this.state.stashedValue) {
@@ -257,8 +377,7 @@ function (_React$Component) {
257
377
  });
258
378
  }
259
379
  });
260
-
261
- _defineProperty(_assertThisInitialized(_this), "resetValue", function (force) {
380
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "resetValue", function (force) {
262
381
  var _this$state = _this.state,
263
382
  value = _this$state.value,
264
383
  focusedNode = _this$state.focusedNode;
@@ -292,12 +411,17 @@ function (_React$Component) {
292
411
  return Promise.resolve({});
293
412
  }
294
413
  });
295
-
296
- _defineProperty(_assertThisInitialized(_this), "onChange", function (change, done) {
414
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "onChange", function (change, done) {
297
415
  log('[onChange]');
416
+ var value = change.value;
417
+ var charactersLimit = _this.props.charactersLimit;
418
+
419
+ if (value && value.document && value.document.text && value.document.text.length > charactersLimit) {
420
+ return;
421
+ }
298
422
 
299
423
  _this.setState({
300
- value: change.value
424
+ value: value
301
425
  }, function () {
302
426
  log('[onChange], call done()');
303
427
 
@@ -306,8 +430,7 @@ function (_React$Component) {
306
430
  }
307
431
  });
308
432
  });
309
-
310
- _defineProperty(_assertThisInitialized(_this), "valueToSize", function (v) {
433
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "valueToSize", function (v) {
311
434
  if (!v) {
312
435
  return;
313
436
  }
@@ -329,8 +452,7 @@ function (_React$Component) {
329
452
 
330
453
  return;
331
454
  });
332
-
333
- _defineProperty(_assertThisInitialized(_this), "validateNode", function (node) {
455
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "validateNode", function (node) {
334
456
  if (node.object !== 'block') return;
335
457
  var last = node.nodes.last();
336
458
  if (!last) return;
@@ -343,16 +465,16 @@ function (_React$Component) {
343
465
  log('[validateNode] parent:', parent, p);
344
466
  return undefined;
345
467
  });
346
-
347
- _defineProperty(_assertThisInitialized(_this), "changeData", function (key, data) {
468
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "changeData", function (key, data) {
348
469
  log('[changeData]. .. ', key, data);
349
470
  /**
350
471
  * HACK ALERT: We should be calling setState here and storing the change data:
351
472
  *
352
473
  * <code>this.setState({changeData: { key, data}})</code>
353
- * However this is causing issues with the Mathquill instance. The 'input' event stops firing on the element and no more changes get through.
354
- * The issues seem to be related to the promises in onBlur/onFocus. But removing these brings it's own problems.
355
- * A major clean up is planned for this component so I've decided to temporarily settle on this hack rather than spend more time on this.
474
+ * However this is causing issues with the Mathquill instance. The 'input' event stops firing on the element and no
475
+ * more changes get through. The issues seem to be related to the promises in onBlur/onFocus. But removing these
476
+ * brings it's own problems. A major clean up is planned for this component so I've decided to temporarily settle
477
+ * on this hack rather than spend more time on this.
356
478
  */
357
479
  // Uncomment this line to see the bug described above.
358
480
  // this.setState({changeData: {key, data}})
@@ -362,114 +484,150 @@ function (_React$Component) {
362
484
  data: data
363
485
  };
364
486
  });
365
-
366
- _defineProperty(_assertThisInitialized(_this), "focus", function (pos, node) {
487
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "focus", function (pos, node) {
367
488
  var position = pos || 'end';
368
489
 
369
490
  _this.props.focus(position, node);
370
491
  });
492
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "onDropPaste", /*#__PURE__*/function () {
493
+ var _ref = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(event, change, dropContext) {
494
+ var editor, transfer, file, type, fragment, text, src, inline, range, ch, _change$value, _document, selection, startBlock, defaultBlock, defaultMarks, frag;
495
+
496
+ return _regenerator["default"].wrap(function _callee$(_context) {
497
+ while (1) {
498
+ switch (_context.prev = _context.next) {
499
+ case 0:
500
+ editor = change.editor;
501
+ transfer = (0, _slateReact.getEventTransfer)(event);
502
+ file = transfer.files && transfer.files[0];
503
+ type = transfer.type;
504
+ fragment = transfer.fragment;
505
+ text = transfer.text;
506
+
507
+ if (!(file && (file.type === 'image/jpeg' || file.type === 'image/jpg' || file.type === 'image/png'))) {
508
+ _context.next = 25;
509
+ break;
510
+ }
511
+
512
+ if (_this.props.imageSupport) {
513
+ _context.next = 9;
514
+ break;
515
+ }
516
+
517
+ return _context.abrupt("return");
518
+
519
+ case 9:
520
+ _context.prev = 9;
521
+ log('[onDropPaste]');
522
+ _context.next = 13;
523
+ return (0, serialization.getBase64)(file);
524
+
525
+ case 13:
526
+ src = _context.sent;
527
+ inline = _slate.Inline.create({
528
+ type: 'image',
529
+ isVoid: true,
530
+ data: {
531
+ loading: false,
532
+ src: src
533
+ }
534
+ });
535
+
536
+ if (dropContext) {
537
+ _this.focus();
538
+ } else {
539
+ range = (0, _slateReact.getEventRange)(event, editor);
540
+
541
+ if (range) {
542
+ change.select(range);
543
+ }
544
+ }
545
+
546
+ ch = change.insertInline(inline);
547
+
548
+ _this.onChange(ch);
549
+
550
+ _context.next = 23;
551
+ break;
552
+
553
+ case 20:
554
+ _context.prev = 20;
555
+ _context.t0 = _context["catch"](9);
556
+ log('[onDropPaste] error: ', _context.t0);
557
+
558
+ case 23:
559
+ _context.next = 39;
560
+ break;
561
+
562
+ case 25:
563
+ if (!(type === 'fragment')) {
564
+ _context.next = 29;
565
+ break;
566
+ }
567
+
568
+ change.insertFragment(fragment);
569
+ _context.next = 39;
570
+ break;
571
+
572
+ case 29:
573
+ if (!(type === 'text' || type === 'html')) {
574
+ _context.next = 39;
575
+ break;
576
+ }
577
+
578
+ if (text) {
579
+ _context.next = 32;
580
+ break;
581
+ }
582
+
583
+ return _context.abrupt("return");
584
+
585
+ case 32:
586
+ _change$value = change.value, _document = _change$value.document, selection = _change$value.selection, startBlock = _change$value.startBlock;
587
+
588
+ if (!startBlock.isVoid) {
589
+ _context.next = 35;
590
+ break;
591
+ }
592
+
593
+ return _context.abrupt("return");
594
+
595
+ case 35:
596
+ defaultBlock = startBlock;
597
+ defaultMarks = _document.getInsertMarksAtRange(selection);
598
+ frag = _slatePlainSerializer["default"].deserialize(text, {
599
+ defaultBlock: defaultBlock,
600
+ defaultMarks: defaultMarks
601
+ }).document;
602
+ change.insertFragment(frag);
603
+
604
+ case 39:
605
+ case "end":
606
+ return _context.stop();
607
+ }
608
+ }
609
+ }, _callee, null, [[9, 20]]);
610
+ }));
371
611
 
612
+ return function (_x, _x2, _x3) {
613
+ return _ref.apply(this, arguments);
614
+ };
615
+ }());
372
616
  _this.state = {
373
- value: props.value,
374
- toolbarOpts: createToolbarOpts(props.toolbarOpts)
617
+ value: _props.value,
618
+ toolbarOpts: createToolbarOpts(_props.toolbarOpts)
375
619
  };
376
620
 
377
621
  _this.onResize = function () {
378
- props.onChange(_this.state.value, true);
622
+ _props.onChange(_this.state.value, true);
379
623
  };
380
624
 
381
- _this.plugins = (0, _plugins.buildPlugins)(props.activePlugins, {
382
- math: {
383
- onClick: _this.onMathClick,
384
- onFocus: _this.onPluginFocus,
385
- onBlur: _this.onPluginBlur
386
- },
387
- image: {
388
- onDelete: _this.props.imageSupport && _this.props.imageSupport["delete"] && function (src, done) {
389
- _this.props.imageSupport["delete"](src, function (e) {
390
- done(e, _this.state.value);
391
- });
392
- },
393
- insertImageRequested: _this.props.imageSupport && function (getHandler) {
394
- /**
395
- * The handler is the object through which the outer context
396
- * communicates file upload events like: fileChosen, cancel, progress
397
- */
398
- var handler = getHandler(function () {
399
- return _this.state.value;
400
- });
401
-
402
- _this.props.imageSupport.add(handler);
403
- },
404
- onFocus: _this.onPluginFocus,
405
- onBlur: _this.onPluginBlur
406
- },
407
- toolbar: {
408
- /**
409
- * To minimize converting html -> state -> html
410
- * We only emit markup once 'done' is clicked.
411
- */
412
- disableUnderline: props.disableUnderline,
413
- autoWidth: props.autoWidthToolbar,
414
- onDone: function onDone() {
415
- var nonEmpty = _this.props.nonEmpty;
416
- log('[onDone]');
417
-
418
- _this.setState({
419
- toolbarInFocus: false,
420
- focusedNode: null
421
- });
422
-
423
- _this.editor.blur();
625
+ _this.handlePlugins(_this.props);
424
626
 
425
- if (nonEmpty && _this.state.value.startText.text.length === 0) {
426
- _this.resetValue(true).then(function () {
427
- _this.onEditingDone();
428
- });
429
- } else {
430
- _this.onEditingDone();
431
- }
432
- }
433
- },
434
- table: {
435
- onFocus: function onFocus() {
436
- log('[table:onFocus]...');
437
-
438
- _this.onPluginFocus();
439
- },
440
- onBlur: function onBlur() {
441
- log('[table:onBlur]...');
442
-
443
- _this.onPluginBlur();
444
- }
445
- },
446
- responseArea: {
447
- type: props.responseAreaProps && props.responseAreaProps.type,
448
- options: props.responseAreaProps && props.responseAreaProps.options,
449
- respAreaToolbar: props.responseAreaProps && props.responseAreaProps.respAreaToolbar,
450
- onFocus: function onFocus() {
451
- log('[table:onFocus]...');
452
-
453
- _this.onPluginFocus();
454
- },
455
- onBlur: function onBlur() {
456
- log('[table:onBlur]...');
457
-
458
- _this.onPluginBlur();
459
- }
460
- },
461
- media: {
462
- focus: _this.focus,
463
- createChange: function createChange() {
464
- return _this.state.value.change();
465
- },
466
- onChange: _this.onChange
467
- }
468
- });
469
627
  return _this;
470
628
  }
471
629
 
472
- _createClass(Editor, [{
630
+ (0, _createClass2["default"])(Editor, [{
473
631
  key: "componentDidMount",
474
632
  value: function componentDidMount() {
475
633
  var _this2 = this;
@@ -503,14 +661,29 @@ function (_React$Component) {
503
661
  toolbarOpts: newToolbarOpts
504
662
  });
505
663
  }
664
+
665
+ if (!(0, _isEqual["default"])(nextProps.languageCharactersProps, this.props.languageCharactersProps)) {
666
+ this.handlePlugins(nextProps);
667
+ }
668
+ }
669
+ }, {
670
+ key: "componentDidUpdate",
671
+ value: function componentDidUpdate() {
672
+ // The cursor is on a zero width element and when that is placed near void elements, it is not visible
673
+ // so we increase the width to at least 2px in order for the user to see it
674
+ var zeroWidthEls = document.querySelectorAll('[data-slate-zero-width="z"]');
675
+ Array.from(zeroWidthEls).forEach(function (el) {
676
+ el.style.minWidth = '2px';
677
+ el.style.display = 'inline-block';
678
+ });
506
679
  }
507
680
  }, {
508
681
  key: "componentWillUnmount",
509
-
682
+ value:
510
683
  /**
511
684
  * Remove onResize event listener
512
685
  */
513
- value: function componentWillUnmount() {
686
+ function componentWillUnmount() {
514
687
  window.removeEventListener('resize', this.onResize);
515
688
  } // Allowing time for onChange to take effect if it is called
516
689
 
@@ -547,6 +720,7 @@ function (_React$Component) {
547
720
 
548
721
  var _this$props2 = this.props,
549
722
  disabled = _this$props2.disabled,
723
+ spellCheck = _this$props2.spellCheck,
550
724
  highlightShape = _this$props2.highlightShape,
551
725
  classes = _this$props2.classes,
552
726
  className = _this$props2.className,
@@ -559,16 +733,16 @@ function (_React$Component) {
559
733
  toolbarOpts = _this$state2.toolbarOpts;
560
734
  log('[render] value: ', value);
561
735
  var sizeStyle = this.buildSizeStyle();
562
- var names = (0, _classnames["default"])((_classNames = {}, _defineProperty(_classNames, classes.withBg, highlightShape), _defineProperty(_classNames, classes.toolbarOnTop, toolbarOpts.alwaysVisible && toolbarOpts.position === 'top'), _classNames), className);
563
- return _react["default"].createElement("div", {
564
- ref: function ref(_ref) {
565
- return _this3.wrapperRef = _ref;
736
+ 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);
737
+ return /*#__PURE__*/_react["default"].createElement("div", {
738
+ ref: function ref(_ref2) {
739
+ return _this3.wrapperRef = _ref2;
566
740
  },
567
741
  style: {
568
742
  width: sizeStyle.width
569
743
  },
570
744
  className: names
571
- }, _react["default"].createElement(_slateReact.Editor, {
745
+ }, /*#__PURE__*/_react["default"].createElement(_slateReact.Editor, {
572
746
  plugins: this.plugins,
573
747
  innerRef: function innerRef(r) {
574
748
  if (r) {
@@ -578,16 +752,28 @@ function (_React$Component) {
578
752
  ref: function ref(r) {
579
753
  return _this3.editor = r && _this3.props.editorRef(r);
580
754
  },
755
+ toolbarRef: function toolbarRef(r) {
756
+ if (r) {
757
+ _this3.toolbarRef = r;
758
+ }
759
+ },
581
760
  value: value,
582
761
  focus: this.focus,
583
762
  onKeyDown: onKeyDown,
584
763
  onChange: this.onChange,
585
764
  onBlur: this.onBlur,
765
+ onDrop: function onDrop(event, editor) {
766
+ return _this3.onDropPaste(event, editor, true);
767
+ },
768
+ onPaste: function onPaste(event, editor) {
769
+ return _this3.onDropPaste(event, editor);
770
+ },
586
771
  onFocus: this.onFocus,
587
772
  onEditingDone: this.onEditingDone,
588
773
  focusedNode: focusedNode,
589
774
  normalize: this.normalize,
590
775
  readOnly: disabled,
776
+ spellCheck: spellCheck,
591
777
  className: classes.slateEditor,
592
778
  style: {
593
779
  minHeight: sizeStyle.minHeight,
@@ -601,14 +787,12 @@ function (_React$Component) {
601
787
  }));
602
788
  }
603
789
  }]);
604
-
605
790
  return Editor;
606
791
  }(_react["default"].Component); // TODO color - hardcoded gray background and keypad colors will need to change too
607
792
 
608
793
 
609
794
  exports.Editor = Editor;
610
-
611
- _defineProperty(Editor, "propTypes", {
795
+ (0, _defineProperty2["default"])(Editor, "propTypes", {
612
796
  autoFocus: _propTypes["default"].bool,
613
797
  editorRef: _propTypes["default"].func.isRequired,
614
798
  onRef: _propTypes["default"].func.isRequired,
@@ -619,6 +803,7 @@ _defineProperty(Editor, "propTypes", {
619
803
  focus: _propTypes["default"].func.isRequired,
620
804
  value: _slatePropTypes["default"].value.isRequired,
621
805
  imageSupport: _propTypes["default"].object,
806
+ charactersLimit: _propTypes["default"].number,
622
807
  width: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].number]),
623
808
  height: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].number]),
624
809
  minHeight: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].number]),
@@ -626,6 +811,7 @@ _defineProperty(Editor, "propTypes", {
626
811
  classes: _propTypes["default"].object.isRequired,
627
812
  highlightShape: _propTypes["default"].bool,
628
813
  disabled: _propTypes["default"].bool,
814
+ spellCheck: _propTypes["default"].bool,
629
815
  nonEmpty: _propTypes["default"].bool,
630
816
  disableUnderline: _propTypes["default"].bool,
631
817
  autoWidthToolbar: _propTypes["default"].bool,
@@ -635,8 +821,13 @@ _defineProperty(Editor, "propTypes", {
635
821
  type: _propTypes["default"].oneOf(['explicit-constructed-response', 'inline-dropdown', 'drag-in-the-blank']),
636
822
  options: _propTypes["default"].object,
637
823
  respAreaToolbar: _propTypes["default"].func,
638
- onDelete: _propTypes["default"].func
824
+ onHandleAreaChange: _propTypes["default"].func
639
825
  }),
826
+ languageCharactersProps: _propTypes["default"].arrayOf(_propTypes["default"].shape({
827
+ language: _propTypes["default"].string,
828
+ characterIcon: _propTypes["default"].string,
829
+ characters: _propTypes["default"].arrayOf(_propTypes["default"].arrayOf(_propTypes["default"].string))
830
+ })),
640
831
  toolbarOpts: _propTypes["default"].shape({
641
832
  position: _propTypes["default"].oneOf(['bottom', 'top']),
642
833
  alignment: _propTypes["default"].oneOf(['left', 'right']),
@@ -650,17 +841,19 @@ _defineProperty(Editor, "propTypes", {
650
841
  });
651
842
  return !allValid && new Error("Invalid values: ".concat(values, ", values must be one of [").concat(_plugins.ALL_PLUGINS.join(','), "]"));
652
843
  }),
653
- className: _propTypes["default"].string
844
+ className: _propTypes["default"].string,
845
+ maxImageWidth: _propTypes["default"].number,
846
+ maxImageHeight: _propTypes["default"].number
654
847
  });
655
-
656
- _defineProperty(Editor, "defaultProps", {
848
+ (0, _defineProperty2["default"])(Editor, "defaultProps", {
657
849
  disableUnderline: true,
658
850
  onFocus: function onFocus() {},
659
851
  onBlur: function onBlur() {},
852
+ onKeyDown: function onKeyDown() {},
660
853
  toolbarOpts: defaultToolbarOpts,
661
- onKeyDown: function onKeyDown() {}
854
+ responseAreaProps: defaultResponseAreaProps,
855
+ languageCharactersProps: defaultLanguageCharactersProps
662
856
  });
663
-
664
857
  var styles = {
665
858
  withBg: {
666
859
  backgroundColor: 'rgba(0,0,0,0.06)'
@@ -674,7 +867,7 @@ var styles = {
674
867
  color: _renderUi.color.text(),
675
868
  backgroundColor: _renderUi.color.background()
676
869
  },
677
- '& tr': {
870
+ '& table:not([border="1"]) tr': {
678
871
  borderTop: '1px solid #dfe2e5' // TODO perhaps secondary color for background, for now disable
679
872
  // '&:nth-child(2n)': {
680
873
  // backgroundColor: '#f6f8fa'
@@ -682,9 +875,11 @@ var styles = {
682
875
 
683
876
  },
684
877
  '& td, th': {
685
- border: '1px solid #dfe2e5',
686
878
  padding: '.6em 1em',
687
879
  textAlign: 'center'
880
+ },
881
+ '& table:not([border="1"]) td, th': {
882
+ border: '1px solid #dfe2e5'
688
883
  }
689
884
  },
690
885
  toolbarOnTop: {