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