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