@seafile/sdoc-editor 3.0.271 → 3.0.273

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.
@@ -7,42 +7,54 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports["default"] = void 0;
8
8
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/slicedToArray"));
9
9
  var _react = require("react");
10
+ var mathJaxUsers = 0;
10
11
  var useMathJax = function useMathJax(mathJaxSource) {
11
12
  var _useState = (0, _react.useState)(true),
12
13
  _useState2 = (0, _slicedToArray2["default"])(_useState, 2),
13
14
  isLoading = _useState2[0],
14
15
  setIsLoading = _useState2[1];
15
16
  (0, _react.useEffect)(function () {
17
+ var _window$MathJax;
16
18
  if (!mathJaxSource) {
17
19
  setIsLoading(false);
18
20
  return;
19
21
  }
20
- window.MathJax = {
21
- options: {
22
- enableMenu: false
23
- },
24
- tex: {
25
- inlineMath: [['$', '$']],
26
- displayMath: [['$$', '$$']]
27
- },
28
- svg: {
29
- fontCache: 'global'
30
- }
31
- };
32
- if (!document.querySelector('#mathjax')) {
33
- var script = document.createElement('script');
22
+ mathJaxUsers += 1;
23
+ var script = document.getElementById('mathjax');
24
+ if (!script) {
25
+ window.MathJax = {
26
+ options: {
27
+ enableMenu: false
28
+ },
29
+ tex: {
30
+ inlineMath: [['$', '$']],
31
+ displayMath: [['$$', '$$']]
32
+ },
33
+ svg: {
34
+ fontCache: 'global'
35
+ }
36
+ };
37
+ script = document.createElement('script');
34
38
  script.src = mathJaxSource;
35
39
  script.id = 'mathjax';
36
- document.body.appendChild(script);
37
- script.onload = function () {
38
- setIsLoading(false);
39
- };
40
- } else {
40
+ }
41
+ var onLoad = function onLoad() {
42
+ return setIsLoading(false);
43
+ };
44
+ if (typeof ((_window$MathJax = window.MathJax) === null || _window$MathJax === void 0 ? void 0 : _window$MathJax.tex2svg) === 'function') {
41
45
  setIsLoading(false);
46
+ } else {
47
+ script.addEventListener('load', onLoad);
42
48
  }
49
+ if (!script.isConnected) document.body.appendChild(script);
43
50
  return function () {
44
- var script = document.getElementById('mathjax');
45
- script && script.parentNode.removeChild(script);
51
+ var _document$getElementB;
52
+ script.removeEventListener('load', onLoad);
53
+ mathJaxUsers -= 1;
54
+ // Other editors and viewers may still reference the shared glyph cache.
55
+ if (mathJaxUsers > 0) return;
56
+ script.remove();
57
+ (_document$getElementB = document.getElementById('MJX-SVG-global-cache')) === null || _document$getElementB === void 0 ? void 0 : _document$getElementB.remove();
46
58
  };
47
59
  // eslint-disable-next-line react-hooks/exhaustive-deps
48
60
  }, []);
@@ -67,6 +67,7 @@ var PublishedRevisionDiffViewer = function PublishedRevisionDiffViewer(_ref) {
67
67
  elements: isShowChanges && (diff === null || diff === void 0 ? void 0 : diff.value) || revisionContent.elements
68
68
  };
69
69
  return /*#__PURE__*/_react["default"].createElement(_sdocViewer["default"], {
70
+ mathJaxSource: mathJaxSource,
70
71
  document: document,
71
72
  showToolbar: true,
72
73
  showOutline: true,
@@ -60,6 +60,7 @@ var RevisionDiffViewer = function RevisionDiffViewer(_ref) {
60
60
  return /*#__PURE__*/_react["default"].createElement(_loading["default"], null);
61
61
  }
62
62
  return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_sdocViewer["default"], {
63
+ mathJaxSource: mathJaxSource,
63
64
  editor: editor,
64
65
  document: {
65
66
  elements: diff.value
@@ -34,6 +34,7 @@ var DiffViewer = function DiffViewer(_ref) {
34
34
  }, []);
35
35
  if (isLoadingMathJax) return;
36
36
  return /*#__PURE__*/_react["default"].createElement(_sdocViewer["default"], {
37
+ mathJaxSource: mathJaxSource,
37
38
  document: {
38
39
  elements: diff.value
39
40
  },
@@ -33,17 +33,12 @@ var SDocViewer = function SDocViewer(_ref) {
33
33
  showComment = _ref$showComment === void 0 ? false : _ref$showComment,
34
34
  _ref$plugins = _ref.plugins,
35
35
  plugins = _ref$plugins === void 0 ? [] : _ref$plugins,
36
- _ref$enableMathJax = _ref.enableMathJax,
37
- enableMathJax = _ref$enableMathJax === void 0 ? false : _ref$enableMathJax,
38
36
  _ref$mathJaxSource = _ref.mathJaxSource,
39
37
  mathJaxSource = _ref$mathJaxSource === void 0 ? _constants.MATH_JAX_SOURCE_RUL : _ref$mathJaxSource,
40
38
  _ref$isDiffView = _ref.isDiffView,
41
39
  isDiffView = _ref$isDiffView === void 0 ? false : _ref$isDiffView;
42
- // eslint-disable-next-line react-hooks/rules-of-hooks
43
- var _ref2 = enableMathJax ? (0, _useMathjax["default"])(mathJaxSource) : {
44
- isLoadingMathJax: false
45
- },
46
- isLoadingMathJax = _ref2.isLoadingMathJax;
40
+ var _useMathJax = (0, _useMathjax["default"])(mathJaxSource),
41
+ isLoadingMathJax = _useMathJax.isLoadingMathJax;
47
42
  if (!_context["default"].api) {
48
43
  _context["default"].initApi();
49
44
  }
@@ -62,7 +57,7 @@ var SDocViewer = function SDocViewer(_ref) {
62
57
  };
63
58
  // eslint-disable-next-line react-hooks/exhaustive-deps
64
59
  }, []);
65
- if (enableMathJax && isLoadingMathJax) {
60
+ if (isLoadingMathJax) {
66
61
  return /*#__PURE__*/_react["default"].createElement(_loading["default"], null);
67
62
  }
68
63
  return /*#__PURE__*/_react["default"].createElement(Provider, null, /*#__PURE__*/_react["default"].createElement(_usePlugins.PluginsProvider, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seafile/sdoc-editor",
3
- "version": "3.0.271",
3
+ "version": "3.0.273",
4
4
  "main": "dist/index.js",
5
5
  "scripts": {
6
6
  "test": "jest",
@@ -19,7 +19,7 @@
19
19
  "dependencies": {
20
20
  "@seafile/comment-editor": "1.0.34",
21
21
  "@seafile/print-js": "1.6.6",
22
- "@seafile/react-image-lightbox": "^5.0.10",
22
+ "@seafile/react-image-lightbox": "^5.0.83",
23
23
  "@seafile/slate": "0.91.8",
24
24
  "@seafile/slate-history": "0.86.2",
25
25
  "@seafile/slate-hyperscript": "0.81.7",
@@ -70,5 +70,5 @@
70
70
  "publishConfig": {
71
71
  "access": "public"
72
72
  },
73
- "gitHead": "17ee60b83169bf934370d9c7293b2f640c636677"
73
+ "gitHead": "63e68f667a444f26d7ba15d5ec0a8cdaf190980a"
74
74
  }