dash-core-components 2.2.0 → 2.3.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.
@@ -17,6 +17,8 @@ var _graph = _interopRequireDefault(require("../utils/LazyLoader/graph"));
17
17
 
18
18
  var _plotly = _interopRequireDefault(require("../utils/LazyLoader/plotly"));
19
19
 
20
+ var _mathjax = _interopRequireDefault(require("../utils/LazyLoader/mathjax"));
21
+
20
22
  var _Graph = require("../fragments/Graph.privateprops");
21
23
 
22
24
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -84,6 +86,11 @@ var PlotlyGraph = /*#__PURE__*/function (_Component) {
84
86
  _classCallCheck(this, PlotlyGraph);
85
87
 
86
88
  _this = _super.call(this, props);
89
+
90
+ if (props.mathjax) {
91
+ PlotlyGraph._loadMathjax = true;
92
+ }
93
+
87
94
  _this.state = {
88
95
  prependData: [],
89
96
  extendData: []
@@ -178,9 +185,9 @@ var PlotlyGraph = /*#__PURE__*/function (_Component) {
178
185
  }(_react.Component);
179
186
 
180
187
  var RealPlotlyGraph = (0, _dashComponentPlugins.asyncDecorator)(PlotlyGraph, function () {
181
- return Promise.all([(0, _plotly.default)(), (0, _graph.default)()]).then(function (_ref2) {
182
- var _ref3 = _slicedToArray(_ref2, 2),
183
- graph = _ref3[1];
188
+ return Promise.all([(0, _graph.default)(), (0, _plotly.default)(), PlotlyGraph._loadMathjax ? (0, _mathjax.default)() : undefined]).then(function (_ref2) {
189
+ var _ref3 = _slicedToArray(_ref2, 1),
190
+ graph = _ref3[0];
184
191
 
185
192
  return graph;
186
193
  });
@@ -318,6 +325,11 @@ PlotlyGraph.propTypes = _objectSpread(_objectSpread({}, _Graph.privatePropTypes)
318
325
  */
319
326
  className: _propTypes.default.string,
320
327
 
328
+ /**
329
+ * If true, loads mathjax v3 (tex-svg) into the page and use it in the graph
330
+ */
331
+ mathjax: _propTypes.default.bool,
332
+
321
333
  /**
322
334
  * Beta: If true, animate between updates using
323
335
  * plotly.js's `animate` function
@@ -617,6 +629,7 @@ PlotlyGraph.defaultProps = _objectSpread(_objectSpread({}, _Graph.privateDefault
617
629
  frames: []
618
630
  },
619
631
  responsive: 'auto',
632
+ mathjax: false,
620
633
  animate: false,
621
634
  animation_options: {
622
635
  frame: {
@@ -7,18 +7,34 @@ Object.defineProperty(exports, "__esModule", {
7
7
  });
8
8
  exports.propTypes = exports.defaultProps = exports.default = void 0;
9
9
 
10
+ var _dashComponentPlugins = require("@plotly/dash-component-plugins");
11
+
10
12
  var _propTypes = _interopRequireDefault(require("prop-types"));
11
13
 
12
14
  var _react = _interopRequireWildcard(require("react"));
13
15
 
14
16
  var _markdown = _interopRequireDefault(require("../utils/LazyLoader/markdown"));
15
17
 
18
+ var _mathjax = _interopRequireDefault(require("../utils/LazyLoader/mathjax"));
19
+
16
20
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
17
21
 
18
22
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
19
23
 
20
24
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
25
 
26
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
27
+
28
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
29
+
30
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
31
+
32
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
33
+
34
+ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
35
+
36
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
37
+
22
38
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
23
39
 
24
40
  function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
@@ -39,23 +55,30 @@ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Re
39
55
 
40
56
  function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
41
57
 
42
- var RealDashMarkdown = /*#__PURE__*/(0, _react.lazy)(_markdown.default); // eslint-disable-next-line valid-jsdoc
58
+ // eslint-disable-next-line valid-jsdoc
43
59
 
44
60
  /**
45
61
  * A component that renders Markdown text as specified by the
46
62
  * GitHub Markdown spec. These component uses
47
63
  * [react-markdown](https://rexxars.github.io/react-markdown/) under the hood.
48
64
  */
49
-
50
65
  var DashMarkdown = /*#__PURE__*/function (_Component) {
51
66
  _inherits(DashMarkdown, _Component);
52
67
 
53
68
  var _super = _createSuper(DashMarkdown);
54
69
 
55
- function DashMarkdown() {
70
+ function DashMarkdown(props) {
71
+ var _this;
72
+
56
73
  _classCallCheck(this, DashMarkdown);
57
74
 
58
- return _super.apply(this, arguments);
75
+ _this = _super.call(this, props);
76
+
77
+ if (props.mathjax) {
78
+ DashMarkdown._loadMathjax = true;
79
+ }
80
+
81
+ return _this;
59
82
  }
60
83
 
61
84
  _createClass(DashMarkdown, [{
@@ -84,6 +107,11 @@ DashMarkdown.propTypes = {
84
107
  */
85
108
  className: _propTypes.default.string,
86
109
 
110
+ /**
111
+ * If true, loads mathjax v3 (tex-svg) into the page and use it in the markdown
112
+ */
113
+ mathjax: _propTypes.default.bool,
114
+
87
115
  /**
88
116
  * A boolean to control raw HTML escaping.
89
117
  * Setting HTML from code is risky because it's easy to
@@ -141,10 +169,19 @@ DashMarkdown.propTypes = {
141
169
  style: _propTypes.default.object
142
170
  };
143
171
  DashMarkdown.defaultProps = {
172
+ mathjax: false,
144
173
  dangerously_allow_html: false,
145
174
  highlight_config: {},
146
175
  dedent: true
147
176
  };
177
+ var RealDashMarkdown = (0, _dashComponentPlugins.asyncDecorator)(DashMarkdown, function () {
178
+ return Promise.all([(0, _markdown.default)(), DashMarkdown._loadMathjax ? (0, _mathjax.default)() : undefined]).then(function (_ref) {
179
+ var _ref2 = _slicedToArray(_ref, 1),
180
+ md = _ref2[0];
181
+
182
+ return md;
183
+ });
184
+ });
148
185
  var propTypes = DashMarkdown.propTypes;
149
186
  exports.propTypes = propTypes;
150
187
  var defaultProps = DashMarkdown.defaultProps;
@@ -5,6 +5,8 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
 
8
+ var _mathjax = _interopRequireDefault(require("../utils/LazyLoader/mathjax"));
9
+
8
10
  var _react = _interopRequireWildcard(require("react"));
9
11
 
10
12
  var _withPolyfill = _interopRequireDefault(require("react-resize-detector/build/withPolyfill"));
@@ -15,12 +17,12 @@ var _propTypes = _interopRequireDefault(require("prop-types"));
15
17
 
16
18
  var _Graph = require("../components/Graph.react");
17
19
 
18
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
-
20
20
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
21
21
 
22
22
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
23
23
 
24
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
25
+
24
26
  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; }
25
27
 
26
28
  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) { _defineProperty(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,8 +41,6 @@ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Sy
39
41
 
40
42
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
41
43
 
42
- function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
43
-
44
44
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
45
45
 
46
46
  function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
@@ -61,6 +61,8 @@ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Re
61
61
 
62
62
  function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
63
63
 
64
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
65
+
64
66
  /* global Plotly:true */
65
67
 
66
68
  /**
@@ -99,48 +101,64 @@ var filterEventData = function filterEventData(gd, eventData, event) {
99
101
  var filteredEventData;
100
102
 
101
103
  if ((0, _ramda.includes)(event, ['click', 'hover', 'selected'])) {
102
- var points = [];
104
+ var _ret = function () {
105
+ var points = [];
103
106
 
104
- if ((0, _ramda.isNil)(eventData)) {
105
- return null;
106
- }
107
- /*
108
- * remove `data`, `layout`, `xaxis`, etc
109
- * objects from the event data since they're so big
110
- * and cause JSON stringify ciricular structure errors.
111
- *
112
- * also, pull down the `customdata` point from the data array
113
- * into the event object
114
- */
115
-
116
-
117
- var data = gd.data;
107
+ if ((0, _ramda.isNil)(eventData)) {
108
+ return {
109
+ v: null
110
+ };
111
+ }
112
+ /*
113
+ * remove `data`, `layout`, `xaxis`, etc
114
+ * objects from the event data since they're so big
115
+ * and cause JSON stringify ciricular structure errors.
116
+ *
117
+ * also, pull down the `customdata` point from the data array
118
+ * into the event object
119
+ */
120
+
121
+
122
+ var data = gd.data;
123
+
124
+ var _loop = function _loop(i) {
125
+ var fullPoint = eventData.points[i];
126
+ var pointData = (0, _ramda.filter)(function (o) {
127
+ return !(0, _ramda.includes)((0, _ramda.type)(o), ['Object', 'Array']);
128
+ }, fullPoint); // permit a bounding box to pass through, if present
129
+
130
+ if ((0, _ramda.has)('bbox', fullPoint)) {
131
+ pointData.bbox = fullPoint.bbox;
132
+ }
118
133
 
119
- for (var i = 0; i < eventData.points.length; i++) {
120
- var fullPoint = eventData.points[i];
121
- var pointData = (0, _ramda.filter)(function (o) {
122
- return !(0, _ramda.includes)((0, _ramda.type)(o), ['Object', 'Array']);
123
- }, fullPoint); // permit a bounding box to pass through, if present
134
+ if ((0, _ramda.has)('curveNumber', fullPoint) && (0, _ramda.has)('customdata', data[pointData.curveNumber])) {
135
+ if ((0, _ramda.has)('pointNumber', fullPoint)) {
136
+ pointData.customdata = data[pointData.curveNumber].customdata[fullPoint.pointNumber];
137
+ } else if ((0, _ramda.has)('pointNumbers', fullPoint)) {
138
+ pointData.customdata = fullPoint.pointNumbers.map(function (point) {
139
+ return data[pointData.curveNumber].customdata[point];
140
+ });
141
+ }
142
+ } // specific to histogram. see https://github.com/plotly/plotly.js/pull/2113/
124
143
 
125
- if ((0, _ramda.has)('bbox', fullPoint)) {
126
- pointData.bbox = fullPoint.bbox;
127
- }
128
144
 
129
- if ((0, _ramda.has)('curveNumber', fullPoint) && (0, _ramda.has)('pointNumber', fullPoint) && (0, _ramda.has)('customdata', data[pointData.curveNumber])) {
130
- pointData.customdata = data[pointData.curveNumber].customdata[fullPoint.pointNumber];
131
- } // specific to histogram. see https://github.com/plotly/plotly.js/pull/2113/
145
+ if ((0, _ramda.has)('pointNumbers', fullPoint)) {
146
+ pointData.pointNumbers = fullPoint.pointNumbers;
147
+ }
132
148
 
149
+ points[i] = pointData;
150
+ };
133
151
 
134
- if ((0, _ramda.has)('pointNumbers', fullPoint)) {
135
- pointData.pointNumbers = fullPoint.pointNumbers;
152
+ for (var i = 0; i < eventData.points.length; i++) {
153
+ _loop(i);
136
154
  }
137
155
 
138
- points[i] = pointData;
139
- }
156
+ filteredEventData = {
157
+ points: points
158
+ };
159
+ }();
140
160
 
141
- filteredEventData = {
142
- points: points
143
- };
161
+ if (_typeof(_ret) === "object") return _ret.v;
144
162
  } else if (event === 'relayout' || event === 'restyle') {
145
163
  /*
146
164
  * relayout shouldn't include any big objects
@@ -206,23 +224,39 @@ var PlotlyGraph = /*#__PURE__*/function (_Component) {
206
224
  config = props.config;
207
225
  var animate = props.animate,
208
226
  animation_options = props.animation_options,
209
- responsive = props.responsive;
227
+ responsive = props.responsive,
228
+ mathjax = props.mathjax;
210
229
  var gd = this.gd.current;
211
230
  figure = props._dashprivate_transformFigure(figure, gd);
212
231
  config = props._dashprivate_transformConfig(config, gd);
232
+ var configClone = this.getConfig(config, responsive); // add typesetMath | not exposed to the dash API
233
+
234
+ configClone.typesetMath = mathjax;
235
+ var figureClone = {
236
+ data: figure.data,
237
+ layout: this.getLayout(figure.layout, responsive),
238
+ frames: figure.frames,
239
+ config: configClone
240
+ };
213
241
 
214
242
  if (animate && this._hasPlotted && figure.data.length === gd.data.length) {
215
- return Plotly.animate(gd, figure, animation_options);
243
+ // in case we've have figure frames,
244
+ // we need to recreate frames before animation
245
+ if (figure.frames) {
246
+ return Plotly.deleteFrames(gd).then(function () {
247
+ return Plotly.addFrames(gd, figure.frames);
248
+ }).then(function () {
249
+ return Plotly.animate(gd, figureClone, animation_options);
250
+ });
251
+ }
252
+
253
+ return Plotly.animate(gd, figureClone, animation_options);
216
254
  }
217
255
 
218
- var configClone = this.getConfig(config, responsive);
219
- var layoutClone = this.getLayout(figure.layout, responsive);
220
256
  gd.classList.add('dash-graph--pending');
221
- return Plotly.react(gd, {
222
- data: figure.data,
223
- layout: layoutClone,
224
- frames: figure.frames,
225
- config: configClone
257
+ return (0, _mathjax.default)(mathjax).then(function () {
258
+ var gd = _this2.gd.current;
259
+ return gd && Plotly.react(gd, figureClone);
226
260
  }).then(function () {
227
261
  var gd = _this2.gd.current; // double-check gd hasn't been unmounted
228
262
 
@@ -259,6 +293,7 @@ var PlotlyGraph = /*#__PURE__*/function (_Component) {
259
293
 
260
294
  var clearState = props.clearState;
261
295
  var dataArray = props[dataKey];
296
+ var p = Promise.resolve();
262
297
  dataArray.forEach(function (data) {
263
298
  var updateData, traceIndices, maxPoints;
264
299
 
@@ -284,10 +319,14 @@ var PlotlyGraph = /*#__PURE__*/function (_Component) {
284
319
  traceIndices = generateIndices(updateData);
285
320
  }
286
321
 
287
- var gd = _this3.gd.current;
288
- return Plotly[plotlyFnKey](gd, updateData, traceIndices, maxPoints);
322
+ p = p.then(function () {
323
+ var gd = _this3.gd.current;
324
+ return gd && Plotly[plotlyFnKey](gd, updateData, traceIndices, maxPoints);
325
+ });
326
+ });
327
+ p.then(function () {
328
+ return clearState(dataKey);
289
329
  });
290
- clearState(dataKey);
291
330
  }
292
331
  }, {
293
332
  key: "getConfig",
@@ -473,20 +512,28 @@ var PlotlyGraph = /*#__PURE__*/function (_Component) {
473
512
  }, {
474
513
  key: "componentDidMount",
475
514
  value: function componentDidMount() {
476
- var _this$props$prependDa, _this$props$extendDat;
515
+ var _this4 = this,
516
+ _this$props$prependDa,
517
+ _this$props$extendDat;
477
518
 
478
- this.plot(this.props);
519
+ var p = this.plot(this.props);
479
520
 
480
521
  if (this.props.prependData) {
481
- this.mergeTraces(this.props, 'prependData', 'prependTraces');
522
+ p = p.then(function () {
523
+ return _this4.mergeTraces(_this4.props, 'prependData', 'prependTraces');
524
+ });
482
525
  }
483
526
 
484
527
  if (this.props.extendData) {
485
- this.mergeTraces(this.props, 'extendData', 'extendTraces');
528
+ p = p.then(function () {
529
+ return _this4.mergeTraces(_this4.props, 'extendData', 'extendTraces');
530
+ });
486
531
  }
487
532
 
488
533
  if ((_this$props$prependDa = this.props.prependData) !== null && _this$props$prependDa !== void 0 && _this$props$prependDa.length || (_this$props$extendDat = this.props.extendData) !== null && _this$props$extendDat !== void 0 && _this$props$extendDat.length) {
489
- this.props._dashprivate_onFigureModified(this.props.figure);
534
+ p.then(function () {
535
+ return _this4.props._dashprivate_onFigureModified(_this4.props.figure);
536
+ });
490
537
  }
491
538
  }
492
539
  }, {
@@ -510,7 +557,9 @@ var PlotlyGraph = /*#__PURE__*/function (_Component) {
510
557
  }, {
511
558
  key: "UNSAFE_componentWillReceiveProps",
512
559
  value: function UNSAFE_componentWillReceiveProps(nextProps) {
513
- var _this$props$prependDa2, _this$props$extendDat2;
560
+ var _this5 = this,
561
+ _this$props$prependDa2,
562
+ _this$props$extendDat2;
514
563
 
515
564
  var idChanged = this.props.id !== nextProps.id;
516
565
 
@@ -522,26 +571,34 @@ var PlotlyGraph = /*#__PURE__*/function (_Component) {
522
571
  return;
523
572
  }
524
573
 
525
- if (this.props.figure !== nextProps.figure || this.props._dashprivate_transformConfig !== nextProps._dashprivate_transformConfig || this.props._dashprivate_transformFigure !== nextProps._dashprivate_transformFigure) {
526
- this.plot(nextProps);
574
+ var p = Promise.resolve();
575
+
576
+ if (this.props.mathjax !== nextProps.mathjax || this.props.figure !== nextProps.figure || this.props._dashprivate_transformConfig !== nextProps._dashprivate_transformConfig || this.props._dashprivate_transformFigure !== nextProps._dashprivate_transformFigure) {
577
+ p = this.plot(nextProps);
527
578
  }
528
579
 
529
580
  if (this.props.prependData !== nextProps.prependData) {
530
- this.mergeTraces(nextProps, 'prependData', 'prependTraces');
581
+ p = p.then(function () {
582
+ return _this5.mergeTraces(nextProps, 'prependData', 'prependTraces');
583
+ });
531
584
  }
532
585
 
533
586
  if (this.props.extendData !== nextProps.extendData) {
534
- this.mergeTraces(nextProps, 'extendData', 'extendTraces');
587
+ p = p.then(function () {
588
+ return _this5.mergeTraces(nextProps, 'extendData', 'extendTraces');
589
+ });
535
590
  }
536
591
 
537
592
  if ((_this$props$prependDa2 = this.props.prependData) !== null && _this$props$prependDa2 !== void 0 && _this$props$prependDa2.length || (_this$props$extendDat2 = this.props.extendData) !== null && _this$props$extendDat2 !== void 0 && _this$props$extendDat2.length) {
538
- this.props._dashprivate_onFigureModified(this.props.figure);
593
+ p.then(function () {
594
+ return _this5.props._dashprivate_onFigureModified(_this5.props.figure);
595
+ });
539
596
  }
540
597
  }
541
598
  }, {
542
599
  key: "componentDidUpdate",
543
600
  value: function componentDidUpdate(prevProps) {
544
- if (prevProps.id !== this.props.id) {
601
+ if (prevProps.id !== this.props.id || prevProps.mathjax !== this.props.mathjax) {
545
602
  this.plot(this.props);
546
603
  }
547
604
  }
@@ -15,6 +15,10 @@ var _reactJsxParser = _interopRequireDefault(require("react-jsx-parser"));
15
15
 
16
16
  var _reactMarkdown = _interopRequireDefault(require("react-markdown"));
17
17
 
18
+ var _remarkMath = _interopRequireDefault(require("remark-math"));
19
+
20
+ var _Math = _interopRequireDefault(require("./Math.react"));
21
+
18
22
  var _MarkdownHighlighter = _interopRequireDefault(require("../utils/MarkdownHighlighter"));
19
23
 
20
24
  var _Markdown = require("../components/Markdown.react");
@@ -159,6 +163,7 @@ var DashMarkdown = /*#__PURE__*/function (_Component) {
159
163
  highlight_config = _this$props.highlight_config,
160
164
  loading_state = _this$props.loading_state,
161
165
  dangerously_allow_html = _this$props.dangerously_allow_html,
166
+ mathjax = _this$props.mathjax,
162
167
  children = _this$props.children,
163
168
  dedent = _this$props.dedent;
164
169
  var textProp = (0, _ramda.type)(children) === 'Array' ? children.join('\n') : children;
@@ -182,7 +187,20 @@ var DashMarkdown = /*#__PURE__*/function (_Component) {
182
187
  }, /*#__PURE__*/_react.default.createElement(_reactMarkdown.default, {
183
188
  source: displayText,
184
189
  escapeHtml: !dangerously_allow_html,
190
+ plugins: mathjax ? [_remarkMath.default] : [],
185
191
  renderers: {
192
+ math: function math(props) {
193
+ return /*#__PURE__*/_react.default.createElement(_Math.default, {
194
+ tex: props.value,
195
+ inline: false
196
+ });
197
+ },
198
+ inlineMath: function inlineMath(props) {
199
+ return /*#__PURE__*/_react.default.createElement(_Math.default, {
200
+ tex: props.value,
201
+ inline: true
202
+ });
203
+ },
186
204
  html: function html(props) {
187
205
  return props.escapeHtml ? props.value : /*#__PURE__*/_react.default.createElement(_reactJsxParser.default, {
188
206
  jsx: props.value,
@@ -0,0 +1,101 @@
1
+ "use strict";
2
+
3
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.propTypes = exports.defaultProps = exports.default = void 0;
9
+
10
+ var _propTypes = _interopRequireDefault(require("prop-types"));
11
+
12
+ var _react = _interopRequireWildcard(require("react"));
13
+
14
+ var _mathjax = _interopRequireDefault(require("../utils/LazyLoader/mathjax"));
15
+
16
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
17
+
18
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
19
+
20
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
+
22
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
23
+
24
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
25
+
26
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
27
+
28
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
29
+
30
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
31
+
32
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
33
+
34
+ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
35
+
36
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
37
+
38
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
39
+
40
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
41
+
42
+ var DashMath = /*#__PURE__*/function (_Component) {
43
+ _inherits(DashMath, _Component);
44
+
45
+ var _super = _createSuper(DashMath);
46
+
47
+ function DashMath(props) {
48
+ var _this;
49
+
50
+ _classCallCheck(this, DashMath);
51
+
52
+ _this = _super.call(this, props);
53
+ _this.span_element = /*#__PURE__*/_react.default.createRef();
54
+ return _this;
55
+ }
56
+
57
+ _createClass(DashMath, [{
58
+ key: "componentDidMount",
59
+ value: function componentDidMount() {
60
+ this.renderMath();
61
+ }
62
+ }, {
63
+ key: "componentDidUpdate",
64
+ value: function componentDidUpdate(prevProps) {
65
+ if (prevProps.tex !== this.props.tex || prevProps.inline !== this.props.inline) {
66
+ this.renderMath();
67
+ }
68
+ }
69
+ }, {
70
+ key: "renderMath",
71
+ value: function renderMath() {
72
+ var current = this.span_element.current;
73
+ (0, _mathjax.default)().then(function () {
74
+ window.MathJax.typeset([current]);
75
+ });
76
+ }
77
+ }, {
78
+ key: "render",
79
+ value: function render() {
80
+ return /*#__PURE__*/_react.default.createElement("span", {
81
+ ref: this.span_element
82
+ }, this.props.inline ? '\\(' : '\\[', this.props.tex, this.props.inline ? '\\)' : '\\]');
83
+ }
84
+ }]);
85
+
86
+ return DashMath;
87
+ }(_react.Component);
88
+
89
+ exports.default = DashMath;
90
+ DashMath.propTypes = {
91
+ tex: _propTypes.default.string,
92
+ inline: _propTypes.default.bool
93
+ };
94
+ DashMath.defaultProps = {
95
+ tex: '',
96
+ inline: true
97
+ };
98
+ var propTypes = DashMath.propTypes;
99
+ exports.propTypes = propTypes;
100
+ var defaultProps = DashMath.defaultProps;
101
+ exports.defaultProps = defaultProps;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
9
+
10
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
11
+
12
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
13
+
14
+ var _default = function _default(mathjax) {
15
+ return Promise.resolve(window.MathJax || (mathjax === false ? undefined : Promise.resolve().then(function () {
16
+ return _interopRequireWildcard(require('../mathjax'));
17
+ }).then(function () {
18
+ return window.MathJax;
19
+ })));
20
+ };
21
+
22
+ exports.default = _default;
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ require("mathjax/es5/tex-svg");
4
+
5
+ window.MathJax.config.startup.typeset = false;