@pie-lib/editable-html 11.4.0 → 11.6.0

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