@pie-lib/editable-html 11.21.2 → 11.21.3-next.155

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (159) hide show
  1. package/CHANGELOG.md +6 -76
  2. package/esm/package.json +3 -0
  3. package/lib/block-tags.js +2 -3
  4. package/lib/block-tags.js.map +1 -1
  5. package/lib/constants.js +3 -6
  6. package/lib/constants.js.map +1 -1
  7. package/lib/editor.js +350 -481
  8. package/lib/editor.js.map +1 -1
  9. package/lib/index.js +18 -79
  10. package/lib/index.js.map +1 -1
  11. package/lib/parse-html.js +7 -7
  12. package/lib/parse-html.js.map +1 -1
  13. package/lib/plugins/characters/custom-popper.js +28 -44
  14. package/lib/plugins/characters/custom-popper.js.map +1 -1
  15. package/lib/plugins/characters/index.js +23 -63
  16. package/lib/plugins/characters/index.js.map +1 -1
  17. package/lib/plugins/characters/utils.js +3 -6
  18. package/lib/plugins/characters/utils.js.map +1 -1
  19. package/lib/plugins/css/icons/index.js +13 -25
  20. package/lib/plugins/css/icons/index.js.map +1 -1
  21. package/lib/plugins/css/index.js +34 -93
  22. package/lib/plugins/css/index.js.map +1 -1
  23. package/lib/plugins/customPlugin/index.js +10 -26
  24. package/lib/plugins/customPlugin/index.js.map +1 -1
  25. package/lib/plugins/html/icons/index.js +17 -25
  26. package/lib/plugins/html/icons/index.js.map +1 -1
  27. package/lib/plugins/html/index.js +4 -13
  28. package/lib/plugins/html/index.js.map +1 -1
  29. package/lib/plugins/image/alt-dialog.js +20 -49
  30. package/lib/plugins/image/alt-dialog.js.map +1 -1
  31. package/lib/plugins/image/component.js +118 -194
  32. package/lib/plugins/image/component.js.map +1 -1
  33. package/lib/plugins/image/image-toolbar.js +48 -88
  34. package/lib/plugins/image/image-toolbar.js.map +1 -1
  35. package/lib/plugins/image/index.js +6 -46
  36. package/lib/plugins/image/index.js.map +1 -1
  37. package/lib/plugins/image/insert-image-handler.js +10 -31
  38. package/lib/plugins/image/insert-image-handler.js.map +1 -1
  39. package/lib/plugins/index.js +46 -106
  40. package/lib/plugins/index.js.map +1 -1
  41. package/lib/plugins/list/index.js +27 -73
  42. package/lib/plugins/list/index.js.map +1 -1
  43. package/lib/plugins/math/index.js +64 -116
  44. package/lib/plugins/math/index.js.map +1 -1
  45. package/lib/plugins/media/index.js +27 -84
  46. package/lib/plugins/media/index.js.map +1 -1
  47. package/lib/plugins/media/media-dialog.js +192 -307
  48. package/lib/plugins/media/media-dialog.js.map +1 -1
  49. package/lib/plugins/media/media-toolbar.js +40 -65
  50. package/lib/plugins/media/media-toolbar.js.map +1 -1
  51. package/lib/plugins/media/media-wrapper.js +20 -49
  52. package/lib/plugins/media/media-wrapper.js.map +1 -1
  53. package/lib/plugins/rendering/index.js +5 -15
  54. package/lib/plugins/rendering/index.js.map +1 -1
  55. package/lib/plugins/respArea/drag-in-the-blank/choice.js +233 -251
  56. package/lib/plugins/respArea/drag-in-the-blank/choice.js.map +1 -1
  57. package/lib/plugins/respArea/drag-in-the-blank/index.js +17 -59
  58. package/lib/plugins/respArea/drag-in-the-blank/index.js.map +1 -1
  59. package/lib/plugins/respArea/drag-in-the-blank/utils.js +38 -0
  60. package/lib/plugins/respArea/drag-in-the-blank/utils.js.map +1 -0
  61. package/lib/plugins/respArea/explicit-constructed-response/index.js +3 -10
  62. package/lib/plugins/respArea/explicit-constructed-response/index.js.map +1 -1
  63. package/lib/plugins/respArea/icons/index.js +22 -45
  64. package/lib/plugins/respArea/icons/index.js.map +1 -1
  65. package/lib/plugins/respArea/index.js +5 -59
  66. package/lib/plugins/respArea/index.js.map +1 -1
  67. package/lib/plugins/respArea/inline-dropdown/index.js +2 -10
  68. package/lib/plugins/respArea/inline-dropdown/index.js.map +1 -1
  69. package/lib/plugins/respArea/math-templated/index.js +91 -109
  70. package/lib/plugins/respArea/math-templated/index.js.map +1 -1
  71. package/lib/plugins/respArea/utils.js +12 -42
  72. package/lib/plugins/respArea/utils.js.map +1 -1
  73. package/lib/plugins/table/CustomTablePlugin.js +24 -41
  74. package/lib/plugins/table/CustomTablePlugin.js.map +1 -1
  75. package/lib/plugins/table/icons/index.js +21 -35
  76. package/lib/plugins/table/icons/index.js.map +1 -1
  77. package/lib/plugins/table/index.js +48 -118
  78. package/lib/plugins/table/index.js.map +1 -1
  79. package/lib/plugins/table/table-toolbar.js +37 -86
  80. package/lib/plugins/table/table-toolbar.js.map +1 -1
  81. package/lib/plugins/textAlign/icons/index.js +25 -64
  82. package/lib/plugins/textAlign/icons/index.js.map +1 -1
  83. package/lib/plugins/textAlign/index.js +0 -8
  84. package/lib/plugins/textAlign/index.js.map +1 -1
  85. package/lib/plugins/toolbar/default-toolbar.js +30 -79
  86. package/lib/plugins/toolbar/default-toolbar.js.map +1 -1
  87. package/lib/plugins/toolbar/done-button.js +16 -34
  88. package/lib/plugins/toolbar/done-button.js.map +1 -1
  89. package/lib/plugins/toolbar/editor-and-toolbar.js +174 -202
  90. package/lib/plugins/toolbar/editor-and-toolbar.js.map +1 -1
  91. package/lib/plugins/toolbar/index.js +0 -5
  92. package/lib/plugins/toolbar/index.js.map +1 -1
  93. package/lib/plugins/toolbar/toolbar-buttons.js +59 -108
  94. package/lib/plugins/toolbar/toolbar-buttons.js.map +1 -1
  95. package/lib/plugins/toolbar/toolbar.js +93 -162
  96. package/lib/plugins/toolbar/toolbar.js.map +1 -1
  97. package/lib/plugins/utils.js +5 -25
  98. package/lib/plugins/utils.js.map +1 -1
  99. package/lib/serialization.js +47 -153
  100. package/lib/serialization.js.map +1 -1
  101. package/lib/shared/alert-dialog.js +35 -42
  102. package/lib/theme.js +1 -2
  103. package/lib/theme.js.map +1 -1
  104. package/package.json +26 -14
  105. package/src/__tests__/editor-utils.test.js +162 -0
  106. package/src/__tests__/utils.js +1 -1
  107. package/src/editor.jsx +175 -153
  108. package/src/index.jsx +0 -3
  109. package/src/plugins/characters/custom-popper.js +25 -25
  110. package/src/plugins/characters/index.jsx +15 -5
  111. package/src/plugins/css/icons/index.jsx +11 -13
  112. package/src/plugins/css/index.jsx +16 -11
  113. package/src/plugins/html/icons/index.jsx +17 -14
  114. package/src/plugins/image/__tests__/component.test.jsx +61 -29
  115. package/src/plugins/image/__tests__/image-toolbar-logic.test.jsx +69 -17
  116. package/src/plugins/image/__tests__/image-toolbar.test.jsx +6 -4
  117. package/src/plugins/image/alt-dialog.jsx +9 -8
  118. package/src/plugins/image/component.jsx +68 -92
  119. package/src/plugins/image/image-toolbar.jsx +31 -28
  120. package/src/plugins/image/index.jsx +1 -1
  121. package/src/plugins/index.jsx +12 -10
  122. package/src/plugins/math/__tests__/index.test.jsx +45 -26
  123. package/src/plugins/math/index.jsx +1 -1
  124. package/src/plugins/media/index.jsx +6 -5
  125. package/src/plugins/media/media-dialog.js +65 -76
  126. package/src/plugins/media/media-toolbar.jsx +32 -33
  127. package/src/plugins/media/media-wrapper.jsx +10 -13
  128. package/src/plugins/respArea/drag-in-the-blank/choice.jsx +240 -167
  129. package/src/plugins/respArea/drag-in-the-blank/index.jsx +27 -56
  130. package/src/plugins/respArea/drag-in-the-blank/utils.js +14 -0
  131. package/src/plugins/respArea/icons/index.jsx +16 -16
  132. package/src/plugins/respArea/math-templated/index.jsx +88 -89
  133. package/src/plugins/respArea/utils.jsx +5 -3
  134. package/src/plugins/table/__tests__/table-toolbar.test.jsx +40 -7
  135. package/src/plugins/table/icons/index.jsx +16 -16
  136. package/src/plugins/table/index.jsx +35 -19
  137. package/src/plugins/table/table-toolbar.jsx +18 -19
  138. package/src/plugins/textAlign/icons/index.jsx +13 -4
  139. package/src/plugins/textAlign/index.jsx +0 -3
  140. package/src/plugins/toolbar/__tests__/default-toolbar.test.jsx +102 -69
  141. package/src/plugins/toolbar/__tests__/editor-and-toolbar.test.jsx +14 -11
  142. package/src/plugins/toolbar/__tests__/toolbar-buttons.test.jsx +81 -35
  143. package/src/plugins/toolbar/__tests__/toolbar.test.jsx +44 -38
  144. package/src/plugins/toolbar/default-toolbar.jsx +18 -21
  145. package/src/plugins/toolbar/done-button.jsx +16 -22
  146. package/src/plugins/toolbar/editor-and-toolbar.jsx +134 -158
  147. package/src/plugins/toolbar/toolbar-buttons.jsx +30 -46
  148. package/src/plugins/toolbar/toolbar.jsx +57 -79
  149. package/src/serialization.jsx +3 -3
  150. package/src/__tests__/editor.test.jsx +0 -363
  151. package/src/plugins/image/__tests__/__snapshots__/component.test.jsx.snap +0 -51
  152. package/src/plugins/image/__tests__/__snapshots__/image-toolbar-logic.test.jsx.snap +0 -27
  153. package/src/plugins/image/__tests__/__snapshots__/image-toolbar.test.jsx.snap +0 -44
  154. package/src/plugins/math/__tests__/__snapshots__/index.test.jsx.snap +0 -48
  155. package/src/plugins/table/__tests__/__snapshots__/table-toolbar.test.jsx.snap +0 -44
  156. package/src/plugins/toolbar/__tests__/__snapshots__/default-toolbar.test.jsx.snap +0 -923
  157. package/src/plugins/toolbar/__tests__/__snapshots__/editor-and-toolbar.test.jsx.snap +0 -20
  158. package/src/plugins/toolbar/__tests__/__snapshots__/toolbar-buttons.test.jsx.snap +0 -36
  159. package/src/plugins/toolbar/__tests__/__snapshots__/toolbar.test.jsx.snap +0 -46
