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