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