@@ -1,45 +1,28 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.valueToHtml = exports.reduceMultipleBrs = exports.reactAttributes = exports.parseStyleString = exports.htmlToValue = exports.handleHtml = exports.getBase64 = exports.extraCSSRulesOpts = exports.TEXT_RULE = exports.INLINE_TAGS = void 0;
9
-
10
8
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
-
12
9
  var _slateHtmlSerializer = _interopRequireDefault(require("slate-html-serializer"));
13
-
14
10
  var _react = _interopRequireDefault(require("react"));
15
-
16
11
  var _debug = _interopRequireDefault(require("debug"));
17
-
18
12
  var _toStyle = require("to-style");
19
-
20
13
  var _isEmpty = _interopRequireDefault(require("lodash/isEmpty"));
21
-
22
14
  var _image = require("./plugins/image");
23
-
24
15
  var _math = require("./plugins/math");
25
-
26
16
  var _media = require("./plugins/media");
27
-
28
17
  var _list = require("./plugins/list");
29
-
30
18
  var _table = require("./plugins/table");
31
-
32
19
  var _respArea = require("./plugins/respArea");
33
-
34
20
  var _slate = require("slate");
35
-
36
21
  var _blockTags = require("./block-tags");
37
-
38
- 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; }
39
-
40
- 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; }
41
-
22
+ 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; }
23
+ 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; }
42
24
  var log = (0, _debug["default"])('@pie-lib:editable-html:serialization');
