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

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