@pie-lib/editable-html 12.1.0-next.2 → 12.1.0-next.30

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 (103) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/lib/block-tags.js +25 -0
  3. package/lib/block-tags.js.map +1 -0
  4. package/lib/constants.js +12 -0
  5. package/lib/constants.js.map +1 -0
  6. package/lib/editor.js +1254 -0
  7. package/lib/editor.js.map +1 -0
  8. package/lib/index.js +224 -0
  9. package/lib/index.js.map +1 -0
  10. package/lib/parse-html.js +19 -0
  11. package/lib/parse-html.js.map +1 -0
  12. package/lib/plugins/characters/custom-popper.js +58 -0
  13. package/lib/plugins/characters/custom-popper.js.map +1 -0
  14. package/lib/plugins/characters/index.js +280 -0
  15. package/lib/plugins/characters/index.js.map +1 -0
  16. package/lib/plugins/characters/utils.js +380 -0
  17. package/lib/plugins/characters/utils.js.map +1 -0
  18. package/lib/plugins/css/icons/index.js +26 -0
  19. package/lib/plugins/css/icons/index.js.map +1 -0
  20. package/lib/plugins/css/index.js +350 -0
  21. package/lib/plugins/css/index.js.map +1 -0
  22. package/lib/plugins/customPlugin/index.js +109 -0
  23. package/lib/plugins/customPlugin/index.js.map +1 -0
  24. package/lib/plugins/html/icons/index.js +31 -0
  25. package/lib/plugins/html/icons/index.js.map +1 -0
  26. package/lib/plugins/html/index.js +72 -0
  27. package/lib/plugins/html/index.js.map +1 -0
  28. package/lib/plugins/image/alt-dialog.js +105 -0
  29. package/lib/plugins/image/alt-dialog.js.map +1 -0
  30. package/lib/plugins/image/component.js +357 -0
  31. package/lib/plugins/image/component.js.map +1 -0
  32. package/lib/plugins/image/image-toolbar.js +140 -0
  33. package/lib/plugins/image/image-toolbar.js.map +1 -0
  34. package/lib/plugins/image/index.js +237 -0
  35. package/lib/plugins/image/index.js.map +1 -0
  36. package/lib/plugins/image/insert-image-handler.js +141 -0
  37. package/lib/plugins/image/insert-image-handler.js.map +1 -0
  38. package/lib/plugins/index.js +359 -0
  39. package/lib/plugins/index.js.map +1 -0
  40. package/lib/plugins/list/index.js +300 -0
  41. package/lib/plugins/list/index.js.map +1 -0
  42. package/lib/plugins/math/index.js +417 -0
  43. package/lib/plugins/math/index.js.map +1 -0
  44. package/lib/plugins/media/index.js +343 -0
  45. package/lib/plugins/media/index.js.map +1 -0
  46. package/lib/plugins/media/media-dialog.js +612 -0
  47. package/lib/plugins/media/media-dialog.js.map +1 -0
  48. package/lib/plugins/media/media-toolbar.js +78 -0
  49. package/lib/plugins/media/media-toolbar.js.map +1 -0
  50. package/lib/plugins/media/media-wrapper.js +66 -0
  51. package/lib/plugins/media/media-wrapper.js.map +1 -0
  52. package/lib/plugins/rendering/index.js +46 -0
  53. package/lib/plugins/rendering/index.js.map +1 -0
  54. package/lib/plugins/respArea/drag-in-the-blank/choice.js +288 -0
  55. package/lib/plugins/respArea/drag-in-the-blank/choice.js.map +1 -0
  56. package/lib/plugins/respArea/drag-in-the-blank/index.js +56 -0
  57. package/lib/plugins/respArea/drag-in-the-blank/index.js.map +1 -0
  58. package/lib/plugins/respArea/drag-in-the-blank/utils.js +48 -0
  59. package/lib/plugins/respArea/drag-in-the-blank/utils.js.map +1 -0
  60. package/lib/plugins/respArea/explicit-constructed-response/index.js +51 -0
  61. package/lib/plugins/respArea/explicit-constructed-response/index.js.map +1 -0
  62. package/lib/plugins/respArea/icons/index.js +82 -0
  63. package/lib/plugins/respArea/icons/index.js.map +1 -0
  64. package/lib/plugins/respArea/index.js +298 -0
  65. package/lib/plugins/respArea/index.js.map +1 -0
  66. package/lib/plugins/respArea/inline-dropdown/index.js +68 -0
  67. package/lib/plugins/respArea/inline-dropdown/index.js.map +1 -0
  68. package/lib/plugins/respArea/math-templated/index.js +113 -0
  69. package/lib/plugins/respArea/math-templated/index.js.map +1 -0
  70. package/lib/plugins/respArea/utils.js +101 -0
  71. package/lib/plugins/respArea/utils.js.map +1 -0
  72. package/lib/plugins/table/CustomTablePlugin.js +123 -0
  73. package/lib/plugins/table/CustomTablePlugin.js.map +1 -0
  74. package/lib/plugins/table/icons/index.js +57 -0
  75. package/lib/plugins/table/icons/index.js.map +1 -0
  76. package/lib/plugins/table/index.js +431 -0
  77. package/lib/plugins/table/index.js.map +1 -0
  78. package/lib/plugins/table/table-toolbar.js +153 -0
  79. package/lib/plugins/table/table-toolbar.js.map +1 -0
  80. package/lib/plugins/textAlign/icons/index.js +202 -0
  81. package/lib/plugins/textAlign/icons/index.js.map +1 -0
  82. package/lib/plugins/textAlign/index.js +27 -0
  83. package/lib/plugins/textAlign/index.js.map +1 -0
  84. package/lib/plugins/toolbar/default-toolbar.js +194 -0
  85. package/lib/plugins/toolbar/default-toolbar.js.map +1 -0
  86. package/lib/plugins/toolbar/done-button.js +36 -0
  87. package/lib/plugins/toolbar/done-button.js.map +1 -0
  88. package/lib/plugins/toolbar/editor-and-toolbar.js +270 -0
  89. package/lib/plugins/toolbar/editor-and-toolbar.js.map +1 -0
  90. package/lib/plugins/toolbar/index.js +30 -0
  91. package/lib/plugins/toolbar/index.js.map +1 -0
  92. package/lib/plugins/toolbar/toolbar-buttons.js +157 -0
  93. package/lib/plugins/toolbar/toolbar-buttons.js.map +1 -0
  94. package/lib/plugins/toolbar/toolbar.js +321 -0
  95. package/lib/plugins/toolbar/toolbar.js.map +1 -0
  96. package/lib/plugins/utils.js +45 -0
  97. package/lib/plugins/utils.js.map +1 -0
  98. package/lib/serialization.js +595 -0
  99. package/lib/serialization.js.map +1 -0
  100. package/lib/shared/alert-dialog.js +69 -0
  101. package/lib/theme.js +9 -0
  102. package/lib/theme.js.map +1 -0
  103. package/package.json +9 -11