25
+
43
26
  /**
44
27
  * Tags to marks.
45
28
  *
@@ -58,51 +41,36 @@ var MARK_TAGS = {
58
41
  sup: 'sup',
59
42
  sub: 'sub'
60
43
  };
61
-
62
- var parseStyleString = function parseStyleString(s) {
44
+ var parseStyleString = exports.parseStyleString = function parseStyleString(s) {
63
45
  var regex = /([\w-]*)\s*:\s*([^;]*)/g;
64
46
  var match;
65
47
  var result = {};
66
-
67
48
  while (match = regex.exec(s)) {
68
49
  result[match[1]] = match[2].trim();
69
50
  }
70
-
71
51
  return result;
72
52
  };
73
-
74
- exports.parseStyleString = parseStyleString;
75
-
76
- var getBase64 = function getBase64(file) {
53
+ var getBase64 = exports.getBase64 = function getBase64(file) {
77
54
  return new Promise(function (resolve, reject) {
78
55
  var reader = new FileReader();
79
56
  reader.readAsDataURL(file);
80
-
81
57
  reader.onload = function () {
82
58
  return resolve(reader.result);
83
59
  };
84
-
85
60
  reader.onerror = function (error) {
86
61
  return reject(error);
87
62
  };
88
63
  });
89
64
  };
90
-
91
- exports.getBase64 = getBase64;
92
-
93
- var reactAttributes = function reactAttributes(o) {
65
+ var reactAttributes = exports.reactAttributes = function reactAttributes(o) {
94
66
  return (0, _toStyle.object)(o, {
95
67
  camelize: true,
96
68
  addUnits: false
97
69
  });
98
70
  };
99
-
100
- exports.reactAttributes = reactAttributes;
101
-
102
71
  var attributesToMap = function attributesToMap(el) {
103
72
  return function (acc, attribute) {
104
73
  var value = el.getAttribute(attribute);
105
-
106
74
  if (value) {
107
75
  if (attribute === 'style') {
108
76
  var styleString = el.getAttribute(attribute);
@@ -112,12 +80,11 @@ var attributesToMap = function attributesToMap(el) {
112
80
  acc[attribute] = el.getAttribute(attribute);
113
81
  }
114
82
  }
115
-
116
83
  return acc;
117
84
  };
118
85
  };
119
-
120
86
  var attributes = ['border', 'cellpadding', 'cellspacing', 'class', 'style', 'align'];
87
+
121
88
  /**
122
89
  * Serializer rules.
123
90
  *
@@ -127,25 +94,19 @@ var attributes = ['border', 'cellpadding', 'cellspacing', 'class', 'style', 'ali
127
94
  var blocks = {
128
95
  deserialize: function deserialize(el, next) {
129
96
  log('[blocks:deserialize] block: ', el);
130
-
131
97
  var block = _blockTags.BLOCK_TAGS[el.tagName.toLowerCase()];
132
-
133
98
  if (!block) return;
134
99
  log('[blocks:deserialize] block: ', block);
135
-
136
100
  if (el.childNodes.length === 1) {
137
101
  var cn = el.childNodes[0];
138
-
139
102
  if (cn && cn.tagName && cn.tagName.toLowerCase() === block) {
140
103
  log('[we have a child node of the same]...');
141
104
  return;
142
105
  }
143
106
  }
144
-
145
107
  return {
146
108
  object: 'block',
147
109
  type: block,
148
-
149
110
  /**
150
111
  * Here for rendering styles for all block elements
151
112
  */
