@pie-lib/editable-html 11.1.2-next.0 → 11.2.0-beta.2

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 (166) hide show
  1. package/CHANGELOG.md +50 -158
  2. package/NEXT.CHANGELOG.json +1 -0
  3. package/package.json +11 -6
  4. package/src/__tests__/editor.test.jsx +363 -0
  5. package/src/__tests__/serialization.test.js +291 -0
  6. package/src/__tests__/utils.js +36 -0
  7. package/src/block-tags.js +17 -0
  8. package/src/constants.js +7 -0
  9. package/src/editor.jsx +303 -49
  10. package/src/index.jsx +19 -10
  11. package/src/plugins/characters/index.jsx +11 -3
  12. package/src/plugins/characters/utils.js +12 -12
  13. package/src/plugins/css/icons/index.jsx +17 -0
  14. package/src/plugins/css/index.jsx +346 -0
  15. package/src/plugins/customPlugin/index.jsx +85 -0
  16. package/src/plugins/html/index.jsx +9 -6
  17. package/src/plugins/image/__tests__/__snapshots__/component.test.jsx.snap +51 -0
  18. package/src/plugins/image/__tests__/__snapshots__/image-toolbar-logic.test.jsx.snap +27 -0
  19. package/src/plugins/image/__tests__/__snapshots__/image-toolbar.test.jsx.snap +44 -0
  20. package/src/plugins/image/__tests__/component.test.jsx +41 -0
  21. package/src/plugins/image/__tests__/image-toolbar-logic.test.jsx +42 -0
  22. package/src/plugins/image/__tests__/image-toolbar.test.jsx +11 -0
  23. package/src/plugins/image/__tests__/index.test.js +95 -0
  24. package/src/plugins/image/__tests__/insert-image-handler.test.js +113 -0
  25. package/src/plugins/image/__tests__/mock-change.js +15 -0
  26. package/src/plugins/image/index.jsx +2 -1
  27. package/src/plugins/image/insert-image-handler.js +13 -6
  28. package/src/plugins/index.jsx +248 -5
  29. package/src/plugins/list/__tests__/index.test.js +54 -0
  30. package/src/plugins/list/index.jsx +130 -0
  31. package/src/plugins/math/__tests__/__snapshots__/index.test.jsx.snap +48 -0
  32. package/src/plugins/math/__tests__/index.test.jsx +245 -0
  33. package/src/plugins/math/index.jsx +87 -56
  34. package/src/plugins/media/__tests__/index.test.js +75 -0
  35. package/src/plugins/media/index.jsx +3 -2
  36. package/src/plugins/media/media-dialog.js +106 -57
  37. package/src/plugins/rendering/index.js +31 -0
  38. package/src/plugins/respArea/drag-in-the-blank/choice.jsx +4 -1
  39. package/src/plugins/respArea/explicit-constructed-response/index.jsx +10 -8
  40. package/src/plugins/respArea/index.jsx +53 -7
  41. package/src/plugins/respArea/inline-dropdown/index.jsx +13 -6
  42. package/src/plugins/respArea/math-templated/index.jsx +104 -0
  43. package/src/plugins/respArea/utils.jsx +11 -0
  44. package/src/plugins/table/CustomTablePlugin.js +113 -0
  45. package/src/plugins/table/__tests__/__snapshots__/table-toolbar.test.jsx.snap +44 -0
  46. package/src/plugins/table/__tests__/index.test.jsx +401 -0
  47. package/src/plugins/table/__tests__/table-toolbar.test.jsx +42 -0
  48. package/src/plugins/table/index.jsx +46 -59
  49. package/src/plugins/table/table-toolbar.jsx +39 -2
  50. package/src/plugins/textAlign/icons/index.jsx +139 -0
  51. package/src/plugins/textAlign/index.jsx +23 -0
  52. package/src/plugins/toolbar/__tests__/__snapshots__/default-toolbar.test.jsx.snap +923 -0
  53. package/src/plugins/toolbar/__tests__/__snapshots__/editor-and-toolbar.test.jsx.snap +20 -0
  54. package/src/plugins/toolbar/__tests__/__snapshots__/toolbar-buttons.test.jsx.snap +36 -0
  55. package/src/plugins/toolbar/__tests__/__snapshots__/toolbar.test.jsx.snap +46 -0
  56. package/src/plugins/toolbar/__tests__/default-toolbar.test.jsx +94 -0
  57. package/src/plugins/toolbar/__tests__/editor-and-toolbar.test.jsx +37 -0
  58. package/src/plugins/toolbar/__tests__/toolbar-buttons.test.jsx +51 -0
  59. package/src/plugins/toolbar/__tests__/toolbar.test.jsx +106 -0
  60. package/src/plugins/toolbar/default-toolbar.jsx +82 -20
  61. package/src/plugins/toolbar/done-button.jsx +3 -1
  62. package/src/plugins/toolbar/editor-and-toolbar.jsx +18 -13
  63. package/src/plugins/toolbar/toolbar-buttons.jsx +52 -11
  64. package/src/plugins/toolbar/toolbar.jsx +31 -8
  65. package/src/serialization.jsx +213 -38
  66. package/README.md +0 -45
  67. package/deploy.sh +0 -16
  68. package/lib/editor.js +0 -1094
  69. package/lib/editor.js.map +0 -1
  70. package/lib/index.js +0 -253
  71. package/lib/index.js.map +0 -1
  72. package/lib/parse-html.js +0 -16
  73. package/lib/parse-html.js.map +0 -1
  74. package/lib/plugins/characters/custom-popper.js +0 -73
  75. package/lib/plugins/characters/custom-popper.js.map +0 -1
  76. package/lib/plugins/characters/index.js +0 -300
  77. package/lib/plugins/characters/index.js.map +0 -1
  78. package/lib/plugins/characters/utils.js +0 -381
  79. package/lib/plugins/characters/utils.js.map +0 -1
  80. package/lib/plugins/html/icons/index.js +0 -38
  81. package/lib/plugins/html/icons/index.js.map +0 -1
  82. package/lib/plugins/html/index.js +0 -76
  83. package/lib/plugins/html/index.js.map +0 -1
  84. package/lib/plugins/image/alt-dialog.js +0 -129
  85. package/lib/plugins/image/alt-dialog.js.map +0 -1
  86. package/lib/plugins/image/component.js +0 -419
  87. package/lib/plugins/image/component.js.map +0 -1
  88. package/lib/plugins/image/image-toolbar.js +0 -177
  89. package/lib/plugins/image/image-toolbar.js.map +0 -1
  90. package/lib/plugins/image/index.js +0 -262
  91. package/lib/plugins/image/index.js.map +0 -1
  92. package/lib/plugins/image/insert-image-handler.js +0 -152
  93. package/lib/plugins/image/insert-image-handler.js.map +0 -1
  94. package/lib/plugins/index.js +0 -143
  95. package/lib/plugins/index.js.map +0 -1
  96. package/lib/plugins/list/index.js +0 -204
  97. package/lib/plugins/list/index.js.map +0 -1
  98. package/lib/plugins/math/index.js +0 -419
  99. package/lib/plugins/math/index.js.map +0 -1
  100. package/lib/plugins/media/index.js +0 -384
  101. package/lib/plugins/media/index.js.map +0 -1
  102. package/lib/plugins/media/media-dialog.js +0 -668
  103. package/lib/plugins/media/media-dialog.js.map +0 -1
  104. package/lib/plugins/media/media-toolbar.js +0 -101
  105. package/lib/plugins/media/media-toolbar.js.map +0 -1
  106. package/lib/plugins/media/media-wrapper.js +0 -93
  107. package/lib/plugins/media/media-wrapper.js.map +0 -1
  108. package/lib/plugins/respArea/drag-in-the-blank/choice.js +0 -251
  109. package/lib/plugins/respArea/drag-in-the-blank/choice.js.map +0 -1
  110. package/lib/plugins/respArea/drag-in-the-blank/index.js +0 -97
  111. package/lib/plugins/respArea/drag-in-the-blank/index.js.map +0 -1
  112. package/lib/plugins/respArea/explicit-constructed-response/index.js +0 -55
  113. package/lib/plugins/respArea/explicit-constructed-response/index.js.map +0 -1
  114. package/lib/plugins/respArea/icons/index.js +0 -95
  115. package/lib/plugins/respArea/icons/index.js.map +0 -1
  116. package/lib/plugins/respArea/index.js +0 -293
  117. package/lib/plugins/respArea/index.js.map +0 -1
  118. package/lib/plugins/respArea/inline-dropdown/index.js +0 -70
  119. package/lib/plugins/respArea/inline-dropdown/index.js.map +0 -1
  120. package/lib/plugins/respArea/utils.js +0 -110
  121. package/lib/plugins/respArea/utils.js.map +0 -1
  122. package/lib/plugins/table/icons/index.js +0 -69
  123. package/lib/plugins/table/icons/index.js.map +0 -1
  124. package/lib/plugins/table/index.js +0 -499
  125. package/lib/plugins/table/index.js.map +0 -1
  126. package/lib/plugins/table/table-toolbar.js +0 -158
  127. package/lib/plugins/table/table-toolbar.js.map +0 -1
  128. package/lib/plugins/toolbar/default-toolbar.js +0 -174
  129. package/lib/plugins/toolbar/default-toolbar.js.map +0 -1
  130. package/lib/plugins/toolbar/done-button.js +0 -50
  131. package/lib/plugins/toolbar/done-button.js.map +0 -1
  132. package/lib/plugins/toolbar/editor-and-toolbar.js +0 -287
  133. package/lib/plugins/toolbar/editor-and-toolbar.js.map +0 -1
  134. package/lib/plugins/toolbar/index.js +0 -34
  135. package/lib/plugins/toolbar/index.js.map +0 -1
  136. package/lib/plugins/toolbar/toolbar-buttons.js +0 -161
  137. package/lib/plugins/toolbar/toolbar-buttons.js.map +0 -1
  138. package/lib/plugins/toolbar/toolbar.js +0 -352
  139. package/lib/plugins/toolbar/toolbar.js.map +0 -1
  140. package/lib/plugins/utils.js +0 -62
  141. package/lib/plugins/utils.js.map +0 -1
  142. package/lib/serialization.js +0 -488
  143. package/lib/serialization.js.map +0 -1
  144. package/lib/theme.js +0 -9
  145. package/lib/theme.js.map +0 -1
  146. package/playground/image/data.js +0 -59
  147. package/playground/image/index.html +0 -22
  148. package/playground/image/index.jsx +0 -81
  149. package/playground/index.html +0 -25
  150. package/playground/mathquill/index.html +0 -22
  151. package/playground/mathquill/index.jsx +0 -155
  152. package/playground/package.json +0 -15
  153. package/playground/prod-test/index.html +0 -22
  154. package/playground/prod-test/index.jsx +0 -28
  155. package/playground/schema-override/data.js +0 -29
  156. package/playground/schema-override/image-plugin.jsx +0 -41
  157. package/playground/schema-override/index.html +0 -21
  158. package/playground/schema-override/index.jsx +0 -97
  159. package/playground/serialization/data.js +0 -29
  160. package/playground/serialization/image-plugin.jsx +0 -41
  161. package/playground/serialization/index.html +0 -22
  162. package/playground/serialization/index.jsx +0 -12
  163. package/playground/static.json +0 -3
  164. package/playground/table-examples.html +0 -70
  165. package/playground/webpack.config.js +0 -42
  166. package/static.json +0 -1