@@ -0,0 +1,417 @@
1
+ "use strict";
2
+
3
+ require("core-js/modules/es.symbol.js");
4
+ require("core-js/modules/es.array.filter.js");
5
+ require("core-js/modules/es.array.for-each.js");
6
+ require("core-js/modules/es.object.define-properties.js");
7
+ require("core-js/modules/es.object.define-property.js");
8
+ require("core-js/modules/es.object.get-own-property-descriptor.js");
9
+ require("core-js/modules/es.object.get-own-property-descriptors.js");
10
+ require("core-js/modules/es.object.keys.js");
11
+ require("core-js/modules/web.dom-collections.for-each.js");
12
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
13
+ Object.defineProperty(exports, "__esModule", {
14
+ value: true
15
+ });
16
+ exports.CustomToolbarComp = void 0;
17
+ exports["default"] = MathPlugin;
18
+ exports.serialization = exports.inlineMath = void 0;
19
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
20
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
21
+ require("core-js/modules/es.array.concat.js");
22
+ require("core-js/modules/es.array.map.js");
23
+ require("core-js/modules/es.object.to-string.js");
24
+ require("core-js/modules/es.regexp.exec.js");
25
+ require("core-js/modules/es.string.replace.js");
26
+ require("core-js/modules/esnext.string.replace-all.js");
27
+ var _Functions = _interopRequireDefault(require("@mui/icons-material/Functions"));
28
+ var _slate = require("slate");
29
+ var _mathToolbar = require("@pie-lib/math-toolbar");
30
+ var _mathRendering = require("@pie-lib/math-rendering");
31
+ var _react = _interopRequireDefault(require("react"));
32
+ var _debug = _interopRequireDefault(require("debug"));
33
+ var _slatePropTypes = _interopRequireDefault(require("slate-prop-types"));
34
+ var _propTypes = _interopRequireDefault(require("prop-types"));
35
+ var _blockTags = require("../../block-tags");
36
+ var _isEqual = _interopRequireDefault(require("lodash/isEqual"));
37
+ 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; }
38
+ 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; }
39
+ var log = (0, _debug["default"])('@pie-lib:editable-html:plugins:math');
40
+ var TEXT_NODE = 3;
41
+ function generateAdditionalKeys() {
42
+ var keyData = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
43
+ return keyData.map(function (key) {
44
+ return {
45
+ name: key,
46
+ latex: key,
47
+ write: key,
48
+ label: key
49
+ };
50
+ });
51
+ }
52
+
53
+ // eslint-disable-next-line react/display-name
54
+ var CustomToolbarComp = exports.CustomToolbarComp = /*#__PURE__*/_react["default"].memo(function (props) {
55
+ var node = props.node,
56
+ value = props.value,
57
+ onFocus = props.onFocus,
58
+ onBlur = props.onBlur,
59
+ onClick = props.onClick;
60
+ var _ref = props || {},
61
+ pluginProps = _ref.pluginProps;
62
+ var _ref2 = pluginProps || {},
63
+ math = _ref2.math;
64
+ var _ref3 = math || {},
65
+ keypadMode = _ref3.keypadMode,
66
+ customKeys = _ref3.customKeys,
67
+ _ref3$controlledKeypa = _ref3.controlledKeypadMode,
68
+ controlledKeypadMode = _ref3$controlledKeypa === void 0 ? true : _ref3$controlledKeypa;
69
+ var onDone = function onDone(latex) {
70
+ var update = _objectSpread(_objectSpread({}, node.data.toObject()), {}, {
71
+ latex: latex
72
+ });
73
+ var change = value.change().setNodeByKey(node.key, {
74
+ data: update
75
+ });
76
+ var nextText = value.document.getNextText(node.key);
77
+ change.moveFocusTo(nextText.key, 0).moveAnchorTo(nextText.key, 0);
78
+ props.onToolbarDone(change, false);
79
+ };
80
+ var onChange = function onChange(latex) {
81
+ var update = _objectSpread(_objectSpread({}, node.data.toObject()), {}, {
82
+ latex: latex
83
+ });
84
+ var change = value.change().setNodeByKey(node.key, {
85
+ data: update
86
+ });
87
+ log('call onToolbarChange:', change);
88
+ props.onDataChange(node.key, update);
89
+ };
90
+ var latex = node.data.get('latex');
91
+ return /*#__PURE__*/_react["default"].createElement(_mathToolbar.MathToolbar, {
92
+ autoFocus: true,
93
+ additionalKeys: generateAdditionalKeys(customKeys),
94
+ latex: latex,
95
+ onChange: onChange,
96
+ onDone: onDone,
97
+ onBlur: onBlur,
98
+ onFocus: onFocus,
99
+ onClick: onClick,
100
+ keypadMode: keypadMode,
101
+ controlledKeypadMode: controlledKeypadMode
102
+ });
103
+ }, function (prev, next) {
104
+ var node = prev.node,
105
+ _prev$pluginProps = prev.pluginProps,
106
+ _prev$pluginProps2 = _prev$pluginProps === void 0 ? {} : _prev$pluginProps,
107
+ _prev$pluginProps2$ma = _prev$pluginProps2.math,
108
+ _prev$pluginProps2$ma2 = _prev$pluginProps2$ma === void 0 ? {} : _prev$pluginProps2$ma,
109
+ keypadMode = _prev$pluginProps2$ma2.keypadMode,
110
+ controlledKeypadMode = _prev$pluginProps2$ma2.controlledKeypadMode;
111
+ var nodeNext = next.node,
112
+ _next$pluginProps = next.pluginProps,
113
+ _next$pluginProps2 = _next$pluginProps === void 0 ? {} : _next$pluginProps,
114
+ _next$pluginProps2$ma = _next$pluginProps2.math,
115
+ _next$pluginProps2$ma2 = _next$pluginProps2$ma === void 0 ? {} : _next$pluginProps2$ma,
116
+ keypadModeNext = _next$pluginProps2$ma2.keypadMode,
117
+ controlledKeypadModeNext = _next$pluginProps2$ma2.controlledKeypadMode;
118
+ var keypadModeChanged = keypadMode !== keypadModeNext;
119
+ var controlledKeypadModeChanged = controlledKeypadMode !== controlledKeypadModeNext;
120
+ var equal = node.equals(nodeNext);
121
+ return equal && !keypadModeChanged && !controlledKeypadModeChanged;
122
+ });
123
+ CustomToolbarComp.propTypes = {
124
+ node: _slatePropTypes["default"].node.isRequired,
125
+ value: _slatePropTypes["default"].value,
126
+ onToolbarDone: _propTypes["default"].func,
127
+ onDataChange: _propTypes["default"].func,
128
+ onFocus: _propTypes["default"].func,
129
+ onClick: _propTypes["default"].func,
130
+ onBlur: _propTypes["default"].func
131
+ };
132
+ function MathPlugin(opts) {
133
+ MathPlugin.mathMlOptions = {
134
+ mmlOutput: opts.mmlOutput,
135
+ mmlEditing: opts.mmlEditing
136
+ };
137
+ return {
138
+ name: 'math',
139
+ toolbar: {
140
+ ariaLabel: 'Math Toolbar',
141
+ icon: /*#__PURE__*/_react["default"].createElement(_Functions["default"], null),
142
+ onClick: function onClick(value, onChange) {
143
+ log('[insertMath]');
144
+ var math = inlineMath();
145
+ var change = value.change().insertInline(math);
146
+ onChange(change);
147
+ },
148
+ supports: function supports(node) {
149
+ return node && node.object === 'inline' && node.type === 'math';
150
+ },
151
+ /**
152
+ * Return a react component function
153
+ * @param node {Slate.Node}
154
+ * @param value {Slate.Value}
155
+ * @param onDone {(change?: Slate.Change, finishEditing :boolea) => void} - a function to call once the toolbar
156
+ * has made any changes, call with the node.key and a data object.
157
+ */
158
+ CustomToolbarComp: CustomToolbarComp
159
+ },
160
+ schema: {
161
+ document: {
162
+ match: [{
163
+ type: 'math'
164
+ }]
165
+ }
166
+ },
167
+ pluginStyles: function pluginStyles(node, parentNode, p) {
168
+ if (p) {
169
+ return {
170
+ position: 'absolute',
171
+ top: 'initial'
172
+ };
173
+ }
174
+ },
175
+ renderNode: function renderNode(props) {
176
+ if (props.node.type === 'math') {
177
+ log('[renderNode]: data:', props.node.data);
178
+ return /*#__PURE__*/_react["default"].createElement(_mathToolbar.MathPreview, props);
179
+ }
180
+
181
+ /**
182
+ * Here for rendering mathml content
183
+ */
184
+ if (props.node.type === 'mathml') {
185
+ var html = props.node.data.get('html');
186
+ return /*#__PURE__*/_react["default"].createElement("span", (0, _extends2["default"])({}, props.attributes, {
187
+ dangerouslySetInnerHTML: {
188
+ __html: html
189
+ }
190
+ }));
191
+ }
192
+ }
193
+ };
194
+ }
195
+ MathPlugin.ROUND_BRACKETS = 'round_brackets';
196
+ MathPlugin.SQUARE_BRACKETS = 'square_brackets';
197
+ MathPlugin.DOLLAR = 'dollar';
198
+ MathPlugin.DOUBLE_DOLLAR = 'double_dollar';
199
+ MathPlugin.mathMlOptions = {};
200
+ MathPlugin.propTypes = {
201
+ attributes: _propTypes["default"].object,
202
+ node: _slatePropTypes["default"].node
203
+ };
204
+ var inlineMath = exports.inlineMath = function inlineMath() {
205
+ return _slate.Inline.create({
206
+ object: 'inline',
207
+ type: 'math',
208
+ isVoid: true,
209
+ data: {
210
+ latex: ''
211
+ }
212
+ });
213
+ };
214
+ var htmlDecode = function htmlDecode(input) {
215
+ var doc = new DOMParser().parseFromString(input, 'text/html');
216
+ return doc.documentElement.textContent;
217
+ };
218
+ var getTagName = function getTagName(el) {
219
+ return (el && el.tagName || '').toLowerCase();
220
+ };
221
+
222
+ /**
223
+ * Makes sure that strings that contain stuff like:
224
+ * x<y are not transformed into x by the DOMParser because it thinks
225
+ * that <y is the start of a dom element tag
226
+ * @param input
227
+ * @returns {*}
228
+ */
229
+ var arrowHandlingCase = function arrowHandlingCase(input) {
230
+ /*
231
+ If we have a < character followed by a letter
232
+ we make sure to replace it with a &lt; sign instead
233
+ */
234
+ return input.replace(/<([a-zA-Z]*)/g, '&lt;$1');
235
+ };
236
+ function replaceLeftRight(latexInput) {
237
+ // for some reason, mmlToLatex parses () incorrectly - or at least in a way that our interpreter can not use them
238
+ // Replace '\\left.' and '\\right.' with an empty string
239
+ return latexInput.replace(/\\left\.\s*|\\right\.\s*/g, '');
240
+ }
241
+ var convertLatexToMathMl = function convertLatexToMathMl(_ref4) {
242
+ var latex = _ref4.latex,
243
+ decoded = _ref4.decoded,
244
+ wrapper = _ref4.wrapper;
245
+ var removeEmptyMos = function removeEmptyMos(mmlFromLatex) {
246
+ // Regular expression to match <mo>&#x2061;</mo> and <mo ...>&#x2061;</mo>, which get added when using log with base
247
+ // not sure why they get added, but they add an extra space which is not needed
248
+ var regex = /<mo(?: [^>]*)?>&#x2061;<\/mo>/g;
249
+
250
+ // Replace all occurrences of the matched patterns
251
+ return mmlFromLatex.replace(regex, '');
252
+ };
253
+ var handled = arrowHandlingCase(decoded);
254
+ var latexToConvert = "<span data-latex=\"\" data-raw=\"".concat(handled, "\">").concat((0, _mathRendering.wrapMath)(handled, wrapper), "</span>");
255
+
256
+ // use math rendering (MathJax) to convert latex to mathMl
257
+ var mathMlFromLatex = (0, _mathRendering.renderMath)(latexToConvert, {
258
+ skipWaitForMathRenderingLib: true
259
+ });
260
+
261
+ // if renderMath returned the exact same string that we sent, it just means that the conversion could not be done
262
+ var conversionDidNotWork = (0, _isEqual["default"])(latexToConvert, mathMlFromLatex);
263
+ mathMlFromLatex = removeEmptyMos(mathMlFromLatex);
264
+
265
+ // we convert resulted mathml to latex to check if the resulted mathMl can be converted back to latex if user wants to edit it later
266
+ var latexFromMathMl = mathMlFromLatex ? (0, _mathRendering.mmlToLatex)(mathMlFromLatex) : '';
267
+
268
+ // we need to remove all the spaces from the latex to be able to compare it
269
+ var strippedL = latex.replace(/\s/g, '');
270
+ var strippedNewL = latexFromMathMl.replace(/\s/g, '');
271
+
272
+ // we check if the latex keeps his form after being converted to mathml and back to latex
273
+ // if it does, we can safely convert it to mathml
274
+ if (!(0, _isEqual["default"])(strippedL, strippedNewL)) {
275
+ var correctedLatex = replaceLeftRight(latexFromMathMl);
276
+
277
+ // As George requested in PD-3167, I will set the new mathML anyway, and also log differences
278
+ // if it doesn't, we keep the latex version
279
+ // eslint-disable-next-line no-console
280
+ console.log('This latex can not be safely converted to mathml so we will keep the latex version!!!', {
281
+ initialLatex: latex,
282
+ newLatex: latexFromMathMl,
283
+ correctedLatex: correctedLatex,
284
+ mathML: mathMlFromLatex,
285
+ conversionDidNotWork: conversionDidNotWork
286
+ });
287
+ }
288
+ return {
289
+ mathMlFromLatex: mathMlFromLatex,
290
+ conversionDidNotWork: conversionDidNotWork
291
+ };
292
+ };
293
+ var convertMathMlToLatex = function convertMathMlToLatex(mathMl) {
294
+ var htmlWithRemovedSpaces = mathMl.replaceAll('&nbsp;', ' ');
295
+ var htmlToUse = (0, _mathRendering.mmlToLatex)(htmlWithRemovedSpaces);
296
+ var latex = htmlDecode(htmlToUse);
297
+
298
+ // todo fix this in mathml-to-latex
299
+ return replaceLeftRight(latex);
300
+ };
301
+ var serialization = exports.serialization = {
302
+ deserialize: function deserialize(el) {
303
+ var tagName = getTagName(el);
304
+ /**
305
+ * This is used for when there's a wrapper over the mathml element.
306
+ * Because of this slate rule: "Only allow block nodes or inline and text nodes in blocks."
307
+ * The element that contains only the mathml is removed (along with the math) because it has
308
+ * an inline child and the block is of type block
309
+ * This is for legacy content only since our math rendering is valid for the core slate rules
310
+ */
311
+ var hasMathChild = _blockTags.BLOCK_TAGS[tagName] && el.childNodes.length === 1 && getTagName(el.firstChild) === 'math';
312
+ log('[deserialize] name: ', tagName);
313
+
314
+ /**
315
+ * This is here in order to be able to render mathml content
316
+ */
317
+ if (tagName === 'math' || el.dataset && el.dataset.type === 'mathml' || hasMathChild) {
318
+ var mathMl = hasMathChild ? el.innerHTML : el.outerHTML;
319
+ if (MathPlugin.mathMlOptions.mmlEditing) {
320
+ var _unWrapMath = (0, _mathRendering.unWrapMath)(convertMathMlToLatex(mathMl)),
321
+ unwrapped = _unWrapMath.unwrapped,
322
+ wrapType = _unWrapMath.wrapType;
323
+ return {
324
+ object: 'inline',
325
+ type: 'math',
326
+ isVoid: true,
327
+ nodes: [],
328
+ data: {
329
+ latex: unwrapped,
330
+ wrapper: wrapType
331
+ }
332
+ };
333
+ }
334
+ return {
335
+ object: 'inline',
336
+ isVoid: true,
337
+ type: 'mathml',
338
+ data: {
339
+ html: mathMl
340
+ }
341
+ };
342
+ }
343
+ if (el.nodeType === TEXT_NODE) {
344
+ return;
345
+ }
346
+ if (tagName !== 'span') {
347
+ return;
348
+ }
349
+ var hasLatex = el.hasAttribute('data-latex') || el.hasAttribute('latex');
350
+ if (hasLatex) {
351
+ var latex = htmlDecode(el.innerHTML);
352
+ var _unWrapMath2 = (0, _mathRendering.unWrapMath)(latex),
353
+ _unwrapped = _unWrapMath2.unwrapped,
354
+ _wrapType = _unWrapMath2.wrapType;
355
+ log('[deserialize]: noBrackets: ', _unwrapped, _wrapType);
356
+ return {
357
+ object: 'inline',
358
+ type: 'math',
359
+ isVoid: true,
360
+ nodes: [],
361
+ data: {
362
+ latex: _unwrapped,
363
+ wrapper: _wrapType
364
+ }
365
+ };
366
+ }
367
+ },
368
+ serialize: function serialize(object) {
369
+ if (object.type === 'math') {
370
+ var latex = object.data.get('latex');
371
+ var wrapper = object.data.get('wrapper');
372
+ var decoded = htmlDecode(arrowHandlingCase(latex));
373
+ log('[serialize] latex: ', latex);
374
+ if (MathPlugin.mathMlOptions.mmlOutput) {
375
+ var _convertLatexToMathMl = convertLatexToMathMl({
376
+ latex: latex,
377
+ decoded: decoded,
378
+ wrapper: wrapper
379
+ }),
380
+ mathMlFromLatex = _convertLatexToMathMl.mathMlFromLatex,
381
+ conversionDidNotWork = _convertLatexToMathMl.conversionDidNotWork;
382
+ if (conversionDidNotWork) {
383
+ // this means we could not convert latex to mathMl, so just return the latex version,
384
+ // same as we would do if mmlOutput would not be enabled
385
+ return /*#__PURE__*/_react["default"].createElement("span", {
386
+ "data-latex": "",
387
+ "data-raw": decoded
388
+ }, (0, _mathRendering.wrapMath)(decoded, wrapper));
389
+ }
390
+ return /*#__PURE__*/_react["default"].createElement("span", {
391
+ "data-type": "mathml",
392
+ dangerouslySetInnerHTML: {
393
+ __html: mathMlFromLatex
394
+ }
395
+ });
396
+ }
397
+ return /*#__PURE__*/_react["default"].createElement("span", {
398
+ "data-latex": "",
399
+ "data-raw": decoded
400
+ }, (0, _mathRendering.wrapMath)(decoded, wrapper));
401
+ }
402
+
403
+ /**
404
+ * Here for rendering mathml content
405
+ */
406
+ if (object.type === 'mathml') {
407
+ var html = object.data.get('html');
408
+ return /*#__PURE__*/_react["default"].createElement("span", {
409
+ "data-type": "mathml",
410
+ dangerouslySetInnerHTML: {
411
+ __html: html
412
+ }
413
+ });
414
+ }
415
+ }
416
+ };
417
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":["_Functions","_interopRequireDefault","require","_slate","_mathToolbar","_mathRendering","_react","_debug","_slatePropTypes","_propTypes","_blockTags","_isEqual","ownKeys","e","r","t","Object","keys","getOwnPropertySymbols","o","filter","getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","arguments","length","forEach","_defineProperty2","getOwnPropertyDescriptors","defineProperties","defineProperty","log","debug","TEXT_NODE","generateAdditionalKeys","keyData","undefined","map","key","name","latex","write","label","CustomToolbarComp","exports","React","memo","props","node","value","onFocus","onBlur","onClick","_ref","pluginProps","_ref2","math","_ref3","keypadMode","customKeys","_ref3$controlledKeypa","controlledKeypadMode","onDone","update","data","toObject","change","setNodeByKey","nextText","document","getNextText","moveFocusTo","moveAnchorTo","onToolbarDone","onChange","onDataChange","get","createElement","MathToolbar","autoFocus","additionalKeys","prev","next","_prev$pluginProps","_prev$pluginProps2","_prev$pluginProps2$ma","_prev$pluginProps2$ma2","nodeNext","_next$pluginProps","_next$pluginProps2","_next$pluginProps2$ma","_next$pluginProps2$ma2","keypadModeNext","controlledKeypadModeNext","keypadModeChanged","controlledKeypadModeChanged","equal","equals","propTypes","SlatePropTypes","isRequired","PropTypes","func","MathPlugin","opts","mathMlOptions","mmlOutput","mmlEditing","toolbar","ariaLabel","icon","inlineMath","insertInline","supports","object","type","schema","match","pluginStyles","parentNode","p","position","top","renderNode","MathPreview","html","_extends2","attributes","dangerouslySetInnerHTML","__html","ROUND_BRACKETS","SQUARE_BRACKETS","DOLLAR","DOUBLE_DOLLAR","Inline","create","isVoid","htmlDecode","input","doc","DOMParser","parseFromString","documentElement","textContent","getTagName","el","tagName","toLowerCase","arrowHandlingCase","replace","replaceLeftRight","latexInput","convertLatexToMathMl","_ref4","decoded","wrapper","removeEmptyMos","mmlFromLatex","regex","handled","latexToConvert","concat","wrapMath","mathMlFromLatex","renderMath","skipWaitForMathRenderingLib","conversionDidNotWork","isEqual","latexFromMathMl","mmlToLatex","strippedL","strippedNewL","correctedLatex","console","initialLatex","newLatex","mathML","convertMathMlToLatex","mathMl","htmlWithRemovedSpaces","replaceAll","htmlToUse","serialization","deserialize","hasMathChild","BLOCK_TAGS","childNodes","firstChild","dataset","innerHTML","outerHTML","_unWrapMath","unWrapMath","unwrapped","wrapType","nodes","nodeType","hasLatex","hasAttribute","_unWrapMath2","serialize","_convertLatexToMathMl"],"sources":["../../../src/plugins/math/index.jsx"],"sourcesContent":["import Functions from '@mui/icons-material/Functions';\nimport { Inline } from 'slate';\nimport { MathPreview, MathToolbar } from '@pie-lib/math-toolbar';\nimport { wrapMath, unWrapMath, mmlToLatex, renderMath } from '@pie-lib/math-rendering';\nimport React from 'react';\nimport debug from 'debug';\nimport SlatePropTypes from 'slate-prop-types';\nimport PropTypes from 'prop-types';\n\nimport { BLOCK_TAGS } from '../../block-tags';\nimport isEqual from 'lodash/isEqual';\n\nconst log = debug('@pie-lib:editable-html:plugins:math');\n\nconst TEXT_NODE = 3;\n\nfunction generateAdditionalKeys(keyData = []) {\n return keyData.map((key) => ({\n name: key,\n latex: key,\n write: key,\n label: key,\n }));\n}\n\n// eslint-disable-next-line react/display-name\nexport const CustomToolbarComp = React.memo(\n (props) => {\n const { node, value, onFocus, onBlur, onClick } = props;\n const { pluginProps } = props || {};\n const { math } = pluginProps || {};\n const { keypadMode, customKeys, controlledKeypadMode = true } = math || {};\n\n const onDone = (latex) => {\n const update = {\n ...node.data.toObject(),\n latex,\n };\n\n const change = value.change().setNodeByKey(node.key, { data: update });\n\n const nextText = value.document.getNextText(node.key);\n\n change.moveFocusTo(nextText.key, 0).moveAnchorTo(nextText.key, 0);\n\n props.onToolbarDone(change, false);\n };\n\n const onChange = (latex) => {\n const update = {\n ...node.data.toObject(),\n latex,\n };\n const change = value.change().setNodeByKey(node.key, { data: update });\n log('call onToolbarChange:', change);\n props.onDataChange(node.key, update);\n };\n\n const latex = node.data.get('latex');\n\n return (\n <MathToolbar\n autoFocus\n additionalKeys={generateAdditionalKeys(customKeys)}\n latex={latex}\n onChange={onChange}\n onDone={onDone}\n onBlur={onBlur}\n onFocus={onFocus}\n onClick={onClick}\n keypadMode={keypadMode}\n controlledKeypadMode={controlledKeypadMode}\n />\n );\n },\n (prev, next) => {\n const { node, pluginProps: { math: { keypadMode, controlledKeypadMode } = {} } = {} } = prev;\n const {\n node: nodeNext,\n pluginProps: { math: { keypadMode: keypadModeNext, controlledKeypadMode: controlledKeypadModeNext } = {} } = {},\n } = next;\n const keypadModeChanged = keypadMode !== keypadModeNext;\n const controlledKeypadModeChanged = controlledKeypadMode !== controlledKeypadModeNext;\n\n const equal = node.equals(nodeNext);\n return equal && !keypadModeChanged && !controlledKeypadModeChanged;\n },\n);\n\nCustomToolbarComp.propTypes = {\n node: SlatePropTypes.node.isRequired,\n value: SlatePropTypes.value,\n onToolbarDone: PropTypes.func,\n onDataChange: PropTypes.func,\n onFocus: PropTypes.func,\n onClick: PropTypes.func,\n onBlur: PropTypes.func,\n};\n\nexport default function MathPlugin(opts) {\n MathPlugin.mathMlOptions = {\n mmlOutput: opts.mmlOutput,\n mmlEditing: opts.mmlEditing,\n };\n\n return {\n name: 'math',\n toolbar: {\n ariaLabel: 'Math Toolbar',\n icon: <Functions />,\n onClick: (value, onChange) => {\n log('[insertMath]');\n const math = inlineMath();\n const change = value.change().insertInline(math);\n onChange(change);\n },\n supports: (node) => node && node.object === 'inline' && node.type === 'math',\n /**\n * Return a react component function\n * @param node {Slate.Node}\n * @param value {Slate.Value}\n * @param onDone {(change?: Slate.Change, finishEditing :boolea) => void} - a function to call once the toolbar\n * has made any changes, call with the node.key and a data object.\n */\n CustomToolbarComp,\n },\n schema: {\n document: { match: [{ type: 'math' }] },\n },\n\n pluginStyles: (node, parentNode, p) => {\n if (p) {\n return {\n position: 'absolute',\n top: 'initial',\n };\n }\n },\n\n renderNode: (props) => {\n if (props.node.type === 'math') {\n log('[renderNode]: data:', props.node.data);\n return <MathPreview {...props} />;\n }\n\n /**\n * Here for rendering mathml content\n */\n if (props.node.type === 'mathml') {\n const html = props.node.data.get('html');\n\n return <span {...props.attributes} dangerouslySetInnerHTML={{ __html: html }} />;\n }\n },\n };\n}\n\nMathPlugin.ROUND_BRACKETS = 'round_brackets';\nMathPlugin.SQUARE_BRACKETS = 'square_brackets';\nMathPlugin.DOLLAR = 'dollar';\nMathPlugin.DOUBLE_DOLLAR = 'double_dollar';\nMathPlugin.mathMlOptions = {};\n\nMathPlugin.propTypes = {\n attributes: PropTypes.object,\n node: SlatePropTypes.node,\n};\n\nexport const inlineMath = () =>\n Inline.create({\n object: 'inline',\n type: 'math',\n isVoid: true,\n data: {\n latex: '',\n },\n });\n\nconst htmlDecode = (input) => {\n const doc = new DOMParser().parseFromString(input, 'text/html');\n\n return doc.documentElement.textContent;\n};\n\nconst getTagName = (el) => {\n return ((el && el.tagName) || '').toLowerCase();\n};\n\n/**\n * Makes sure that strings that contain stuff like:\n * x<y are not transformed into x by the DOMParser because it thinks\n * that <y is the start of a dom element tag\n * @param input\n * @returns {*}\n */\nconst arrowHandlingCase = (input) => {\n /*\n If we have a < character followed by a letter\n we make sure to replace it with a &lt; sign instead\n */\n return input.replace(/<([a-zA-Z]*)/g, '&lt;$1');\n};\n\nfunction replaceLeftRight(latexInput) {\n // for some reason, mmlToLatex parses () incorrectly - or at least in a way that our interpreter can not use them\n // Replace '\\\\left.' and '\\\\right.' with an empty string\n return latexInput.replace(/\\\\left\\.\\s*|\\\\right\\.\\s*/g, '');\n}\n\nconst convertLatexToMathMl = ({ latex, decoded, wrapper }) => {\n const removeEmptyMos = (mmlFromLatex) => {\n // Regular expression to match <mo>&#x2061;</mo> and <mo ...>&#x2061;</mo>, which get added when using log with base\n // not sure why they get added, but they add an extra space which is not needed\n const regex = /<mo(?: [^>]*)?>&#x2061;<\\/mo>/g;\n\n // Replace all occurrences of the matched patterns\n return mmlFromLatex.replace(regex, '');\n };\n const handled = arrowHandlingCase(decoded);\n\n const latexToConvert = `<span data-latex=\"\" data-raw=\"${handled}\">${wrapMath(handled, wrapper)}</span>`;\n\n // use math rendering (MathJax) to convert latex to mathMl\n let mathMlFromLatex = renderMath(latexToConvert, {\n skipWaitForMathRenderingLib: true,\n });\n\n // if renderMath returned the exact same string that we sent, it just means that the conversion could not be done\n const conversionDidNotWork = isEqual(latexToConvert, mathMlFromLatex);\n\n mathMlFromLatex = removeEmptyMos(mathMlFromLatex);\n\n // we convert resulted mathml to latex to check if the resulted mathMl can be converted back to latex if user wants to edit it later\n const latexFromMathMl = mathMlFromLatex ? mmlToLatex(mathMlFromLatex) : '';\n\n // we need to remove all the spaces from the latex to be able to compare it\n const strippedL = latex.replace(/\\s/g, '');\n const strippedNewL = latexFromMathMl.replace(/\\s/g, '');\n\n // we check if the latex keeps his form after being converted to mathml and back to latex\n // if it does, we can safely convert it to mathml\n if (!isEqual(strippedL, strippedNewL)) {\n const correctedLatex = replaceLeftRight(latexFromMathMl);\n\n // As George requested in PD-3167, I will set the new mathML anyway, and also log differences\n // if it doesn't, we keep the latex version\n // eslint-disable-next-line no-console\n console.log('This latex can not be safely converted to mathml so we will keep the latex version!!!', {\n initialLatex: latex,\n newLatex: latexFromMathMl,\n correctedLatex,\n mathML: mathMlFromLatex,\n conversionDidNotWork,\n });\n }\n\n return { mathMlFromLatex, conversionDidNotWork };\n};\n\nconst convertMathMlToLatex = (mathMl) => {\n const htmlWithRemovedSpaces = mathMl.replaceAll('&nbsp;', ' ');\n const htmlToUse = mmlToLatex(htmlWithRemovedSpaces);\n const latex = htmlDecode(htmlToUse);\n\n // todo fix this in mathml-to-latex\n return replaceLeftRight(latex);\n};\n\nexport const serialization = {\n deserialize(el) {\n const tagName = getTagName(el);\n /**\n * This is used for when there's a wrapper over the mathml element.\n * Because of this slate rule: \"Only allow block nodes or inline and text nodes in blocks.\"\n * The element that contains only the mathml is removed (along with the math) because it has\n * an inline child and the block is of type block\n * This is for legacy content only since our math rendering is valid for the core slate rules\n */\n const hasMathChild = BLOCK_TAGS[tagName] && el.childNodes.length === 1 && getTagName(el.firstChild) === 'math';\n log('[deserialize] name: ', tagName);\n\n /**\n * This is here in order to be able to render mathml content\n */\n if (tagName === 'math' || (el.dataset && el.dataset.type === 'mathml') || hasMathChild) {\n const mathMl = hasMathChild ? el.innerHTML : el.outerHTML;\n\n if (MathPlugin.mathMlOptions.mmlEditing) {\n const { unwrapped, wrapType } = unWrapMath(convertMathMlToLatex(mathMl));\n\n return {\n object: 'inline',\n type: 'math',\n isVoid: true,\n nodes: [],\n data: {\n latex: unwrapped,\n wrapper: wrapType,\n },\n };\n }\n\n return {\n object: 'inline',\n isVoid: true,\n type: 'mathml',\n data: {\n html: mathMl,\n },\n };\n }\n\n if (el.nodeType === TEXT_NODE) {\n return;\n }\n\n if (tagName !== 'span') {\n return;\n }\n\n const hasLatex = el.hasAttribute('data-latex') || el.hasAttribute('latex');\n\n if (hasLatex) {\n const latex = htmlDecode(el.innerHTML);\n const { unwrapped, wrapType } = unWrapMath(latex);\n log('[deserialize]: noBrackets: ', unwrapped, wrapType);\n return {\n object: 'inline',\n type: 'math',\n isVoid: true,\n nodes: [],\n data: {\n latex: unwrapped,\n wrapper: wrapType,\n },\n };\n }\n },\n serialize(object) {\n if (object.type === 'math') {\n const latex = object.data.get('latex');\n const wrapper = object.data.get('wrapper');\n const decoded = htmlDecode(arrowHandlingCase(latex));\n\n log('[serialize] latex: ', latex);\n\n if (MathPlugin.mathMlOptions.mmlOutput) {\n const { mathMlFromLatex, conversionDidNotWork } = convertLatexToMathMl({ latex, decoded, wrapper });\n\n if (conversionDidNotWork) {\n // this means we could not convert latex to mathMl, so just return the latex version,\n // same as we would do if mmlOutput would not be enabled\n return (\n <span data-latex=\"\" data-raw={decoded}>\n {wrapMath(decoded, wrapper)}\n </span>\n );\n }\n\n return <span data-type=\"mathml\" dangerouslySetInnerHTML={{ __html: mathMlFromLatex }} />;\n }\n\n return (\n <span data-latex=\"\" data-raw={decoded}>\n {wrapMath(decoded, wrapper)}\n </span>\n );\n }\n\n /**\n * Here for rendering mathml content\n */\n if (object.type === 'mathml') {\n const html = object.data.get('html');\n\n return <span data-type=\"mathml\"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