@pie-lib/editable-html 11.15.0 → 11.17.0-hotfix.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.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,30 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [11.17.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/editable-html@11.1.1...@pie-lib/editable-html@11.17.0) (2025-09-25)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * fixed pie-lib/icons import [PD-5126] ([dcb506c](https://github.com/pie-framework/pie-lib/commit/dcb506c914a177f6d88bf73247a023bfe71dac1f))
12
+
13
+
14
+ ### Features
15
+
16
+ * split pie-toolbox into multiple packages [PD-5126] ([7d55a25](https://github.com/pie-framework/pie-lib/commit/7d55a2552d084cd3d0d5c00dc77411b2ced2f5e2))
17
+
18
+
19
+
20
+
21
+
22
+ # [11.16.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/editable-html@11.15.0...@pie-lib/editable-html@11.16.0) (2025-09-18)
23
+
24
+ **Note:** Version bump only for package @pie-lib/editable-html
25
+
26
+
27
+
28
+
29
+
6
30
  # [11.15.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/editable-html@11.14.0...@pie-lib/editable-html@11.15.0) (2025-09-18)
7
31
 
8
32
  **Note:** Version bump only for package @pie-lib/editable-html
package/lib/editor.js CHANGED
@@ -67,7 +67,7 @@ var _styles = require("@material-ui/core/styles");
67
67
 
68
68
  var _renderUi = require("@pie-lib/render-ui");
69
69
 
70
- var _alertDialog = _interopRequireDefault(require("./shared/alert-dialog"));
70
+ var _alertDialog = _interopRequireDefault(require("../../config-ui/src/alert-dialog"));
71
71
 
72
72
  var serialization = _interopRequireWildcard(require("./serialization"));
73
73
 
@@ -19,7 +19,7 @@ var _slate = require("slate");
19
19
 
20
20
  var _mathToolbar = require("@pie-lib/math-toolbar");
21
21
 
22
- var _mathRendering = require("@pie-lib/math-rendering");
22
+ var _renderMathBundled = require("@pie-lib/render-math-bundled");
23
23
 
24
24
  var _react = _interopRequireDefault(require("react"));
25
25
 
@@ -276,16 +276,16 @@ var convertLatexToMathMl = function convertLatexToMathMl(_ref4) {
276
276
  };
277
277
 
278
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
279
+ var latexToConvert = "<span data-latex=\"\" data-raw=\"".concat(handled, "\">").concat((0, _renderMathBundled.wrapMath)(handled, wrapper), "</span>"); // use math rendering (MathJax) to convert latex to mathMl
280
280
 
281
- var mathMlFromLatex = (0, _mathRendering.renderMath)(latexToConvert, {
281
+ var mathMlFromLatex = (0, _renderMathBundled.renderMath)(latexToConvert, {
282
282
  skipWaitForMathRenderingLib: true
283
283
  }); // if renderMath returned the exact same string that we sent, it just means that the conversion could not be done
284
284
 
285
285
  var conversionDidNotWork = (0, _isEqual["default"])(latexToConvert, mathMlFromLatex);
286
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
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
288
+ var latexFromMathMl = mathMlFromLatex ? (0, _renderMathBundled.mmlToLatex)(mathMlFromLatex) : ''; // we need to remove all the spaces from the latex to be able to compare it
289
289
 
290
290
  var strippedL = latex.replace(/\s/g, '');
291
291
  var strippedNewL = latexFromMathMl.replace(/\s/g, ''); // we check if the latex keeps his form after being converted to mathml and back to latex
@@ -313,7 +313,7 @@ var convertLatexToMathMl = function convertLatexToMathMl(_ref4) {
313
313
 
314
314
  var convertMathMlToLatex = function convertMathMlToLatex(mathMl) {
315
315
  var htmlWithRemovedSpaces = mathMl.replaceAll('&nbsp;', ' ');
316
- var htmlToUse = (0, _mathRendering.mmlToLatex)(htmlWithRemovedSpaces);
316
+ var htmlToUse = (0, _renderMathBundled.mmlToLatex)(htmlWithRemovedSpaces);
317
317
  var latex = htmlDecode(htmlToUse); // todo fix this in mathml-to-latex
318
318
 
319
319
  return replaceLeftRight(latex);
@@ -340,7 +340,7 @@ var serialization = {
340
340
  var mathMl = hasMathChild ? el.innerHTML : el.outerHTML;
341
341
 
342
342
  if (MathPlugin.mathMlOptions.mmlEditing) {
343
- var _unWrapMath = (0, _mathRendering.unWrapMath)(convertMathMlToLatex(mathMl)),
343
+ var _unWrapMath = (0, _renderMathBundled.unWrapMath)(convertMathMlToLatex(mathMl)),
344
344
  unwrapped = _unWrapMath.unwrapped,
345
345
  wrapType = _unWrapMath.wrapType;
346
346
 
@@ -379,7 +379,7 @@ var serialization = {
379
379
  if (hasLatex) {
380
380
  var latex = htmlDecode(el.innerHTML);
381
381
 
382
- var _unWrapMath2 = (0, _mathRendering.unWrapMath)(latex),
382
+ var _unWrapMath2 = (0, _renderMathBundled.unWrapMath)(latex),
383
383
  _unwrapped = _unWrapMath2.unwrapped,
384
384
  _wrapType = _unWrapMath2.wrapType;
385
385
 
@@ -418,7 +418,7 @@ var serialization = {
418
418
  return /*#__PURE__*/_react["default"].createElement("span", {
419
419
  "data-latex": "",
420
420
  "data-raw": decoded
421
- }, (0, _mathRendering.wrapMath)(decoded, wrapper));
421
+ }, (0, _renderMathBundled.wrapMath)(decoded, wrapper));
422
422
  }
423
423
 
424
424
  return /*#__PURE__*/_react["default"].createElement("span", {
@@ -432,7 +432,7 @@ var serialization = {
432
432
  return /*#__PURE__*/_react["default"].createElement("span", {
433
433
  "data-latex": "",
434
434
  "data-raw": decoded
435
- }, (0, _mathRendering.wrapMath)(decoded, wrapper));
435
+ }, (0, _renderMathBundled.wrapMath)(decoded, wrapper));
436
436
  }
437
437
  /**
438
438
  * Here for rendering mathml content
@@ -1 +1 @@
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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yBA,oBAAzB;;AAEA,YAAIA,oBAAJ,EAA0B;AACxB;AACA;AACA,8BACE;AAAM,0BAAW,EAAjB;AAAoB,wBAAUT;AAA9B,aACG,6BAASA,OAAT,EAAkBC,OAAlB,CADH,CADF;AAKD;;AAED,4BAAO;AAAM,uBAAU,QAAhB;AAAyB,UAAA,uBAAuB,EAAE;AAAEzB,YAAAA,MAAM,EAAE+B;AAAV;AAAlD,UAAP;AACD;;AAED,0BACE;AAAM,sBAAW,EAAjB;AAAoB,oBAAUP;AAA9B,SACG,6BAASA,OAAT,EAAkBC,OAAlB,CADH,CADF;AAKD;AAED;AACJ;AACA;;;AACI,QAAIrC,MAAM,CAACC,IAAP,KAAgB,QAApB,EAA8B;AAC5B,UAAMS,IAAI,GAAGV,MAAM,CAACtC,IAAP,CAAYY,GAAZ,CAAgB,MAAhB,CAAb;AAEA,0BAAO;AAAM,qBAAU,QAAhB;AAAyB,QAAA,uBAAuB,EAAE;AAAEsC,UAAAA,MAAM,EAAEF;AAAV;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"}
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,IAAI,EAAhC;AAAA,MAAQC,IAAR,SAAQA,IAAR;;AACA,cAAgEA,IAAI,IAAI,EAAxE;AAAA,MAAQC,UAAR,SA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review, MathToolbar } from '@pie-lib/math-toolbar';\nimport { wrapMath, unWrapMath, mmlToLatex, renderMath } from '@pie-lib/render-math-bundled';\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"}
@@ -33,7 +33,7 @@ var _drag = require("@pie-lib/drag");
33
33
 
34
34
  var _renderUi = require("@pie-lib/render-ui");
35
35
 
36
- var _mathRendering = require("@pie-lib/math-rendering");
36
+ var _renderMathBundled = require("@pie-lib/render-math-bundled");
37
37
 
38
38
  var _styles = require("@material-ui/core/styles");
39
39
 
@@ -122,8 +122,8 @@ var BlankContent = /*#__PURE__*/function (_React$Component) {
122
122
  }, {
123
123
  key: "componentDidUpdate",
124
124
  value: function componentDidUpdate(prevProps, prevState, snapshot) {
125
- if (this.elementRef && typeof _mathRendering.renderMath === 'function') {
126
- (0, _mathRendering.renderMath)(this.elementRef);
125
+ if (this.elementRef && typeof _renderMathBundled.renderMath === 'function') {
126
+ (0, _renderMathBundled.renderMath)(this.elementRef);
127
127
  }
128
128
 
129
129
  if (snapshot && (!this.state.hoveredElementSize || this.state.hoveredElementSize.width !== snapshot.width || this.state.hoveredElementSize.height !== snapshot.height)) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/plugins/respArea/drag-in-the-blank/choice.jsx"],"names":["useStyles","theme","content","border","palette","primary","main","fontSize","chip","minWidth","correct","color","incorrect","error","selected","primaryDark","BlankContent","props","handleClick","bind","state","hoveredElementSize","document","addEventListener","removeEventListener","event","classes","elementRef","className","contains","target","prevProps","isOver","node","width","offsetWidth","height","offsetHeight","prevState","snapshot","renderMath","setState","n","children","isDragging","dragItem","value","label","finalLabel","hasGrip","isPreview","ref","display","minHeight","background","defaults","BORDER_LIGHT","WHITE","BORDER_DARK","boxSizing","borderRadius","overflow","position","padding","undefined","key","top","left","__html","React","Component","PropTypes","object","func","bool","StyledBlankContent","connectedBlankContent","connectDropTarget","connectDragSource","dragContent","dragEl","over","tileTarget","drop","monitor","draggedItem","getItem","shouldDrop","index","onChange","dropped","canDrop","instanceId","DropTile","connect","dropTarget","shallow","tileSource","canDrag","disabled","beginDrag","id","targetId","fromChoice","endDrag","dropResult","getDropResult","duplicates","removeResponse","dragSource"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAEA;;;;;;;;AAEA,IAAMA,SAAS,GAAG,wBAAW,UAACC,KAAD;AAAA,SAAY;AACvCC,IAAAA,OAAO,EAAE;AACPC,MAAAA,MAAM,sBAAeF,KAAK,CAACG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V,qBAJa,CAAjB;AAMO,IAAMqB,UAAU,GAAG;AACxBC,EAAAA,OADwB,mBAChBjF,KADgB,EACT;AACb,WAAO,CAACA,KAAK,CAACkF,QAAP,IAAmB,CAAC,CAAClF,KAAK,CAAC6B,KAAlC;AACD,GAHuB;AAIxBsD,EAAAA,SAJwB,qBAIdnF,KAJc,EAIP;AACf,WAAO;AACLoF,MAAAA,EAAE,EAAEpF,KAAK,CAACqF,QADL;AAELxD,MAAAA,KAAK,EAAE7B,KAAK,CAAC6B,KAFR;AAGL8C,MAAAA,UAAU,EAAE3E,KAAK,CAAC2E,UAHb;AAILW,MAAAA,UAAU,EAAE;AAJP,KAAP;AAMD,GAXuB;AAYxBC,EAAAA,OAZwB,mBAYhBvF,KAZgB,EAYTmE,OAZS,EAYA;AACtB;AACA,QAAMqB,UAAU,GAAGrB,OAAO,CAACsB,aAAR,EAAnB;;AAEA,QAAI,CAACD,UAAD,IAAgBA,UAAU,CAACf,OAAX,IAAsB,CAACzE,KAAK,CAAC0F,UAAjD,EAA8D;AAC5D,UAAMtB,WAAW,GAAGD,OAAO,CAACE,OAAR,EAApB;;AAEA,UAAID,WAAW,CAACkB,UAAhB,EAA4B;AAC1BtF,QAAAA,KAAK,CAAC2F,cAAN,CAAqBvB,WAAW,CAACvC,KAAjC;AACD;AACF;AACF;AAvBuB,CAAnB;;;eA0BQ,sBAAW,0BAAX,EAAuCmD,UAAvC,EAAmD,UAACH,OAAD,EAAUV,OAAV;AAAA,SAAuB;AACvFN,IAAAA,iBAAiB,EAAEgB,OAAO,CAACe,UAAR,EADoE;AAEvFjE,IAAAA,UAAU,EAAEwC,OAAO,CAACxC,UAAR;AAF2E,GAAvB;AAAA,CAAnD,EAGXiD,QAHW,C","sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\nimport isUndefined from 'lodash/isUndefined';\nimport { DragSource, DropTarget } from '@pie-lib/drag';\nimport { color } from '@pie-lib/render-ui';\nimport { renderMath } from '@pie-lib/math-rendering';\nimport { withStyles } from '@material-ui/core/styles';\nimport classnames from 'classnames';\n\nimport { GripIcon } from '../icons';\n\nconst useStyles = withStyles((theme) => ({\n content: {\n border: `solid 0px ${theme.palette.primary.main}`,\n '& mjx-frac': {\n fontSize: '120% !important',\n },\n },\n chip: {\n minWidth: '90px',\n },\n correct: {\n border: `solid 1px ${color.correct()}`,\n },\n incorrect: {\n border: `solid 1px ${theme.palette.error.main}`,\n },\n selected: {\n border: `2px solid ${color.primaryDark()} !important`,\n },\n}));\n\nexport class BlankContent extends React.Component {\n static propTypes = {\n n: PropTypes.object,\n children: PropTypes.func,\n isDragging: PropTypes.bool,\n isOver: PropTypes.bool,\n dragItem: PropTypes.object,\n value: PropTypes.object,\n classes: PropTypes.object,\n };\n\n constructor(props) {\n super(props);\n\n this.handleClick = this.handleClick.bind(this);\n this.state = { hoveredElementSize: null };\n }\n\n componentDidMount() {\n document.addEventListener('click', this.handleClick);\n }\n\n componentWillUnmount() {\n document.removeEventListener('click', this.handleClick);\n }\n\n handleClick(event) {\n const { classes } = this.props;\n\n if (this.elementRef) {\n this.elementRef.className = this.elementRef.contains(event.target) ? classes.selected : '';\n }\n }\n\n getSnapshotBeforeUpdate(prevProps) {\n if (!prevProps.isOver && this.props.isOver && this.elementRef) {\n const node = this.elementRef;\n return { width: node.offsetWidth, height: node.offsetHeight };\n }\n return null;\n }\n\n componentDidUpdate(prevProps, prevState, snapshot) {\n if (this.elementRef && typeof renderMath === 'function') {\n renderMath(this.elementRef);\n }\n\n if (\n snapshot &&\n (!this.state.hoveredElementSize ||\n this.state.hoveredElementSize.width !== snapshot.width ||\n this.state.hoveredElementSize.height !== snapshot.height)\n ) {\n this.setState({ hoveredElementSize: snapshot });\n return;\n }\n\n if (prevProps.isOver && !this.props.isOver && this.state.hoveredElementSize) {\n this.setState({ hoveredElementSize: null });\n }\n }\n\n render() {\n const { n, children, isDragging, dragItem, isOver, value } = this.props;\n const { hoveredElementSize } = this.state;\n\n const label = dragItem && isOver ? dragItem.value.value : value.value || '\\u00A0';\n const finalLabel = isDragging ? '\\u00A0' : label;\n const hasGrip = finalLabel !== '\\u00A0';\n const isPreview = dragItem && isOver;\n\n return (\n <div\n ref={(ref) => (this.elementRef = ref)}\n style={{\n display: 'inline-flex',\n minWidth: '178px',\n minHeight: '36px',\n background: isPreview ? `${color.defaults.BORDER_LIGHT}` : `${color.defaults.WHITE}`,\n border: isPreview ? `1px solid ${color.defaults.BORDER_DARK}` : `1px solid ${color.defaults.BORDER_LIGHT}`,\n boxSizing: 'border-box',\n borderRadius: '3px',\n overflow: 'hidden',\n position: 'relative',\n padding: '8px 8px 8px 35px',\n width: hoveredElementSize ? hoveredElementSize.width : undefined,\n height: hoveredElementSize ? hoveredElementSize.height : undefined,\n }}\n data-key={n.key}\n contentEditable={false}\n >\n {hasGrip && (\n <GripIcon\n style={{\n position: 'absolute',\n top: '6px',\n left: '15px',\n color: '#9B9B9B',\n }}\n contentEditable={false}\n />\n )}\n <span\n dangerouslySetInnerHTML={{\n __html: finalLabel,\n }}\n />\n {children}\n </div>\n );\n }\n}\n\nconst StyledBlankContent = useStyles(BlankContent);\n\nconst connectedBlankContent = useStyles(({ connectDropTarget, connectDragSource, ...props }) => {\n const { classes, isOver, value } = props;\n const dragContent = <StyledBlankContent {...props} />;\n const dragEl = !value ? dragContent : connectDragSource(<span>{dragContent}</span>);\n const content = <span className={classnames(classes.content, isOver && classes.over)}>{dragEl}</span>;\n\n return connectDropTarget ? connectDropTarget(content) : content;\n});\n\nexport const tileTarget = {\n drop(props, monitor) {\n const draggedItem = monitor.getItem();\n const shouldDrop =\n isUndefined(draggedItem.value.index) ||\n isUndefined(props.value.index) ||\n draggedItem.value.index !== props.value.index;\n\n if (shouldDrop) {\n props.onChange(draggedItem.value);\n }\n\n return {\n dropped: shouldDrop,\n };\n },\n canDrop(props, monitor) {\n const draggedItem = monitor.getItem();\n\n return draggedItem.instanceId === props.instanceId;\n },\n};\n\nconst DropTile = DropTarget('drag-in-the-blank-choice', tileTarget, (connect, monitor) => ({\n connectDropTarget: connect.dropTarget(),\n isOver: monitor.isOver({ shallow: true }),\n dragItem: monitor.getItem(),\n}))(connectedBlankContent);\n\nexport const tileSource = {\n canDrag(props) {\n return !props.disabled && !!props.value;\n },\n beginDrag(props) {\n return {\n id: props.targetId,\n value: props.value,\n instanceId: props.instanceId,\n fromChoice: true,\n };\n },\n endDrag(props, monitor) {\n // this will be null if it did not drop\n const dropResult = monitor.getDropResult();\n\n if (!dropResult || (dropResult.dropped && !props.duplicates)) {\n const draggedItem = monitor.getItem();\n\n if (draggedItem.fromChoice) {\n props.removeResponse(draggedItem.value);\n }\n }\n },\n};\n\nexport default DragSource('drag-in-the-blank-choice', tileSource, (connect, monitor) => ({\n connectDragSource: connect.dragSource(),\n isDragging: monitor.isDragging(),\n}))(DropTile);\n"],"file":"choice.js"}
1
+ {"version":3,"sources":["../../../../src/plugins/respArea/drag-in-the-blank/choice.jsx"],"names":["useStyles","theme","content","border","palette","primary","main","fontSize","chip","minWidth","correct","color","incorrect","error","selected","primaryDark","BlankContent","props","handleClick","bind","state","hoveredElementSize","document","addEventListener","removeEventListener","event","classes","elementRef","className","contains","target","prevProps","isOver","node","width","offsetWidth","height","offsetHeight","prevState","snapshot","renderMath","setState","n","children","isDragging","dragItem","value","label","finalLabel","hasGrip","isPreview","ref","display","minHeight","background","defaults","BORDER_LIGHT","WHITE","BORDER_DARK","boxSizing","borderRadius","overflow","position","padding","undefined","key","top","left","__html","React","Component","PropTypes","object","func","bool","StyledBlankContent","connectedBlankContent","connectDropTarget","connectDragSource","dragContent","dragEl","over","tileTarget","drop","monitor","draggedItem","getItem","shouldDrop","index","onChange","dropped","canDrop","instanceId","DropTile","connect","dropTarget","shallow","tileSource","canDrag","disabled","beginDrag","id","targetId","fromChoice","endDrag","dropResult","getDropResult","duplicates","removeResponse","dragSource"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AA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ropTypes from 'prop-types';\nimport isUndefined from 'lodash/isUndefined';\nimport { DragSource, DropTarget } from '@pie-lib/drag';\nimport { color } from '@pie-lib/render-ui';\nimport { renderMath } from '@pie-lib/render-math-bundled';\nimport { withStyles } from '@material-ui/core/styles';\nimport classnames from 'classnames';\n\nimport { GripIcon } from '../icons';\n\nconst useStyles = withStyles((theme) => ({\n content: {\n border: `solid 0px ${theme.palette.primary.main}`,\n '& mjx-frac': {\n fontSize: '120% !important',\n },\n },\n chip: {\n minWidth: '90px',\n },\n correct: {\n border: `solid 1px ${color.correct()}`,\n },\n incorrect: {\n border: `solid 1px ${theme.palette.error.main}`,\n },\n selected: {\n border: `2px solid ${color.primaryDark()} !important`,\n },\n}));\n\nexport class BlankContent extends React.Component {\n static propTypes = {\n n: PropTypes.object,\n children: PropTypes.func,\n isDragging: PropTypes.bool,\n isOver: PropTypes.bool,\n dragItem: PropTypes.object,\n value: PropTypes.object,\n classes: PropTypes.object,\n };\n\n constructor(props) {\n super(props);\n\n this.handleClick = this.handleClick.bind(this);\n this.state = { hoveredElementSize: null };\n }\n\n componentDidMount() {\n document.addEventListener('click', this.handleClick);\n }\n\n componentWillUnmount() {\n document.removeEventListener('click', this.handleClick);\n }\n\n handleClick(event) {\n const { classes } = this.props;\n\n if (this.elementRef) {\n this.elementRef.className = this.elementRef.contains(event.target) ? classes.selected : '';\n }\n }\n\n getSnapshotBeforeUpdate(prevProps) {\n if (!prevProps.isOver && this.props.isOver && this.elementRef) {\n const node = this.elementRef;\n return { width: node.offsetWidth, height: node.offsetHeight };\n }\n return null;\n }\n\n componentDidUpdate(prevProps, prevState, snapshot) {\n if (this.elementRef && typeof renderMath === 'function') {\n renderMath(this.elementRef);\n }\n\n if (\n snapshot &&\n (!this.state.hoveredElementSize ||\n this.state.hoveredElementSize.width !== snapshot.width ||\n this.state.hoveredElementSize.height !== snapshot.height)\n ) {\n this.setState({ hoveredElementSize: snapshot });\n return;\n }\n\n if (prevProps.isOver && !this.props.isOver && this.state.hoveredElementSize) {\n this.setState({ hoveredElementSize: null });\n }\n }\n\n render() {\n const { n, children, isDragging, dragItem, isOver, value } = this.props;\n const { hoveredElementSize } = this.state;\n\n const label = dragItem && isOver ? dragItem.value.value : value.value || '\\u00A0';\n const finalLabel = isDragging ? '\\u00A0' : label;\n const hasGrip = finalLabel !== '\\u00A0';\n const isPreview = dragItem && isOver;\n\n return (\n <div\n ref={(ref) => (this.elementRef = ref)}\n style={{\n display: 'inline-flex',\n minWidth: '178px',\n minHeight: '36px',\n background: isPreview ? `${color.defaults.BORDER_LIGHT}` : `${color.defaults.WHITE}`,\n border: isPreview ? `1px solid ${color.defaults.BORDER_DARK}` : `1px solid ${color.defaults.BORDER_LIGHT}`,\n boxSizing: 'border-box',\n borderRadius: '3px',\n overflow: 'hidden',\n position: 'relative',\n padding: '8px 8px 8px 35px',\n width: hoveredElementSize ? hoveredElementSize.width : undefined,\n height: hoveredElementSize ? hoveredElementSize.height : undefined,\n }}\n data-key={n.key}\n contentEditable={false}\n >\n {hasGrip && (\n <GripIcon\n style={{\n position: 'absolute',\n top: '6px',\n left: '15px',\n color: '#9B9B9B',\n }}\n contentEditable={false}\n />\n )}\n <span\n dangerouslySetInnerHTML={{\n __html: finalLabel,\n }}\n />\n {children}\n </div>\n );\n }\n}\n\nconst StyledBlankContent = useStyles(BlankContent);\n\nconst connectedBlankContent = useStyles(({ connectDropTarget, connectDragSource, ...props }) => {\n const { classes, isOver, value } = props;\n const dragContent = <StyledBlankContent {...props} />;\n const dragEl = !value ? dragContent : connectDragSource(<span>{dragContent}</span>);\n const content = <span className={classnames(classes.content, isOver && classes.over)}>{dragEl}</span>;\n\n return connectDropTarget ? connectDropTarget(content) : content;\n});\n\nexport const tileTarget = {\n drop(props, monitor) {\n const draggedItem = monitor.getItem();\n const shouldDrop =\n isUndefined(draggedItem.value.index) ||\n isUndefined(props.value.index) ||\n draggedItem.value.index !== props.value.index;\n\n if (shouldDrop) {\n props.onChange(draggedItem.value);\n }\n\n return {\n dropped: shouldDrop,\n };\n },\n canDrop(props, monitor) {\n const draggedItem = monitor.getItem();\n\n return draggedItem.instanceId === props.instanceId;\n },\n};\n\nconst DropTile = DropTarget('drag-in-the-blank-choice', tileTarget, (connect, monitor) => ({\n connectDropTarget: connect.dropTarget(),\n isOver: monitor.isOver({ shallow: true }),\n dragItem: monitor.getItem(),\n}))(connectedBlankContent);\n\nexport const tileSource = {\n canDrag(props) {\n return !props.disabled && !!props.value;\n },\n beginDrag(props) {\n return {\n id: props.targetId,\n value: props.value,\n instanceId: props.instanceId,\n fromChoice: true,\n };\n },\n endDrag(props, monitor) {\n // this will be null if it did not drop\n const dropResult = monitor.getDropResult();\n\n if (!dropResult || (dropResult.dropped && !props.duplicates)) {\n const draggedItem = monitor.getItem();\n\n if (draggedItem.fromChoice) {\n props.removeResponse(draggedItem.value);\n }\n }\n },\n};\n\nexport default DragSource('drag-in-the-blank-choice', tileSource, (connect, monitor) => ({\n connectDragSource: connect.dragSource(),\n isDragging: monitor.isDragging(),\n}))(DropTile);\n"],"file":"choice.js"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pie-lib/editable-html",
3
- "version": "11.15.0",
3
+ "version": "11.17.0-hotfix.0",
4
4
  "description": "",
5
5
  "license": "ISC",
6
6
  "main": "lib/index.js",
@@ -10,11 +10,11 @@
10
10
  "@material-ui/core": "^3.8.3",
11
11
  "@material-ui/icons": "^3.0.2",
12
12
  "@material-ui/styles": "^3.0.0-alpha.10",
13
- "@pie-lib/drag": "^2.16.0",
14
- "@pie-lib/math-input": "^6.25.0",
15
- "@pie-lib/math-rendering": "^3.16.0",
16
- "@pie-lib/math-toolbar": "^1.25.0",
17
- "@pie-lib/render-ui": "^4.29.0",
13
+ "@pie-lib/drag": "2.18.0-hotfix.0",
14
+ "@pie-lib/math-input": "^6.27.0",
15
+ "@pie-lib/render-math-bundled": "3.18.0-hotfix.0",
16
+ "@pie-lib/math-toolbar": "^1.27.0",
17
+ "@pie-lib/render-ui": "4.31.0-hotfix.0",
18
18
  "change-case": "^3.0.2",
19
19
  "classnames": "^2.2.6",
20
20
  "debug": "^4.1.1",
@@ -48,6 +48,6 @@
48
48
  "publishConfig": {
49
49
  "access": "public"
50
50
  },
51
- "gitHead": "fea8f3ab465ceb72406e9c66902b172c037583c6",
51
+ "gitHead": "ff5ec2ebe11110b7652812a10c6dc230f08e12cb",
52
52
  "scripts": {}
53
53
  }
@@ -16,8 +16,8 @@ jest.mock('@pie-lib/math-toolbar', () => ({
16
16
  MathToolbar: () => <div />,
17
17
  }));
18
18
 
19
- jest.mock('@pie-lib/math-rendering', () => ({
20
- ...jest.requireActual('@pie-lib/math-rendering'),
19
+ jest.mock('@pie-lib/render-math-bundled', () => ({
20
+ ...jest.requireActual('@pie-lib/render-math-bundled'),
21
21
  mmlToLatex: jest.fn(() => {
22
22
  return '/foobar/latex';
23
23
  }),
@@ -1,7 +1,7 @@
1
1
  import Functions from '@material-ui/icons/Functions';
2
2
  import { Inline } from 'slate';
3
3
  import { MathPreview, MathToolbar } from '@pie-lib/math-toolbar';
4
- import { wrapMath, unWrapMath, mmlToLatex, renderMath } from '@pie-lib/math-rendering';
4
+ import { wrapMath, unWrapMath, mmlToLatex, renderMath } from '@pie-lib/render-math-bundled';
5
5
  import React from 'react';
6
6
  import debug from 'debug';
7
7
  import SlatePropTypes from 'slate-prop-types';
@@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
3
3
  import isUndefined from 'lodash/isUndefined';
4
4
  import { DragSource, DropTarget } from '@pie-lib/drag';
5
5
  import { color } from '@pie-lib/render-ui';
6
- import { renderMath } from '@pie-lib/math-rendering';
6
+ import { renderMath } from '@pie-lib/render-math-bundled';
7
7
  import { withStyles } from '@material-ui/core/styles';
8
8
  import classnames from 'classnames';
9
9
 
package/LICENSE.md DELETED
@@ -1,5 +0,0 @@
1
- Copyright 2019 CoreSpring Inc
2
-
3
- Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
4
-
5
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
@@ -1 +0,0 @@
1
- []
@@ -1,75 +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["default"] = void 0;
9
-
10
- var _react = _interopRequireDefault(require("react"));
11
-
12
- var _propTypes = _interopRequireDefault(require("prop-types"));
13
-
14
- var _core = require("@material-ui/core");
15
-
16
- var _styles = require("@material-ui/core/styles");
17
-
18
- var AlertDialog = function AlertDialog(_ref) {
19
- var text = _ref.text,
20
- title = _ref.title,
21
- onClose = _ref.onClose,
22
- onConfirm = _ref.onConfirm,
23
- open = _ref.open,
24
- onCloseText = _ref.onCloseText,
25
- onConfirmText = _ref.onConfirmText,
26
- classes = _ref.classes;
27
- return /*#__PURE__*/_react["default"].createElement(_core.Dialog, {
28
- open: open,
29
- onClose: onClose
30
- }, title && /*#__PURE__*/_react["default"].createElement(_core.DialogTitle, {
31
- className: classes.heading
32
- }, title), text && /*#__PURE__*/_react["default"].createElement(_core.DialogContent, null, /*#__PURE__*/_react["default"].createElement(_core.DialogContentText, {
33
- className: classes.subheading
34
- }, text)), /*#__PURE__*/_react["default"].createElement(_core.DialogActions, null, onClose && /*#__PURE__*/_react["default"].createElement(_core.Button, {
35
- onClick: onClose,
36
- color: "primary"
37
- }, onCloseText), onConfirm && /*#__PURE__*/_react["default"].createElement(_core.Button, {
38
- autoFocus: true,
39
- onClick: onConfirm,
40
- color: "primary"
41
- }, onConfirmText)));
42
- };
43
-
44
- AlertDialog.defaultProps = {
45
- onCloseText: 'CANCEL',
46
- onConfirmText: 'OK'
47
- };
48
- AlertDialog.propTypes = {
49
- text: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].object]),
50
- title: _propTypes["default"].string,
51
- onClose: _propTypes["default"].func,
52
- onConfirm: _propTypes["default"].func,
53
- open: _propTypes["default"].bool,
54
- onConfirmText: _propTypes["default"].string,
55
- onCloseText: _propTypes["default"].string,
56
- classes: _propTypes["default"].object
57
- };
58
-
59
- var styles = function styles() {
60
- return {
61
- heading: {
62
- '& h2': {
63
- fontSize: 'max(1.25rem, 18px)'
64
- }
65
- },
66
- subheading: {
67
- fontSize: 'max(1rem, 14px)'
68
- }
69
- };
70
- };
71
-
72
- var _default = (0, _styles.withStyles)(styles)(AlertDialog);
73
-
74
- exports["default"] = _default;
75
- //# sourceMappingURL=alert-dialog.js.map