package/lib/editor.js DELETED
@@ -1,1094 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
- var _typeof = require("@babel/runtime/helpers/typeof");
6
-
7
- Object.defineProperty(exports, "__esModule", {
8
- value: true
9
- });
10
- Object.defineProperty(exports, "ALL_PLUGINS", {
11
- enumerable: true,
12
- get: function get() {
13
- return _plugins.ALL_PLUGINS;
14
- }
15
- });
16
- Object.defineProperty(exports, "DEFAULT_PLUGINS", {
17
- enumerable: true,
18
- get: function get() {
19
- return _plugins.DEFAULT_PLUGINS;
20
- }
21
- });
22
- exports.serialization = exports["default"] = exports.Editor = void 0;
23
-
24
- var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
25
-
26
- var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
27
-
28
- var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
29
-
30
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
31
-
32
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
33
-
34
- var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
35
-
36
- var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
37
-
38
- var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
39
-
40
- var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
41
-
42
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
43
-
44
- var _slateReact = require("slate-react");
45
-
46
- var _slatePropTypes = _interopRequireDefault(require("slate-prop-types"));
47
-
48
- var _isEqual = _interopRequireDefault(require("lodash/isEqual"));
49
-
50
- var serialization = _interopRequireWildcard(require("./serialization"));
51
-
52
- exports.serialization = serialization;
53
-
54
- var _propTypes = _interopRequireDefault(require("prop-types"));
55
-
56
- var _react = _interopRequireDefault(require("react"));
57
-
58
- var _slate = require("slate");
59
-
60
- var _plugins = require("./plugins");
61
-
62
- var _debug = _interopRequireDefault(require("debug"));
63
-
64
- var _styles = require("@material-ui/core/styles");
65
-
66
- var _classnames = _interopRequireDefault(require("classnames"));
67
-
68
- var _renderUi = require("@pie-lib/render-ui");
69
-
70
- var _slatePlainSerializer = _interopRequireDefault(require("slate-plain-serializer"));
71
-
72
- var _configUi = require("@pie-lib/config-ui");
73
-
74
- var _insertImageHandler = _interopRequireDefault(require("./plugins/image/insert-image-handler"));
75
-
76
- 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); }
77
-
78
- 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; }
79
-
80
- 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); }; }
81
-
82
- 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; } }
83
-
84
- 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; }
85
-
86
- 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; }
87
-
88
- var log = (0, _debug["default"])('editable-html:editor');
89
- var defaultToolbarOpts = {
90
- position: 'bottom',
91
- alignment: 'left',
92
- alwaysVisible: false,
93
- showDone: true,
94
- doneOn: 'blur'
95
- };
96
- var defaultResponseAreaProps = {
97
- options: {},
98
- respAreaToolbar: function respAreaToolbar() {},
99
- onHandleAreaChange: function onHandleAreaChange() {}
100
- };
101
- var defaultLanguageCharactersProps = [];
102
-
103
- var createToolbarOpts = function createToolbarOpts(toolbarOpts, error, isHtmlMode) {
104
- return _objectSpread(_objectSpread(_objectSpread({}, defaultToolbarOpts), toolbarOpts), {}, {
105
- error: error,
106
- isHtmlMode: isHtmlMode
107
- });
108
- };
109
-
110
- var Editor = /*#__PURE__*/function (_React$Component) {
111
- (0, _inherits2["default"])(Editor, _React$Component);
112
-
113
- var _super = _createSuper(Editor);
114
-
115
- function Editor(_props) {
116
- var _this;
117
-
118
- (0, _classCallCheck2["default"])(this, Editor);
119
- _this = _super.call(this, _props);
120
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "handleAlertDialog", function (open, extraDialogProps, callback) {
121
- _this.setState({
122
- dialog: _objectSpread({
123
- open: open
124
- }, extraDialogProps),
125
- isEdited: false
126
- }, callback);
127
- });
128
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "toggleHtmlMode", function () {
129
- _this.setState(function (prevState) {
130
- return {
131
- isHtmlMode: !prevState.isHtmlMode
132
- };
133
- }, function () {
134
- var error = _this.props.error;
135
- var toolbarOpts = _this.state.toolbarOpts;
136
- var newToolbarOpts = createToolbarOpts(toolbarOpts, error, _this.state.isHtmlMode);
137
-
138
- _this.setState({
139
- toolbarOpts: newToolbarOpts
140
- });
141
- });
142
- });
143
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "handlePlugins", function (props) {
144
- var normalizedResponseAreaProps = _objectSpread(_objectSpread({}, defaultResponseAreaProps), props.responseAreaProps);
145
-
146
- var htmlPluginOpts = {
147
- isHtmlMode: _this.state.isHtmlMode,
148
- isEdited: _this.state.isEdited,
149
- toggleHtmlMode: _this.toggleHtmlMode,
150
- handleAlertDialog: _this.handleAlertDialog
151
- };
152
- _this.plugins = (0, _plugins.buildPlugins)(props.activePlugins, {
153
- math: _objectSpread({
154
- onClick: _this.onMathClick,
155
- onFocus: _this.onPluginFocus,
156
- onBlur: _this.onPluginBlur
157
- }, props.mathMlOptions),
158
- html: htmlPluginOpts,
159
- image: {
160
- disableImageAlignmentButtons: props.disableImageAlignmentButtons,
161
- onDelete: props.imageSupport && props.imageSupport["delete"] && function (src, done) {
162
- props.imageSupport["delete"](src, function (e) {
163
- done(e, _this.state.value);
164
- });
165
- },
166
- insertImageRequested: props.imageSupport && function (addedImage, getHandler) {
167
- var pendingImages = _this.state.pendingImages;
168
-
169
- var onFinish = function onFinish(result) {
170
- var cb;
171
-
172
- if (_this.state.scheduled && result) {
173
- // finish editing only on success
174
- cb = _this.onEditingDone.bind((0, _assertThisInitialized2["default"])(_this));
175
- }
176
-
177
- var newPendingImages = _this.state.pendingImages.filter(function (img) {
178
- return img.key !== addedImage.key;
179
- });
180
-
181
- var newState = {
182
- pendingImages: newPendingImages
183
- };
184
-
185
- if (newPendingImages.length === 0) {
186
- newState.scheduled = false;
187
- }
188
-
189
- _this.setState(newState, cb);
190
- };
191
-
192
- var callback = function callback() {
193
- /**
194
- * The handler is the object through which the outer context
195
- * communicates file upload events like: fileChosen, cancel, progress
196
- */
197
- var handler = getHandler(onFinish, function () {
198
- return _this.state.value;
199
- });
200
- props.imageSupport.add(handler);
201
- };
202
-
203
- _this.setState({
204
- pendingImages: [].concat((0, _toConsumableArray2["default"])(pendingImages), [addedImage])
205
- }, callback);
206
- },
207
- onFocus: _this.onPluginFocus,
208
- onBlur: _this.onPluginBlur,
209
- maxImageWidth: _this.props.maxImageWidth,
210
- maxImageHeight: _this.props.maxImageHeight
211
- },
212
- toolbar: {
213
- /**
214
- * To minimize converting html -> state -> html
215
- * We only emit markup once 'done' is clicked.
216
- */
217
- disableScrollbar: !!props.disableScrollbar,
218
- disableUnderline: props.disableUnderline,
219
- autoWidth: props.autoWidthToolbar,
220
- onDone: function onDone() {
221
- var _this$state$value$sta, _this$state$value$sta2;
222
-
223
- var nonEmpty = props.nonEmpty;
224
- log('[onDone]');
225
-
226
- _this.setState({
227
- toolbarInFocus: false,
228
- focusedNode: null
229
- });
230
-
231
- _this.editor.blur();
232
-
233
- 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) {
234
- _this.resetValue(true).then(function () {
235
- _this.onEditingDone();
236
- });
237
- } else {
238
- _this.onEditingDone();
239
- }
240
- }
241
- },
242
- table: {
243
- onFocus: function onFocus() {
244
- log('[table:onFocus]...');
245
-
246
- _this.onPluginFocus();
247
- },
248
- onBlur: function onBlur() {
249
- log('[table:onBlur]...');
250
-
251
- _this.onPluginBlur();
252
- }
253
- },
254
- responseArea: {
255
- type: normalizedResponseAreaProps.type,
256
- options: normalizedResponseAreaProps.options,
257
- maxResponseAreas: normalizedResponseAreaProps.maxResponseAreas,
258
- respAreaToolbar: normalizedResponseAreaProps.respAreaToolbar,
259
- onHandleAreaChange: normalizedResponseAreaProps.onHandleAreaChange,
260
- error: normalizedResponseAreaProps.error,
261
- onFocus: function onFocus() {
262
- log('[table:onFocus]...');
263
-
264
- _this.onPluginFocus();
265
- },
266
- onBlur: function onBlur() {
267
- log('[table:onBlur]...');
268
-
269
- _this.onPluginBlur();
270
- }
271
- },
272
- languageCharacters: props.languageCharactersProps,
273
- media: {
274
- focus: _this.focus,
275
- createChange: function createChange() {
276
- return _this.state.value.change();
277
- },
278
- onChange: _this.onChange,
279
- uploadSoundSupport: props.uploadSoundSupport
280
- }
281
- });
282
-
283
- if (props.mathMlOptions.mmlOutput || props.mathMlOptions.mmlEditing) {
284
- _this.props.runSerializationOnMarkup();
285
- }
286
- });
287
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "onPluginBlur", function (e) {
288
- log('[onPluginBlur]', e && e.relatedTarget);
289
- var target = e && e.relatedTarget;
290
- var node = target ? (0, _slateReact.findNode)(target, _this.state.value) : null;
291
- log('[onPluginBlur] node: ', node);
292
-
293
- _this.setState({
294
- focusedNode: node
295
- }, function () {
296
- _this.resetValue();
297
- });
298
- });
299
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "onPluginFocus", function (e) {
300
- log('[onPluginFocus]', e && e.target);
301
- var target = e && e.target;
302
-
303
- if (target) {
304
- var node = (0, _slateReact.findNode)(target, _this.state.value);
305
- log('[onPluginFocus] node: ', node);
306
- var stashedValue = _this.state.stashedValue || _this.state.value;
307
-
308
- _this.setState({
309
- focusedNode: node,
310
- stashedValue: stashedValue
311
- });
312
- } else {
313
- _this.setState({
314
- focusedNode: null
315
- });
316
- }
317
-
318
- _this.stashValue();
319
- });
320
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "onMathClick", function (node) {
321
- _this.editor.change(function (c) {
322
- return c.collapseToStartOf(node);
323
- });
324
-
325
- _this.setState({
326
- selectedNode: node
327
- });
328
- });
329
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "onEditingDone", function () {
330
- if (_this.state.isHtmlMode) {
331
- return;
332
- }
333
-
334
- var pendingImages = _this.state.pendingImages;
335
-
336
- if (pendingImages.length) {
337
- _this.setState({
338
- scheduled: true
339
- });
340
-
341
- return;
342
- }
343
-
344
- log('[onEditingDone]');
345
-
346
- _this.setState({
347
- pendingImages: [],
348
- stashedValue: null,
349
- focusedNode: null
350
- });
351
-
352
- log('[onEditingDone] value: ', _this.state.value);
353
-
354
- _this.props.onChange(_this.state.value, true);
355
- });
356
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "handleBlur", function (resolve) {
357
- var nonEmpty = _this.props.nonEmpty;
358
- var doneOn = _this.state.toolbarOpts.doneOn;
359
-
360
- _this.setState({
361
- toolbarInFocus: false,
362
- focusedNode: null
363
- });
364
-
365
- if (_this.editor) {
366
- _this.editor.blur();
367
- }
368
-
369
- if (doneOn === 'blur') {
370
- var _this$state$value$sta3, _this$state$value$sta4;
371
-
372
- 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) {
373
- _this.resetValue(true).then(function () {
374
- _this.onEditingDone();
375
-
376
- resolve();
377
- });
378
- } else {
379
- _this.onEditingDone();
380
-
381
- resolve();
382
- }
383
- }
384
- });
385
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "onBlur", function (event) {
386
- log('[onBlur]');
387
- var target = event.relatedTarget;
388
- var node = target ? (0, _slateReact.findNode)(target, _this.state.value) : null;
389
- log('[onBlur] node: ', node);
390
- return new Promise(function (resolve) {
391
- _this.setState({
392
- preBlurValue: _this.state.value,
393
- focusedNode: !node ? null : node
394
- }, _this.handleBlur.bind((0, _assertThisInitialized2["default"])(_this), resolve));
395
-
396
- _this.props.onBlur(event);
397
- });
398
- });
399
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "handleDomBlur", function (e) {
400
- var editorDOM = document.querySelector("[data-key=\"".concat(_this.state.value.document.key, "\"]"));
401
- setTimeout(function () {
402
- var stateValue = _this.state.value;
403
-
404
- if (!_this.wrapperRef) {
405
- return;
406
- }
407
-
408
- var editorElement = !editorDOM || document.activeElement.closest("[class*=\"".concat(editorDOM.className, "\"]"));
409
- var toolbarElement = !_this.toolbarRef || document.activeElement.closest("[class*=\"".concat(_this.toolbarRef.className, "\"]"));
410
-
411
- var isInCurrentComponent = _this.wrapperRef.contains(editorElement) || _this.wrapperRef.contains(toolbarElement);
412
-
413
- if (!isInCurrentComponent) {
414
- editorDOM.removeEventListener('blur', _this.handleDomBlur);
415
-
416
- if (stateValue.isFocused) {
417
- _this.onBlur(e);
418
- }
419
- }
420
- }, 50);
421
- });
422
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "onFocus", function () {
423
- return new Promise(function (resolve) {
424
- var editorDOM = document.querySelector("[data-key=\"".concat(_this.state.value.document.key, "\"]"));
425
- log('[onFocus]', document.activeElement);
426
- /**
427
- * This is a temporary hack - @see changeData below for some more information.
428
- */
429
-
430
- if (_this.__TEMPORARY_CHANGE_DATA) {
431
- var _this$__TEMPORARY_CHA = _this.__TEMPORARY_CHANGE_DATA,
432
- key = _this$__TEMPORARY_CHA.key,
433
- data = _this$__TEMPORARY_CHA.data;
434
- var domEl = document.querySelector("[data-key=\"".concat(key, "\"]"));
435
-
436
- if (domEl) {
437
- var change = _this.state.value.change().setNodeByKey(key, {
438
- data: data
439
- });
440
-
441
- _this.setState({
442
- value: change.value
443
- }, function () {
444
- _this.__TEMPORARY_CHANGE_DATA = null;
445
- });
446
- }
447
- }
448
- /**
449
- * This is needed just in case the browser decides to make the editor
450
- * lose focus without triggering the onBlur event (can happen in a few cases).
451
- * This will also trigger onBlur if the user clicks outside of the page when the editor
452
- * is focused.
453
- */
454
-
455
-
456
- if (editorDOM === document.activeElement) {
457
- editorDOM.removeEventListener('blur', _this.handleDomBlur);
458
- editorDOM.addEventListener('blur', _this.handleDomBlur);
459
- }
460
-
461
- _this.stashValue();
462
-
463
- _this.props.onFocus();
464
-
465
- resolve();
466
- });
467
- });
468
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "stashValue", function () {
469
- log('[stashValue]');
470
-
471
- if (!_this.state.stashedValue) {
472
- _this.setState({
473
- stashedValue: _this.state.value
474
- });
475
- }
476
- });
477
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "resetValue", function (force) {
478
- var _this$state = _this.state,
479
- value = _this$state.value,
480
- focusedNode = _this$state.focusedNode;
481
-
482
- var stopReset = _this.plugins.reduce(function (s, p) {
483
- return s || p.stopReset && p.stopReset(_this.state.value);
484
- }, false);
485
-
486
- log('[resetValue]', value.isFocused, focusedNode, 'stopReset: ', stopReset);
487
-
488
- if (_this.state.stashedValue && !value.isFocused && !focusedNode && !stopReset || force) {
489
- log('[resetValue] resetting...');
490
- log('stashed', _this.state.stashedValue.document.toObject());
491
- log('current', _this.state.value.document.toObject());
492
-
493
- var newValue = _slate.Value.fromJSON(_this.state.stashedValue.toJSON());
494
-
495
- log('newValue: ', newValue.document);
496
- return new Promise(function (resolve) {
497
- setTimeout(function () {
498
- _this.setState({
499
- value: newValue,
500
- stashedValue: null
501
- }, function () {
502
- log('value now: ', _this.state.value.document.toJSON());
503
- resolve();
504
- });
505
- }, 50);
506
- });
507
- } else {
508
- return Promise.resolve({});
509
- }
510
- });
511
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "onChange", function (change, done) {
512
- log('[onChange]');
513
- var value = change.value;
514
- var charactersLimit = _this.props.charactersLimit;
515
-
516
- if (value && value.document && value.document.text && value.document.text.length > charactersLimit) {
517
- return;
518
- } // Mark the editor as edited when in HTML mode and its content has changed.
519
- // This status will later be used to decide whether to prompt a warning to the user when exiting HTML mode.
520
-
521
-
522
- var isEdited = !_this.state.isHtmlMode ? false : _this.state.value.document.text !== value.document.text ? true : _this.state.isEdited;
523
-
524
- _this.setState({
525
- value: value,
526
- isEdited: isEdited
527
- }, function () {
528
- log('[onChange], call done()');
529
-
530
- if (done) {
531
- done();
532
- }
533
- });
534
- });
535
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "getFocusedValue", function () {
536
- if (_this.state.value.isFocused) {
537
- return _this.state.value;
538
- }
539
-
540
- return _this.state.preBlurValue;
541
- });
542
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "valueToSize", function (v) {
543
- if (!v) {
544
- return;
545
- }
546
-
547
- if (typeof v === 'string') {
548
- if (v.endsWith('%')) {
549
- return undefined;
550
- } else if (v.endsWith('px') || v.endsWith('vh') || v.endsWith('vw')) {
551
- return v;
552
- } else {
553
- var value = parseInt(v, 10);
554
- return isNaN(value) ? value : "".concat(value, "px");
555
- }
556
- }
557
-
558
- if (typeof v === 'number') {
559
- return "".concat(v, "px");
560
- }
561
-
562
- return;
563
- });
564
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "validateNode", function (node) {
565
- if (node.object !== 'block') return;
566
- var last = node.nodes.last();
567
- if (!last) return;
568
- if (last.type !== 'image') return;
569
- log('[validateNode] last is image..');
570
- var parent = last.getParent(last.key);
571
-
572
- var p = _slate.Block.getParent(last.key);
573
-
574
- log('[validateNode] parent:', parent, p);
575
- return undefined;
576
- });
577
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "changeData", function (key, data) {
578
- log('[changeData]. .. ', key, data);
579
- /**
580
- * HACK ALERT: We should be calling setState here and storing the change data:
581
- *
582
- * <code>this.setState({changeData: { key, data}})</code>
583
- * However this is causing issues with the Mathquill instance. The 'input' event stops firing on the element and no
584
- * more changes get through. The issues seem to be related to the promises in onBlur/onFocus. But removing these
585
- * brings it's own problems. A major clean up is planned for this component so I've decided to temporarily settle
586
- * on this hack rather than spend more time on this.
587
- */
588
- // Uncomment this line to see the bug described above.
589
- // this.setState({changeData: {key, data}})
590
-
591
- _this.__TEMPORARY_CHANGE_DATA = {
592
- key: key,
593
- data: data
594
- };
595
- });
596
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "focus", function (pos, node) {
597
- var position = pos || 'end';
598
-
599
- _this.props.focus(position, node);
600
- });
601
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "onDropPaste", /*#__PURE__*/function () {
602
- var _ref = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(event, change, dropContext) {
603
- var editor, transfer, file, type, fragment, text, src, inline, range, ch, handler, _change$value, _document, selection, startBlock, defaultBlock, defaultMarks, frag;
604
-
605
- return _regenerator["default"].wrap(function _callee$(_context) {
606
- while (1) {
607
- switch (_context.prev = _context.next) {
608
- case 0:
609
- editor = change.editor;
610
- transfer = (0, _slateReact.getEventTransfer)(event);
611
- file = transfer.files && transfer.files[0];
612
- type = transfer.type;
613
- fragment = transfer.fragment;
614
- text = transfer.text;
615
-
616
- if (!(file && (file.type === 'image/jpeg' || file.type === 'image/jpg' || file.type === 'image/png'))) {
617
- _context.next = 28;
618
- break;
619
- }
620
-
621
- if (_this.props.imageSupport) {
622
- _context.next = 9;
623
- break;
624
- }
625
-
626
- return _context.abrupt("return");
627
-
628
- case 9:
629
- _context.prev = 9;
630
- log('[onDropPaste]');
631
- _context.next = 13;
632
- return (0, serialization.getBase64)(file);
633
-
634
- case 13:
635
- src = _context.sent;
636
- inline = _slate.Inline.create({
637
- type: 'image',
638
- isVoid: true,
639
- data: {
640
- loading: false,
641
- src: src
642
- }
643
- });
644
-
645
- if (dropContext) {
646
- _this.focus();
647
- } else {
648
- range = (0, _slateReact.getEventRange)(event, editor);
649
-
650
- if (range) {
651
- change.select(range);
652
- }
653
- }
654
-
655
- ch = change.insertInline(inline);
656
-
657
- _this.onChange(ch);
658
-
659
- handler = new _insertImageHandler["default"](inline, function () {}, function () {
660
- return _this.state.value;
661
- }, _this.onChange, true);
662
- handler.fileChosen(file);
663
-
664
- _this.props.imageSupport.add(handler);
665
-
666
- _context.next = 26;
667
- break;
668
-
669
- case 23:
670
- _context.prev = 23;
671
- _context.t0 = _context["catch"](9);
672
- log('[onDropPaste] error: ', _context.t0);
673
-
674
- case 26:
675
- _context.next = 42;
676
- break;
677
-
678
- case 28:
679
- if (!(type === 'fragment')) {
680
- _context.next = 32;
681
- break;
682
- }
683
-
684
- change.insertFragment(fragment);
685
- _context.next = 42;
686
- break;
687
-
688
- case 32:
689
- if (!(type === 'text' || type === 'html')) {
690
- _context.next = 42;
691
- break;
692
- }
693
-
694
- if (text) {
695
- _context.next = 35;
696
- break;
697
- }
698
-
699
- return _context.abrupt("return");
700
-
701
- case 35:
702
- _change$value = change.value, _document = _change$value.document, selection = _change$value.selection, startBlock = _change$value.startBlock;
703
-
704
- if (!startBlock.isVoid) {
705
- _context.next = 38;
706
- break;
707
- }
708
-
709
- return _context.abrupt("return");
710
-
711
- case 38:
712
- defaultBlock = startBlock;
713
- defaultMarks = _document.getInsertMarksAtRange(selection);
714
- frag = _slatePlainSerializer["default"].deserialize(text, {
715
- defaultBlock: defaultBlock,
716
- defaultMarks: defaultMarks
717
- }).document;
718
- change.insertFragment(frag);
719
-
720
- case 42:
721
- case "end":
722
- return _context.stop();
723
- }
724
- }
725
- }, _callee, null, [[9, 23]]);
726
- }));
727
-
728
- return function (_x, _x2, _x3) {
729
- return _ref.apply(this, arguments);
730
- };
731
- }());
732
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "renderPlaceholder", function (props) {
733
- var editor = props.editor;
734
- var document = editor.value.document;
735
-
736
- if (!editor.props.placeholder || document.text !== '' || document.nodes.size !== 1) {
737
- return false;
738
- }
739
-
740
- return /*#__PURE__*/_react["default"].createElement("span", {
741
- contentEditable: false,
742
- style: {
743
- display: 'inline-block',
744
- width: 'fit-content',
745
- // for centering the placeholder if text-align is set to center
746
- maxWidth: '100%',
747
- whiteSpace: 'nowrap',
748
- opacity: '0.33',
749
- pointerEvents: 'none',
750
- userSelect: 'none'
751
- }
752
- }, editor.props.placeholder);
753
- });
754
- _this.state = {
755
- value: _props.value,
756
- toolbarOpts: createToolbarOpts(_props.toolbarOpts, _props.error),
757
- pendingImages: [],
758
- isHtmlMode: false,
759
- isEdited: false,
760
- dialog: {
761
- open: false
762
- }
763
- };
764
- _this.toggleHtmlMode = _this.toggleHtmlMode.bind((0, _assertThisInitialized2["default"])(_this));
765
-
766
- _this.onResize = function () {
767
- _props.onChange(_this.state.value, true);
768
- };
769
-
770
- _this.handlePlugins(_this.props);
771
-
772
- return _this;
773
- }
774
-
775
- (0, _createClass2["default"])(Editor, [{
776
- key: "componentDidMount",
777
- value: function componentDidMount() {
778
- var _this2 = this;
779
-
780
- // onRef is needed to get the ref of the component because we export it using withStyles
781
- this.props.onRef(this);
782
- window.addEventListener('resize', this.onResize);
783
-
784
- if (this.editor && this.props.autoFocus) {
785
- Promise.resolve().then(function () {
786
- if (_this2.editor) {
787
- var editorDOM = document.querySelector("[data-key=\"".concat(_this2.editor.value.document.key, "\"]"));
788
-
789
- _this2.editor.focus();
790
-
791
- if (editorDOM) {
792
- editorDOM.focus();
793
- }
794
- }
795
- });
796
- }
797
- }
798
- }, {
799
- key: "UNSAFE_componentWillReceiveProps",
800
- value: function UNSAFE_componentWillReceiveProps(nextProps) {
801
- var _nextProps$value, _nextProps$value$docu, _this$props$value;
802
-
803
- var _this$state2 = this.state,
804
- isHtmlMode = _this$state2.isHtmlMode,
805
- toolbarOpts = _this$state2.toolbarOpts;
806
- var newToolbarOpts = createToolbarOpts(nextProps.toolbarOpts, nextProps.error, isHtmlMode);
807
-
808
- if (!(0, _isEqual["default"])(newToolbarOpts, toolbarOpts)) {
809
- this.setState({
810
- toolbarOpts: newToolbarOpts
811
- });
812
- }
813
-
814
- var differentCharacterProps = !(0, _isEqual["default"])(nextProps.languageCharactersProps, this.props.languageCharactersProps);
815
- var differentMathMlProps = !(0, _isEqual["default"])(nextProps.mathMlOptions, this.props.mathMlOptions);
816
-
817
- if (differentCharacterProps || differentMathMlProps) {
818
- this.handlePlugins(nextProps);
819
- }
820
-
821
- if (!((_nextProps$value = nextProps.value) !== null && _nextProps$value !== void 0 && (_nextProps$value$docu = _nextProps$value.document) !== null && _nextProps$value$docu !== void 0 && _nextProps$value$docu.equals((_this$props$value = this.props.value) === null || _this$props$value === void 0 ? void 0 : _this$props$value.document))) {
822
- this.setState({
823
- focus: false,
824
- value: nextProps.value
825
- });
826
- }
827
- }
828
- }, {
829
- key: "componentDidUpdate",
830
- value: function componentDidUpdate(prevProps, prevState) {
831
- // The cursor is on a zero width element and when that is placed near void elements, it is not visible
832
- // so we increase the width to at least 2px in order for the user to see it
833
- // Trigger plugins and finish editing if:
834
- // 1. The 'isHtmlMode' state has been toggled.
835
- // 2. We're currently in 'isHtmlMode' and the editor value has been modified.
836
- if (this.state.isHtmlMode !== prevState.isHtmlMode || this.state.isHtmlMode && !prevState.isEdited && this.state.isEdited) {
837
- this.handlePlugins(this.props);
838
- this.onEditingDone();
839
- }
840
-
841
- var zeroWidthEls = document.querySelectorAll('[data-slate-zero-width="z"]');
842
- Array.from(zeroWidthEls).forEach(function (el) {
843
- el.style.minWidth = '2px';
844
- el.style.display = 'inline-block';
845
- });
846
- }
847
- }, {
848
- key: "componentWillUnmount",
849
- value:
850
- /**
851
- * Remove onResize event listener
852
- */
853
- function componentWillUnmount() {
854
- window.removeEventListener('resize', this.onResize);
855
- } // Allowing time for onChange to take effect if it is called
856
-
857
- }, {
858
- key: "buildSizeStyle",
859
- value: function buildSizeStyle() {
860
- var _this$props = this.props,
861
- width = _this$props.width,
862
- minHeight = _this$props.minHeight,
863
- height = _this$props.height,
864
- maxHeight = _this$props.maxHeight;
865
- return {
866
- width: this.valueToSize(width),
867
- height: this.valueToSize(height),
868
- minHeight: this.valueToSize(minHeight),
869
- maxHeight: this.valueToSize(maxHeight)
870
- };
871
- }
872
- }, {
873
- key: "render",
874
- value: function render() {
875
- var _classNames,
876
- _this3 = this;
877
-
878
- var _this$props2 = this.props,
879
- disabled = _this$props2.disabled,
880
- spellCheck = _this$props2.spellCheck,
881
- highlightShape = _this$props2.highlightShape,
882
- classes = _this$props2.classes,
883
- className = _this$props2.className,
884
- placeholder = _this$props2.placeholder,
885
- pluginProps = _this$props2.pluginProps,
886
- onKeyDown = _this$props2.onKeyDown;
887
- var _this$state3 = this.state,
888
- value = _this$state3.value,
889
- focusedNode = _this$state3.focusedNode,
890
- toolbarOpts = _this$state3.toolbarOpts,
891
- dialog = _this$state3.dialog,
892
- scheduled = _this$state3.scheduled;
893
- log('[render] value: ', value);
894
- var sizeStyle = this.buildSizeStyle();
895
- var names = (0, _classnames["default"])((_classNames = {}, (0, _defineProperty2["default"])(_classNames, classes.withBg, highlightShape), (0, _defineProperty2["default"])(_classNames, classes.toolbarOnTop, toolbarOpts.alwaysVisible && toolbarOpts.position === 'top'), (0, _defineProperty2["default"])(_classNames, classes.scheduled, scheduled), _classNames), className);
896
- return /*#__PURE__*/_react["default"].createElement("div", {
897
- ref: function ref(_ref2) {
898
- return _this3.wrapperRef = _ref2;
899
- },
900
- style: {
901
- width: sizeStyle.width
902
- },
903
- className: names
904
- }, scheduled && /*#__PURE__*/_react["default"].createElement("div", {
905
- className: classes.uploading
906
- }, "Uploading image and then saving..."), /*#__PURE__*/_react["default"].createElement(_slateReact.Editor, {
907
- plugins: this.plugins,
908
- innerRef: function innerRef(r) {
909
- if (r) {
910
- _this3.slateEditor = r;
911
- }
912
- },
913
- ref: function ref(r) {
914
- return _this3.editor = r && _this3.props.editorRef(r);
915
- },
916
- toolbarRef: function toolbarRef(r) {
917
- if (r) {
918
- _this3.toolbarRef = r;
919
- }
920
- },
921
- value: value,
922
- focus: this.focus,
923
- onKeyDown: onKeyDown,
924
- onChange: this.onChange,
925
- getFocusedValue: this.getFocusedValue,
926
- onBlur: this.onBlur,
927
- onDrop: function onDrop(event, editor) {
928
- return _this3.onDropPaste(event, editor, true);
929
- },
930
- onPaste: function onPaste(event, editor) {
931
- return _this3.onDropPaste(event, editor);
932
- },
933
- onFocus: this.onFocus,
934
- onEditingDone: this.onEditingDone,
935
- focusedNode: focusedNode,
936
- normalize: this.normalize,
937
- readOnly: disabled,
938
- spellCheck: spellCheck,
939
- autoCorrect: spellCheck,
940
- className: (0, _classnames["default"])((0, _defineProperty2["default"])({}, classes.noPadding, toolbarOpts && toolbarOpts.noBorder), classes.slateEditor),
941
- style: {
942
- minHeight: sizeStyle.minHeight,
943
- height: sizeStyle.height,
944
- maxHeight: sizeStyle.maxHeight
945
- },
946
- pluginProps: pluginProps,
947
- toolbarOpts: toolbarOpts,
948
- placeholder: placeholder,
949
- renderPlaceholder: this.renderPlaceholder,
950
- onDataChange: this.changeData
951
- }), /*#__PURE__*/_react["default"].createElement(_configUi.AlertDialog, {
952
- open: dialog.open,
953
- title: dialog.title,
954
- text: dialog.text,
955
- onClose: dialog.onClose,
956
- onConfirm: dialog.onConfirm
957
- }));
958
- }
959
- }]);
960
- return Editor;
961
- }(_react["default"].Component); // TODO color - hardcoded gray background and keypad colors will need to change too
962
-
963
-
964
- exports.Editor = Editor;
965
- (0, _defineProperty2["default"])(Editor, "propTypes", {
966
- autoFocus: _propTypes["default"].bool,
967
- editorRef: _propTypes["default"].func.isRequired,
968
- error: _propTypes["default"].any,
969
- onRef: _propTypes["default"].func.isRequired,
970
- onChange: _propTypes["default"].func.isRequired,
971
- onFocus: _propTypes["default"].func,
972
- onBlur: _propTypes["default"].func,
973
- onKeyDown: _propTypes["default"].func,
974
- focus: _propTypes["default"].func.isRequired,
975
- value: _slatePropTypes["default"].value.isRequired,
976
- imageSupport: _propTypes["default"].object,
977
- mathMlOptions: _propTypes["default"].shape({
978
- mmlOutput: _propTypes["default"].bool,
979
- mmlEditing: _propTypes["default"].bool
980
- }),
981
- disableImageAlignmentButtons: _propTypes["default"].bool,
982
- uploadSoundSupport: _propTypes["default"].shape({
983
- add: _propTypes["default"].func,
984
- "delete": _propTypes["default"].func
985
- }),
986
- charactersLimit: _propTypes["default"].number,
987
- width: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].number]),
988
- height: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].number]),
989
- minHeight: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].number]),
990
- maxHeight: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].number]),
991
- classes: _propTypes["default"].object.isRequired,
992
- highlightShape: _propTypes["default"].bool,
993
- disabled: _propTypes["default"].bool,
994
- spellCheck: _propTypes["default"].bool,
995
- nonEmpty: _propTypes["default"].bool,
996
- disableScrollbar: _propTypes["default"].bool,
997
- disableUnderline: _propTypes["default"].bool,
998
- autoWidthToolbar: _propTypes["default"].bool,
999
- pluginProps: _propTypes["default"].any,
1000
- placeholder: _propTypes["default"].string,
1001
- responseAreaProps: _propTypes["default"].shape({
1002
- type: _propTypes["default"].oneOf(['explicit-constructed-response', 'inline-dropdown', 'drag-in-the-blank']),
1003
- options: _propTypes["default"].object,
1004
- respAreaToolbar: _propTypes["default"].func,
1005
- onHandleAreaChange: _propTypes["default"].func
1006
- }),
1007
- languageCharactersProps: _propTypes["default"].arrayOf(_propTypes["default"].shape({
1008
- language: _propTypes["default"].string,
1009
- characterIcon: _propTypes["default"].string,
1010
- characters: _propTypes["default"].arrayOf(_propTypes["default"].arrayOf(_propTypes["default"].string))
1011
- })),
1012
- runSerializationOnMarkup: _propTypes["default"].func,
1013
- toolbarOpts: _propTypes["default"].shape({
1014
- position: _propTypes["default"].oneOf(['bottom', 'top']),
1015
- alignment: _propTypes["default"].oneOf(['left', 'right']),
1016
- alwaysVisible: _propTypes["default"].bool,
1017
- showDone: _propTypes["default"].bool,
1018
- doneOn: _propTypes["default"].string
1019
- }),
1020
- activePlugins: _propTypes["default"].arrayOf(function (values) {
1021
- var allValid = values.every(function (v) {
1022
- return _plugins.ALL_PLUGINS.includes(v);
1023
- });
1024
- return !allValid && new Error("Invalid values: ".concat(values, ", values must be one of [").concat(_plugins.ALL_PLUGINS.join(','), "]"));
1025
- }),
1026
- className: _propTypes["default"].string,
1027
- maxImageWidth: _propTypes["default"].number,
1028
- maxImageHeight: _propTypes["default"].number
1029
- });
1030
- (0, _defineProperty2["default"])(Editor, "defaultProps", {
1031
- disableUnderline: true,
1032
- onFocus: function onFocus() {},
1033
- onBlur: function onBlur() {},
1034
- onKeyDown: function onKeyDown() {},
1035
- runSerializationOnMarkup: function runSerializationOnMarkup() {},
1036
- mathMlOptions: {
1037
- mmlOutput: false,
1038
- mmlEditing: false
1039
- },
1040
- toolbarOpts: defaultToolbarOpts,
1041
- responseAreaProps: defaultResponseAreaProps,
1042
- languageCharactersProps: defaultLanguageCharactersProps
1043
- });
1044
- var styles = {
1045
- withBg: {
1046
- backgroundColor: 'rgba(0,0,0,0.06)'
1047
- },
1048
- scheduled: {
1049
- opacity: 0.5,
1050
- pointerEvents: 'none',
1051
- position: 'relative'
1052
- },
1053
- uploading: {
1054
- position: 'absolute',
1055
- top: '50%',
1056
- left: '50%',
1057
- transform: 'translate(-50%, -50%)'
1058
- },
1059
- slateEditor: {
1060
- fontFamily: 'Roboto, sans-serif',
1061
- '& table': {
1062
- tableLayout: 'fixed',
1063
- width: '100%',
1064
- borderCollapse: 'collapse',
1065
- color: _renderUi.color.text(),
1066
- backgroundColor: _renderUi.color.background()
1067
- },
1068
- '& table:not([border="1"]) tr': {
1069
- borderTop: '1px solid #dfe2e5' // TODO perhaps secondary color for background, for now disable
1070
- // '&:nth-child(2n)': {
1071
- // backgroundColor: '#f6f8fa'
1072
- // }
1073
-
1074
- },
1075
- '& td, th': {
1076
- padding: '.6em 1em',
1077
- textAlign: 'center'
1078
- },
1079
- '& table:not([border="1"]) td, th': {
1080
- border: '1px solid #dfe2e5'
1081
- }
1082
- },
1083
- toolbarOnTop: {
1084
- marginTop: '45px'
1085
- },
1086
- noPadding: {
1087
- padding: '0 !important'
1088
- }
1089
- };
1090
-
1091
- var _default = (0, _styles.withStyles)(styles)(Editor);
1092
-
1093
- exports["default"] = _default;
1094
- //# sourceMappingURL=editor.js.map