@@ -160,7 +121,6 @@ var blocks = {
160
121
  var jsonData = object.data.toJSON();
161
122
  log('[blocks:serialize] object: ', object, children);
162
123
  var key;
163
-
164
124
  for (key in _blockTags.BLOCK_TAGS) {
165
125
  if (_blockTags.BLOCK_TAGS[key] === object.type) {
166
126
  var Tag = key;
@@ -169,30 +129,25 @@ var blocks = {
169
129
  }
170
130
  }
171
131
  };
172
- var INLINE_TAGS = {
132
+ var INLINE_TAGS = exports.INLINE_TAGS = {
173
133
  span: 'span'
174
134
  };
175
- exports.INLINE_TAGS = INLINE_TAGS;
176
135
  var inlines = {
177
136
  deserialize: function deserialize(el, next) {
178
137
  log('[inlines:deserialize] inline: ', el);
179
138
  var inlineTag = INLINE_TAGS[el.tagName.toLowerCase()];
180
139
  if (!inlineTag) return;
181
140
  log('[inlines:deserialize] inline: ', inlineTag);
182
-
183
141
  if (el.childNodes.length === 1) {
184
142
  var cn = el.childNodes[0];
185
-
186
143
  if (cn && cn.tagName && cn.tagName.toLowerCase() === inlineTag) {
187
144
  log('[we have a child node of the same]...');
188
145
  return;
189
146
  }
190
147
  }
191
-
192
148
  return {
193
149
  object: 'inline',
194
150
  type: inlineTag,
195
-
196
151
  /**
197
152
  * Here for rendering styles for all inline elements
198
153
  */
@@ -207,7 +162,6 @@ var inlines = {
207
162
  var jsonData = object.data.toJSON();
208
163
  log('[inlines:serialize] object: ', object, children);
209
164
  var key;
210
-
211
165
  for (key in INLINE_TAGS) {
212
166
  if (INLINE_TAGS[key] === object.type) {
213
167
  var Tag = key;
@@ -216,8 +170,7 @@ var inlines = {
216
170
  }
217
171
  }
218
172
  };
219
- var extraCSSRulesOpts = {};
220
- exports.extraCSSRulesOpts = extraCSSRulesOpts;
173
+ var extraCSSRulesOpts = exports.extraCSSRulesOpts = {};
221
174
  var STYLES_MAP = {
222
175
  h3: {
223
176
  fontSize: 'inherit',
@@ -240,11 +193,9 @@ var marks = {
240
193
  var hasCSSRule = ((extraCSSRulesOpts === null || extraCSSRulesOpts === void 0 ? void 0 : extraCSSRulesOpts.names) || []).find(function (name) {
241
194
  return elClasses === null || elClasses === void 0 ? void 0 : elClasses.includes(name);
242
195
  });
243
-
244
196
  if (!mark && !hasCSSRule) {
245
197
  return;
246
198
  }
247
-
248
199
  log('[deserialize] mark: ', mark);
249
200
  var attrs = attributes.reduce(attributesToMap(el), {});
250
201
  var data = (0, _isEmpty["default"])(attrs) ? undefined : {
@@ -253,7 +204,6 @@ var marks = {
253
204
  return {
254
205
  object: 'mark',
255
206
  type: hasCSSRule ? 'css' : mark,
256
-
257
207
  /**
258
208
  * Here for rendering styles for all elements
259
209
  */
@@ -263,13 +213,11 @@ var marks = {
263
213
  },
264
214
  serialize: function serialize(object, children) {
265
215
  var _object$data, _jsonData$attributes;
266
-
267
216
  var jsonData = ((_object$data = object.data) === null || _object$data === void 0 ? void 0 : _object$data.toJSON()) || {};
268
217
  var elClasses = ((_jsonData$attributes = jsonData.attributes) === null || _jsonData$attributes === void 0 ? void 0 : _jsonData$attributes["class"]) || '';
269
218
  var hasCSSRule = ((extraCSSRulesOpts === null || extraCSSRulesOpts === void 0 ? void 0 : extraCSSRulesOpts.names) || []).find(function (name) {
270
219
  return elClasses === null || elClasses === void 0 ? void 0 : elClasses.includes(name);
271
220
  });
272
-
273
221
  if (hasCSSRule) {
274
222
  var htmlAttrs = Object.keys(jsonData.attributes).reduce(function (obj, key) {
275
223
  obj[reactToHTMLAttributesMap[key] || key] = jsonData.attributes[key];
@@ -277,47 +225,40 @@ var marks = {
277
225
  }, {});
278
226
  return /*#__PURE__*/_react["default"].createElement("span", htmlAttrs, children);
279
227
  }
280
-
281
228
  if (_slate.Mark.isMark(object)) {
282
229
  for (var key in MARK_TAGS) {
283
230
  if (MARK_TAGS[key] === object.type) {
284
231
  var Tag = key;
285
232
  var additionalStyles = STYLES_MAP[Tag];
286
-
287
233
  if (additionalStyles) {
288
234
  if (!jsonData.attributes) {
289
235
  jsonData.attributes = {};
290
236
  }
291
-
292
237
  jsonData.attributes.style = _objectSpread(_objectSpread({}, jsonData.attributes.style), additionalStyles);
293
238
  }
294
-
295
239
  return /*#__PURE__*/_react["default"].createElement(Tag, jsonData.attributes, children);
296
240
  }
297
241
  }
298
242
  }
299
243
  }
300
- }; // eslint-disable-next-line no-unused-vars
244
+ };
301
245
 
302
- var findPreviousText = function findPreviousText(el) {
246
+ // eslint-disable-next-line no-unused-vars
247
+ var _findPreviousText = function findPreviousText(el) {
303
248
  if (el.nodeName === '#text') {
304
249
  return el;
305
250
  }
306
-
307
251
  if (el.previousSibling) {
308
- return findPreviousText(el.previousSibling);
252
+ return _findPreviousText(el.previousSibling);
309
253
  }
310
-
311
254
  return null;
312
255
  };
313
-
314
- var TEXT_RULE = {
256
+ var TEXT_RULE = exports.TEXT_RULE = {
315
257
  deserialize: function deserialize(el) {
316
258
  /**
317
259
  * This needs to be called on the dom element in order to merge the adjacent text nodes together
318
260
  * */
319
261
  el.normalize();
320
-
321
262
  if (el.tagName && el.tagName.toLowerCase() === 'br') {
322
263
  return {
323
264
  object: 'text',
@@ -327,7 +268,6 @@ var TEXT_RULE = {
327
268
  }]
328
269
  };
329
270
  }
330
-
331
271
  if (el.nodeName === '#text') {
332
272
  if (el.nodeValue && el.nodeValue.match(/<!--.*?-->/)) return;
333
273
  log('[text:deserialize] return text object..');
@@ -343,49 +283,39 @@ var TEXT_RULE = {
343
283
  serialize: function serialize(obj, children) {
344
284
  if (obj.object === 'string') {
345
285
  return children.split('\n').reduce(function (array, text, i) {
346
- if (i !== 0) array.push( /*#__PURE__*/_react["default"].createElement("br", null));
286
+ if (i !== 0) array.push(/*#__PURE__*/_react["default"].createElement("br", null));
347
287
  array.push(text);
348
288
  return array;
349
289
  }, []);
350
290
  }
351
291
  }
352
292
  };
353
- exports.TEXT_RULE = TEXT_RULE;
354
293
  var RULES = [_list.serialization, _math.serialization, _media.serialization, _image.serialization, _table.serialization, _respArea.serialization, TEXT_RULE, inlines, blocks, marks];
355
-
356
294
  function allWhitespace(node) {
357
295
  // Use ECMA-262 Edition 3 String and RegExp features
358
296
  return !/[^\t\n\r ]/.test(node.textContent);
359
297
  }
360
-
361
298
  function defaultParseHtml(html) {
362
299
  if (typeof DOMParser === 'undefined') {
363
300
  throw new Error('The native `DOMParser` global which the `Html` serializer uses by default is not present in this environment. You must supply the `options.parseHtml` function instead.');
364
301
  }
365
-
366
302
  var parsed = new DOMParser().parseFromString(html, 'text/html');
367
303
  var body = parsed.body;
368
304
  var textNodes = document.createTreeWalker(body, NodeFilter.SHOW_TEXT, null, null);
369
305
  var n = textNodes.nextNode();
370
-
371
306
  while (n) {
372
- var _n$nextSibling, _n$nextSibling$tagNam, _n$previousSibling, _n$previousSibling$ta;
373
-
307
+ var _n$nextSibling, _n$previousSibling;
374
308
  var isWhiteSpace = allWhitespace(n);
375
- var isNotNearMarkup = !MARK_TAGS[(_n$nextSibling = n.nextSibling) === null || _n$nextSibling === void 0 ? void 0 : (_n$nextSibling$tagNam = _n$nextSibling.tagName) === null || _n$nextSibling$tagNam === void 0 ? void 0 : _n$nextSibling$tagNam.toLowerCase()] && !MARK_TAGS[(_n$previousSibling = n.previousSibling) === null || _n$previousSibling === void 0 ? void 0 : (_n$previousSibling$ta = _n$previousSibling.tagName) === null || _n$previousSibling$ta === void 0 ? void 0 : _n$previousSibling$ta.toLowerCase()];
376
-
309
+ var isNotNearMarkup = !MARK_TAGS[(_n$nextSibling = n.nextSibling) === null || _n$nextSibling === void 0 || (_n$nextSibling = _n$nextSibling.tagName) === null || _n$nextSibling === void 0 ? void 0 : _n$nextSibling.toLowerCase()] && !MARK_TAGS[(_n$previousSibling = n.previousSibling) === null || _n$previousSibling === void 0 || (_n$previousSibling = _n$previousSibling.tagName) === null || _n$previousSibling === void 0 ? void 0 : _n$previousSibling.toLowerCase()];
377
310
  if (isWhiteSpace && isNotNearMarkup || n.nodeValue === "\u200B") {
378
311
  n.parentNode.removeChild(n);
379
312
  }
380
-
381
313
  n = textNodes.nextNode();
382
314
  }
383
-
384
315
  return body;
385
316
  }
386
- /** If this lib is used on the server side, we need to bypass using the DOMParser - just put in a stub. */
387
-
388
317
 
318
+ /** If this lib is used on the server side, we need to bypass using the DOMParser - just put in a stub. */
389
319
  var parseHtml = typeof window === 'undefined' ? function () {
390
320
  return {
391
321
  childNodes: []
@@ -396,20 +326,18 @@ var serializer = new _slateHtmlSerializer["default"]({
396
326
  rules: RULES,
397
327
  parseHtml: parseHtml
398
328
  });
399
-
400
329
  var _extends = Object.assign || function (target) {
401
330
  for (var i = 1; i < arguments.length; i++) {
402
331
  var source = arguments[i];
403
-
404
332
  for (var key in source) {
405
333
  if (Object.prototype.hasOwnProperty.call(source, key)) {
406
334
  target[key] = source[key];
407
335
  }
408
336
  }
409
337
  }
410
-
411
338
  return target;
412
339
  };
340
+
413
341
  /**
414
342
  * This is needed in order to override the function that eventually leads
415
343
  * to the max iteration of 12, which in most cases it's not enough. The newer versions
@@ -419,8 +347,6 @@ var _extends = Object.assign || function (target) {
419
347
  * Below is the code that calculates the max iterations.
420
348
  * var max = schema.stack.plugins.length + schema.rules.length + 1;
421
349
  */
422
-
423
-
424
350
  serializer.deserialize = function deserialize(html) {
425
351
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
426
352
  var _options$toJSON = options.toJSON;
@@ -429,22 +355,19 @@ serializer.deserialize = function deserialize(html) {
429
355
  var parseHtml = this.parseHtml;
430
356
  var fragment = parseHtml(html);
431
357
  var children = Array.from(fragment.childNodes);
432
- var nodes = this.deserializeElements(children); // COMPAT: ensure that all top-level inline nodes are wrapped into a block.
358
+ var nodes = this.deserializeElements(children);
433
359
 
360
+ // COMPAT: ensure that all top-level inline nodes are wrapped into a block.
434
361
  nodes = nodes.reduce(function (memo, node, i, original) {
435
362
  if (node.object === 'block') {
436
363
  memo.push(node);
437
364
  return memo;
438
365
  }
439
-
440
366
  if (i > 0 && original[i - 1].object !== 'block') {
441
367
  var _block = memo[memo.length - 1];
442
-
443
368
  _block.nodes.push(node);
444
-
445
369
  return memo;
446
370
  }
447
-
448
371
  var block = _extends({
449
372
  object: 'block',
450
373
  data: {},
@@ -452,11 +375,9 @@ serializer.deserialize = function deserialize(html) {
452
375
  }, defaultBlock, {
453
376
  nodes: [node]
454
377
  });
455
-
456
378
  memo.push(block);
457
379
  return memo;
458
380
  }, []);
459
-
460
381
  if (nodes.length === 0) {
461
382
  nodes = [_extends({
462
383
  object: 'block',
@@ -473,7 +394,6 @@ serializer.deserialize = function deserialize(html) {
473
394
  }]
474
395
  })];
475
396
  }
476
-
477
397
  var json = {
478
398
  object: 'value',
479
399
  document: {
@@ -486,7 +406,6 @@ serializer.deserialize = function deserialize(html) {
486
406
  }
487
407
  };
488
408
  var i;
489
-
490
409
  for (i = 0; i < 3000; i++) {
491
410
  json.schema.rules.push({
492
411
  match: {
@@ -499,56 +418,46 @@ serializer.deserialize = function deserialize(html) {
499
418
  }]
500
419
  });
501
420
  }
502
-
503
421
  var ret = toJSON ? json : _slate.Value.fromJSON(json);
504
-
505
422
  if (ret) {
506
423
  return ret;
507
424
  }
508
-
509
425
  return null;
510
426
  };
511
-
512
- var reduceMultipleBrs = function reduceMultipleBrs(markup) {
427
+ var reduceMultipleBrs = exports.reduceMultipleBrs = function reduceMultipleBrs(markup) {
513
428
  try {
514
429
  return markup.replace(/(<br\s*\/?>){3,}/gi, '<br>');
515
430
  } catch (e) {
516
431
  // eslint-disable-next-line no-console
517
- console.log("Couldn't remove <br/> tags: ", e);
432
+ console.log('Couldn\'t remove <br/> tags: ', e);
518
433
  }
519
-
520
434
  return markup;
521
435
  };
522
-
523
- exports.reduceMultipleBrs = reduceMultipleBrs;
524
-
525
436
  var reduceRedundantNewLineCharacters = function reduceRedundantNewLineCharacters(markup) {
526
437
  try {
527
438
  return markup.replace(/\n/gi, '');
528
439
  } catch (e) {
529
440
  // eslint-disable-next-line no-console
530
- console.log("Couldn't remove <br/> tags: ", e);
441
+ console.log('Couldn\'t remove <br/> tags: ', e);
531
442
  }
532
-
533
443
  return markup;
534
444
  };
445
+
535
446
  /**
536
447
  * Makes sure that the html provided respects the schema
537
448
  * rules for the slate editor.
538
449
  * @param markup
539
450
  * @returns {string}
540
451
  */
541
-
542
-
543
452
  var fixHtmlCode = function fixHtmlCode(markup) {
544
453
  var wrapperEl = document.createElement('div');
545
454
  wrapperEl.innerHTML = markup;
455
+
546
456
  /**
547
457
  * DIV elements that are at the same level as paragraphs
548
458
  * are replaced with P elements for normalizing purposes
549
459
  * @param child
550
460
  */
551
-
552
461
  var fixParagraphs = function fixParagraphs(child) {
553
462
  var p = document.createElement('p');
554
463
  p.innerHTML = child.innerHTML;
@@ -557,6 +466,7 @@ var fixHtmlCode = function fixHtmlCode(markup) {
557
466
  });
558
467
  child.replaceWith(p);
559
468
  };
469
+
560
470
  /**
561
471
  * @summary Makes sure that tables are placed in the root document.
562
472
  * @description This function removes the tables from the nodes that are
@@ -564,48 +474,46 @@ var fixHtmlCode = function fixHtmlCode(markup) {
564
474
  * the parent element.
565
475
  * @param tableArray
566
476
  */
567
-
568
-
569
477
  var fixTables = function fixTables(tableArray) {
570
478
  tableArray.forEach(function (el) {
571
479
  var index = el.index,
572
- child = el.child,
573
- parent = el.parent;
480
+ child = el.child,
481
+ parent = el.parent;
574
482
  var nodesBefore = [];
575
483
  var nodesAfter = [];
576
484
  var allNodes = Array.from(parent.childNodes);
577
485
  var i;
578
-
579
486
  for (i = 0; i < allNodes.length; i++) {
580
487
  var node = allNodes[i];
581
-
582
488
  if (i < index) {
583
489
  nodesBefore.push(node);
584
490
  } else if (i > index) {
585
491
  nodesAfter.push(node);
586
492
  }
587
- } // creating the element that is going to be placed instead of the parent
588
-
493
+ }
589
494
 
495
+ // creating the element that is going to be placed instead of the parent
590
496
  var beforeEl = document.createElement(parent.nodeName);
591
- beforeEl.append.apply(beforeEl, nodesBefore); // replacing parent with the beforeElement
497
+ beforeEl.append.apply(beforeEl, nodesBefore);
592
498
 
593
- parent.replaceWith(beforeEl); // adding the table right after the before element
499
+ // replacing parent with the beforeElement
500
+ parent.replaceWith(beforeEl);
594
501
 
595
- beforeEl.after(child); // creating the element that is going to be placed after the table
502
+ // adding the table right after the before element
503
+ beforeEl.after(child);
596
504
 
505
+ // creating the element that is going to be placed after the table
597
506
  var afterEl = document.createElement(parent.nodeName);
598
- afterEl.append.apply(afterEl, nodesAfter); // adding the after element near the table
507
+ afterEl.append.apply(afterEl, nodesAfter);
599
508
 
509
+ // adding the after element near the table
600
510
  child.after(afterEl);
601
511
  });
602
512
  };
603
-
604
513
  var emptyBlockCheck = function emptyBlockCheck(node) {
605
514
  return (node.nodeName === 'DIV' || node.nodeName === 'P' || node.nodeName === 'LI') && node.childNodes.length === 0;
606
515
  };
607
-
608
- var parseNode = function parseNode(el) {
516
+ var _parseNode = function parseNode(el) {
609
517
  var childArray = Array.from(el.childNodes);
610
518
  var hasParagraphs = childArray.find(function (child) {
611
519
  return child.nodeName === 'P';
@@ -617,11 +525,9 @@ var fixHtmlCode = function fixHtmlCode(markup) {
617
525
  child.remove();
618
526
  return;
619
527
  }
620
-
621
528
  if (hasParagraphs && child.nodeName === 'DIV') {
622
529
  fixParagraphs(child);
623
530
  }
624
-
625
531
  if (wrapperEl !== el && child.nodeName === 'TABLE') {
626
532
  // we don't need to fix tables in the root element
627
533
  tables.push({
@@ -630,40 +536,31 @@ var fixHtmlCode = function fixHtmlCode(markup) {
630
536
  parent: el
631
537
  });
632
538
  }
633
-
634
- parseNode(child);
539
+ _parseNode(child);
635
540
  });
636
-
637
541
  if (tables.length) {
638
542
  fixTables(tables);
639
543
  }
640
544
  };
641
-
642
- parseNode(wrapperEl);
545
+ _parseNode(wrapperEl);
643
546
  return wrapperEl.innerHTML;
644
547
  };
645
-
646
- var handleHtml = function handleHtml(html) {
548
+ var handleHtml = exports.handleHtml = function handleHtml(html) {
647
549
  return fixHtmlCode(reduceRedundantNewLineCharacters(reduceMultipleBrs(html)));
648
550
  };
649
-
650
- exports.handleHtml = handleHtml;
651
-
652
- var htmlToValue = function htmlToValue(html) {
551
+ var htmlToValue = exports.htmlToValue = function htmlToValue(html) {
653
552
  try {
654
553
  return serializer.deserialize(handleHtml(html));
655
554
  } catch (e) {
656
555
  // eslint-disable-next-line no-console
657
- console.log("Couldn't parse html: ", e);
556
+ console.log('Couldn\'t parse html: ', e);
658
557
  return {};
659
558
  }
660
559
  };
661
-
662
- exports.htmlToValue = htmlToValue;
663
-
664
- var valueToHtml = function valueToHtml(value) {
560
+ var valueToHtml = exports.valueToHtml = function valueToHtml(value) {
665
561
  return serializer.serialize(value);
666
562
  };
563
+
667
564
  /**
668
565
  *
669
566
  * <div><div>a</div></div> -> <div>a</div>
@@ -671,7 +568,4 @@ var valueToHtml = function valueToHtml(value) {
671
568
  * <div><div>a</div><div>b</div></div> -> <div>a</div><div>b</div>
672
569
  * <div><div>a</div>4444<div>b</div></div> -> <div>a</div>4444<div>b</div>
673
570
  */
674
-
675
-
676
- exports.valueToHtml = valueToHtml;
677
571
  //# sourceMappingURL=serialization.js.map