dash-core-components 4.5.3 → 4.5.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dash_core_components/async-datepicker.js +1 -1
- package/dash_core_components/async-datepicker.js.map +1 -1
- package/dash_core_components/async-dropdown.js +1 -1
- package/dash_core_components/async-dropdown.js.map +1 -1
- package/dash_core_components/async-graph.js +1 -1
- package/dash_core_components/async-graph.js.map +1 -1
- package/dash_core_components/async-highlight.js +1 -1
- package/dash_core_components/async-highlight.js.map +1 -1
- package/dash_core_components/async-markdown.js +1 -2
- package/dash_core_components/async-markdown.js.map +1 -1
- package/dash_core_components/async-slider.js +1 -1
- package/dash_core_components/async-slider.js.map +1 -1
- package/dash_core_components/async-upload.js +1 -1
- package/dash_core_components/async-upload.js.map +1 -1
- package/dash_core_components/dash_core_components-shared.js +1 -1
- package/dash_core_components/dash_core_components-shared.js.map +1 -1
- package/dash_core_components/dash_core_components.js +1 -1
- package/dash_core_components/dash_core_components.js.map +1 -1
- package/dash_core_components/proptypes.js +1 -1
- package/lib/components/Clipboard.react.js +4 -3
- package/lib/components/ConfirmDialog.react.js +1 -1
- package/lib/components/ConfirmDialogProvider.react.js +1 -1
- package/lib/components/Download.react.js +1 -1
- package/lib/components/Geolocation.react.js +2 -2
- package/lib/components/Graph.react.js +3 -2
- package/lib/components/Input.tsx +2 -2
- package/lib/components/Interval.react.js +3 -2
- package/lib/components/Location.react.js +1 -1
- package/lib/components/Store.react.js +1 -1
- package/lib/components/Upload.react.js +5 -3
- package/lib/components/css/dropdown.css +2 -0
- package/lib/fragments/Graph.react.js +245 -30
- package/lib/fragments/Markdown.tsx +16 -2
- package/lib/fragments/Upload.react.js +4 -3
- package/lib/types.ts +1 -0
- package/lib/utils/LoadingElement.js +1 -1
- package/lib/utils/ResizeDetector.js +2 -2
- package/lib/utils/markdown/components/Code.tsx +2 -2
- package/lib/utils/markdown/components/types.ts +1 -2
- package/lib/utils/markdown/plugins/index.ts +8 -0
- package/lib/utils/markdown/plugins/rehypeBlockCode.ts +25 -0
- package/lib/utils/markdown/plugins/rehypeDashMath.ts +15 -2
- package/lib/utils/markdown/plugins/rehypeLinkTarget.ts +15 -0
- package/lib/utils/markdown/polyfills.ts +24 -0
- package/package.json +6 -6
|
@@ -11,30 +11,35 @@ var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
|
11
11
|
var _Graph = require("../components/Graph.react");
|
|
12
12
|
var _ResizeDetector = _interopRequireDefault(require("../utils/ResizeDetector"));
|
|
13
13
|
var _LoadingElement = _interopRequireDefault(require("../utils/LoadingElement"));
|
|
14
|
-
|
|
14
|
+
var cache;
|
|
15
|
+
function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var r, c, a = Object.defineProperty, n = { __proto__: null, default: e }; if (Object(e) !== e) return n; if (cache || "function" != typeof WeakMap || (cache = new WeakMap()), cache) { if (cache.has(e)) return cache.get(e); cache.set(e, n); } for (c in e) "default" !== c && {}.hasOwnProperty.call(e, c) && ((r = a && Object.getOwnPropertyDescriptor(e, c)) && (r.get || r.set) ? a(n, c, r) : n[c] = e[c]); return n; }
|
|
15
16
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
16
|
-
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
17
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
18
|
-
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
19
17
|
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
20
18
|
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."); }
|
|
21
|
-
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
22
|
-
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
23
19
|
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
24
20
|
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
25
|
-
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
26
21
|
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
27
22
|
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
|
|
28
23
|
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
29
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
30
|
-
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
31
24
|
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
32
25
|
function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); }
|
|
33
26
|
function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
|
|
34
27
|
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
35
28
|
function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
|
|
36
29
|
function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); }
|
|
37
|
-
function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
|
|
30
|
+
function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
|
|
31
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
32
|
+
function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
|
|
33
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
34
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
35
|
+
function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
|
|
36
|
+
function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
|
|
37
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
38
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
39
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
40
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
41
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
42
|
+
function _toPrimitive(t, e) { if ("object" != _typeof(t) || !t) return t; var r; if ("undefined" != typeof Symbol && void 0 !== (r = t[Symbol.toPrimitive])) { var i = r.call(t, e || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === e ? String : Number)(t); } /* global Plotly:true */
|
|
38
43
|
/**
|
|
39
44
|
* `autosize: true` causes Plotly.js to conform to the parent element size.
|
|
40
45
|
* This is necessary for `dcc.Graph` call to `Plotly.Plots.resize(target)` to do something.
|
|
@@ -66,6 +71,15 @@ var AUTO_CONFIG = {};
|
|
|
66
71
|
var UNRESPONSIVE_CONFIG = {
|
|
67
72
|
responsive: false
|
|
68
73
|
};
|
|
74
|
+
var _toPlainArray = function toPlainArray(value) {
|
|
75
|
+
if (ArrayBuffer.isView(value)) {
|
|
76
|
+
return Array.from(value);
|
|
77
|
+
}
|
|
78
|
+
if (Array.isArray(value)) {
|
|
79
|
+
return value.map(_toPlainArray);
|
|
80
|
+
}
|
|
81
|
+
return value;
|
|
82
|
+
};
|
|
69
83
|
var filterEventData = function filterEventData(gd, eventData, event) {
|
|
70
84
|
var filteredEventData;
|
|
71
85
|
if ((0, _ramda.includes)(event, ['click', 'hover', 'selected'])) {
|
|
@@ -83,8 +97,16 @@ var filterEventData = function filterEventData(gd, eventData, event) {
|
|
|
83
97
|
* into the event object
|
|
84
98
|
*/
|
|
85
99
|
var data = gd.data;
|
|
100
|
+
// Parcoords sends one flat point instead of a points array. Its
|
|
101
|
+
// curveNumber is the line index and dataIndex is the trace index, so
|
|
102
|
+
// reshape it to match other traces: curveNumber is the trace and
|
|
103
|
+
// pointNumber is the line.
|
|
104
|
+
var eventPoints = Array.isArray(eventData.points) ? eventData.points : [_objectSpread(_objectSpread({}, eventData), {}, {
|
|
105
|
+
curveNumber: eventData.dataIndex,
|
|
106
|
+
pointNumber: eventData.curveNumber
|
|
107
|
+
})];
|
|
86
108
|
var _loop = function _loop() {
|
|
87
|
-
var fullPoint =
|
|
109
|
+
var fullPoint = eventPoints[i];
|
|
88
110
|
var pointData = (0, _ramda.filter)(function (o) {
|
|
89
111
|
return !(0, _ramda.includes)((0, _ramda.type)(o), ['Object', 'Array']);
|
|
90
112
|
}, fullPoint);
|
|
@@ -94,17 +116,24 @@ var filterEventData = function filterEventData(gd, eventData, event) {
|
|
|
94
116
|
pointData.bbox = fullPoint.bbox;
|
|
95
117
|
}
|
|
96
118
|
if ((0, _ramda.has)('curveNumber', fullPoint) && (0, _ramda.has)('customdata', data[pointData.curveNumber])) {
|
|
119
|
+
var _fullPoint$fullData$c, _fullPoint$fullData;
|
|
120
|
+
var customdata = data[pointData.curveNumber].customdata;
|
|
121
|
+
// Binary (typed array) customdata is only decoded in the full
|
|
122
|
+
// trace, so read it from there and fall back to the input.
|
|
123
|
+
var customdataArray = (_fullPoint$fullData$c = (_fullPoint$fullData = fullPoint.fullData) === null || _fullPoint$fullData === void 0 ? void 0 : _fullPoint$fullData.customdata) !== null && _fullPoint$fullData$c !== void 0 ? _fullPoint$fullData$c : customdata;
|
|
97
124
|
if ((0, _ramda.has)('pointNumber', fullPoint)) {
|
|
98
125
|
if (typeof fullPoint.pointNumber === 'number') {
|
|
99
|
-
pointData.customdata =
|
|
126
|
+
pointData.customdata = customdataArray[fullPoint.pointNumber];
|
|
100
127
|
} else if (!fullPoint.pointNumber && fullPoint.data.mode.includes('lines')) {
|
|
101
|
-
pointData.customdata =
|
|
128
|
+
pointData.customdata = customdataArray;
|
|
102
129
|
}
|
|
103
130
|
} else if ((0, _ramda.has)('pointNumbers', fullPoint)) {
|
|
104
131
|
pointData.customdata = fullPoint.pointNumbers.map(function (point) {
|
|
105
|
-
return
|
|
132
|
+
return customdataArray[point];
|
|
106
133
|
});
|
|
107
134
|
}
|
|
135
|
+
// Typed arrays would serialize as objects, so send plain arrays.
|
|
136
|
+
pointData.customdata = _toPlainArray(pointData.customdata);
|
|
108
137
|
}
|
|
109
138
|
|
|
110
139
|
// specific to histogram. see https://github.com/plotly/plotly.js/pull/2113/
|
|
@@ -113,7 +142,7 @@ var filterEventData = function filterEventData(gd, eventData, event) {
|
|
|
113
142
|
}
|
|
114
143
|
points[i] = pointData;
|
|
115
144
|
};
|
|
116
|
-
for (var i = 0; i <
|
|
145
|
+
for (var i = 0; i < eventPoints.length; i++) {
|
|
117
146
|
_loop();
|
|
118
147
|
}
|
|
119
148
|
filteredEventData = {
|
|
@@ -151,6 +180,101 @@ var filterEventData = function filterEventData(gd, eventData, event) {
|
|
|
151
180
|
return filteredEventData;
|
|
152
181
|
};
|
|
153
182
|
|
|
183
|
+
// layoutUIControlPatterns in plotly.js src/plot_api/plot_api.js: the GUI
|
|
184
|
+
// edits plotly.js keeps across figure updates while their uirevision holds
|
|
185
|
+
var UIREVISION_PATTERNS = [{
|
|
186
|
+
pattern: /^hiddenlabels/,
|
|
187
|
+
attr: 'legend.uirevision'
|
|
188
|
+
}, {
|
|
189
|
+
pattern: /^((x|y)axis\d*)\.((auto)?range|title\.text)/
|
|
190
|
+
}, {
|
|
191
|
+
pattern: /axis\d*\.showspikes$/,
|
|
192
|
+
attr: 'modebar.uirevision'
|
|
193
|
+
}, {
|
|
194
|
+
pattern: /(hover|drag)mode$/,
|
|
195
|
+
attr: 'modebar.uirevision'
|
|
196
|
+
}, {
|
|
197
|
+
pattern: /^(scene\d*)\.camera/
|
|
198
|
+
}, {
|
|
199
|
+
pattern: /^(geo\d*)\.(projection|center|fitbounds)/
|
|
200
|
+
}, {
|
|
201
|
+
pattern: /^(ternary\d*\.[abc]axis)\.(min|title\.text)$/
|
|
202
|
+
}, {
|
|
203
|
+
pattern: /^(polar\d*\.radialaxis)\.((auto)?range|angle|title\.text)/
|
|
204
|
+
}, {
|
|
205
|
+
pattern: /^(polar\d*\.angularaxis)\.rotation/
|
|
206
|
+
}, {
|
|
207
|
+
pattern: /^(map\d*)\.(center|zoom|bearing|pitch)/
|
|
208
|
+
}, {
|
|
209
|
+
pattern: /^legend\.(x|y)$/,
|
|
210
|
+
attr: 'editrevision'
|
|
211
|
+
}, {
|
|
212
|
+
pattern: /^(shapes|annotations)/,
|
|
213
|
+
attr: 'editrevision'
|
|
214
|
+
}, {
|
|
215
|
+
pattern: /^selections/,
|
|
216
|
+
attr: 'selectionrevision'
|
|
217
|
+
}, {
|
|
218
|
+
pattern: /^title\.text$/,
|
|
219
|
+
attr: 'editrevision'
|
|
220
|
+
}];
|
|
221
|
+
var getRevisionAttr = function getRevisionAttr(attr) {
|
|
222
|
+
for (var _i = 0, _UIREVISION_PATTERNS = UIREVISION_PATTERNS; _i < _UIREVISION_PATTERNS.length; _i++) {
|
|
223
|
+
var _UIREVISION_PATTERNS$ = _UIREVISION_PATTERNS[_i],
|
|
224
|
+
pattern = _UIREVISION_PATTERNS$.pattern,
|
|
225
|
+
revisionAttr = _UIREVISION_PATTERNS$.attr;
|
|
226
|
+
var match = attr.match(pattern);
|
|
227
|
+
if (match) {
|
|
228
|
+
return revisionAttr || "".concat(match[1], ".uirevision");
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
return null;
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
// 'shapes[1].x0' -> ['shapes', 1, 'x0']
|
|
235
|
+
var toPath = function toPath(attr) {
|
|
236
|
+
return attr.split('.').flatMap(function (part) {
|
|
237
|
+
return part.split(/\[(\d+)\]/).filter(function (segment) {
|
|
238
|
+
return segment !== '';
|
|
239
|
+
}).map(function (segment, i) {
|
|
240
|
+
return i ? Number(segment) : segment;
|
|
241
|
+
});
|
|
242
|
+
});
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
// Same inheritance as getNewRev in plotly.js
|
|
246
|
+
var getNewRevision = function getNewRevision(layout, revisionAttr) {
|
|
247
|
+
var keys = toPath(revisionAttr);
|
|
248
|
+
var revision = (0, _ramda.path)(keys, layout);
|
|
249
|
+
if (revision !== undefined) {
|
|
250
|
+
return revision;
|
|
251
|
+
}
|
|
252
|
+
for (var depth = keys.length - 2; depth > 0; depth--) {
|
|
253
|
+
var inherited = (0, _ramda.path)([].concat(_toConsumableArray(keys.slice(0, depth)), ['uirevision']), layout);
|
|
254
|
+
if (inherited !== undefined) {
|
|
255
|
+
return inherited;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
return layout.uirevision;
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
// Only sets inside existing containers, never creates them
|
|
262
|
+
var setPath = function setPath(container, keys, value) {
|
|
263
|
+
var parent = (0, _ramda.path)(keys.slice(0, -1), container);
|
|
264
|
+
if (_typeof(parent) !== 'object' || parent === null) {
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
var last = keys[keys.length - 1];
|
|
268
|
+
if (Array.isArray(parent) && last >= parent.length) {
|
|
269
|
+
return;
|
|
270
|
+
}
|
|
271
|
+
if (value === undefined && !Array.isArray(parent)) {
|
|
272
|
+
delete parent[last];
|
|
273
|
+
} else {
|
|
274
|
+
parent[last] = value;
|
|
275
|
+
}
|
|
276
|
+
};
|
|
277
|
+
|
|
154
278
|
/**
|
|
155
279
|
* Graph can be used to render any plotly.js-powered data visualization.
|
|
156
280
|
*
|
|
@@ -166,6 +290,7 @@ var PlotlyGraph = /*#__PURE__*/function (_Component) {
|
|
|
166
290
|
_this2._hasPlotted = false;
|
|
167
291
|
_this2._prevGd = null;
|
|
168
292
|
_this2._queue = Promise.resolve();
|
|
293
|
+
_this2._pendingFigures = [];
|
|
169
294
|
_this2.parentElement = /*#__PURE__*/_react.default.createRef();
|
|
170
295
|
_this2.bindEvents = _this2.bindEvents.bind(_this2);
|
|
171
296
|
_this2.getConfig = _this2.getConfig.bind(_this2);
|
|
@@ -179,6 +304,7 @@ var PlotlyGraph = /*#__PURE__*/function (_Component) {
|
|
|
179
304
|
override: {},
|
|
180
305
|
originals: {}
|
|
181
306
|
};
|
|
307
|
+
_this2._syncedEdits = {};
|
|
182
308
|
return _this2;
|
|
183
309
|
}
|
|
184
310
|
_inherits(PlotlyGraph, _Component);
|
|
@@ -201,13 +327,16 @@ var PlotlyGraph = /*#__PURE__*/function (_Component) {
|
|
|
201
327
|
var configClone = this.getConfig(config, responsive);
|
|
202
328
|
// add typesetMath | not exposed to the dash API
|
|
203
329
|
configClone.typesetMath = mathjax;
|
|
330
|
+
var animating = animate && this._hasPlotted && figure.data.length === gd.data.length;
|
|
331
|
+
var layout = this.getLayout((_figure = figure) === null || _figure === void 0 ? void 0 : _figure.layout, responsive);
|
|
332
|
+
this.applySyncedEdits(layout, animating);
|
|
204
333
|
var figureClone = {
|
|
205
|
-
data: (
|
|
206
|
-
layout
|
|
334
|
+
data: (_figure2 = figure) === null || _figure2 === void 0 ? void 0 : _figure2.data,
|
|
335
|
+
layout,
|
|
207
336
|
frames: (_figure3 = figure) === null || _figure3 === void 0 ? void 0 : _figure3.frames,
|
|
208
337
|
config: configClone
|
|
209
338
|
};
|
|
210
|
-
if (
|
|
339
|
+
if (animating) {
|
|
211
340
|
// in case we've have figure frames,
|
|
212
341
|
// we need to recreate frames before animation
|
|
213
342
|
if (figure.frames) {
|
|
@@ -350,6 +479,79 @@ var PlotlyGraph = /*#__PURE__*/function (_Component) {
|
|
|
350
479
|
}
|
|
351
480
|
return layout;
|
|
352
481
|
}
|
|
482
|
+
|
|
483
|
+
/*
|
|
484
|
+
* The plotly_relayout handler copies GUI edits (zoom, pan, ...) into the
|
|
485
|
+
* figure prop. If Plotly.react gets them as input, plotly.js takes them as
|
|
486
|
+
* the new starting point and drops them from its uirevision bookkeeping
|
|
487
|
+
* (_preGUI), so a later figure without them resets the view. While a
|
|
488
|
+
* synced value is still in the figure and its uirevision is unchanged,
|
|
489
|
+
* give plotly.js the value from before the edit so it keeps the edit
|
|
490
|
+
* itself. Plotly.animate does not apply uirevision, so there the value
|
|
491
|
+
* from before the edit is replaced by the edit instead.
|
|
492
|
+
*/
|
|
493
|
+
}, {
|
|
494
|
+
key: "applySyncedEdits",
|
|
495
|
+
value: function applySyncedEdits(layout, animating) {
|
|
496
|
+
var _this$gd$current,
|
|
497
|
+
_this4 = this;
|
|
498
|
+
var fullLayout = (_this$gd$current = this.gd.current) === null || _this$gd$current === void 0 ? void 0 : _this$gd$current._fullLayout;
|
|
499
|
+
var preGUI = fullLayout === null || fullLayout === void 0 ? void 0 : fullLayout._preGUI;
|
|
500
|
+
if (!layout || !preGUI) {
|
|
501
|
+
return;
|
|
502
|
+
}
|
|
503
|
+
var _loop2 = function _loop2() {
|
|
504
|
+
var _preGUI$attr;
|
|
505
|
+
var _Object$entries$_i = _slicedToArray(_Object$entries[_i2], 2),
|
|
506
|
+
attr = _Object$entries$_i[0],
|
|
507
|
+
syncedValues = _Object$entries$_i[1];
|
|
508
|
+
if (!(attr in preGUI)) {
|
|
509
|
+
delete _this4._syncedEdits[attr];
|
|
510
|
+
return 0; // continue
|
|
511
|
+
}
|
|
512
|
+
var revisionAttr = getRevisionAttr(attr);
|
|
513
|
+
var oldRevision = (0, _ramda.path)(toPath(revisionAttr), fullLayout);
|
|
514
|
+
if (!oldRevision || getNewRevision(layout, revisionAttr) !== oldRevision) {
|
|
515
|
+
return 0; // continue
|
|
516
|
+
}
|
|
517
|
+
var keys = toPath(attr);
|
|
518
|
+
var value = (0, _ramda.path)(keys, layout);
|
|
519
|
+
var original = (_preGUI$attr = preGUI[attr]) !== null && _preGUI$attr !== void 0 ? _preGUI$attr : undefined;
|
|
520
|
+
if (animating) {
|
|
521
|
+
if ((0, _ramda.equals)(value, original)) {
|
|
522
|
+
setPath(layout, keys, (0, _ramda.clone)(syncedValues[syncedValues.length - 1]));
|
|
523
|
+
}
|
|
524
|
+
return 0; // continue
|
|
525
|
+
}
|
|
526
|
+
// Earlier syncs may still be queued for plotting
|
|
527
|
+
var index = syncedValues.findIndex(function (synced) {
|
|
528
|
+
return (0, _ramda.equals)(value, synced);
|
|
529
|
+
});
|
|
530
|
+
if (index !== -1) {
|
|
531
|
+
_this4._syncedEdits[attr] = syncedValues.slice(index);
|
|
532
|
+
setPath(layout, keys, original);
|
|
533
|
+
}
|
|
534
|
+
},
|
|
535
|
+
_ret;
|
|
536
|
+
for (var _i2 = 0, _Object$entries = Object.entries(this._syncedEdits); _i2 < _Object$entries.length; _i2++) {
|
|
537
|
+
_ret = _loop2();
|
|
538
|
+
if (_ret === 0) continue;
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
}, {
|
|
542
|
+
key: "trackSyncedEdits",
|
|
543
|
+
value: function trackSyncedEdits(updates) {
|
|
544
|
+
var _this$gd$current$_ful, _this$gd$current2;
|
|
545
|
+
var preGUI = (_this$gd$current$_ful = (_this$gd$current2 = this.gd.current) === null || _this$gd$current2 === void 0 || (_this$gd$current2 = _this$gd$current2._fullLayout) === null || _this$gd$current2 === void 0 ? void 0 : _this$gd$current2._preGUI) !== null && _this$gd$current$_ful !== void 0 ? _this$gd$current$_ful : {};
|
|
546
|
+
for (var _i3 = 0, _Object$keys = Object.keys(preGUI); _i3 < _Object$keys.length; _i3++) {
|
|
547
|
+
var attr = _Object$keys[_i3];
|
|
548
|
+
var keys = toPath(attr);
|
|
549
|
+
if (keys[0] in updates && getRevisionAttr(attr)) {
|
|
550
|
+
var _this$_syncedEdits$at;
|
|
551
|
+
this._syncedEdits[attr] = [].concat(_toConsumableArray((_this$_syncedEdits$at = this._syncedEdits[attr]) !== null && _this$_syncedEdits$at !== void 0 ? _this$_syncedEdits$at : []), [(0, _ramda.path)(keys, updates)]);
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
}
|
|
353
555
|
}, {
|
|
354
556
|
key: "getConfigOverride",
|
|
355
557
|
value: function getConfigOverride(responsive) {
|
|
@@ -406,7 +608,7 @@ var PlotlyGraph = /*#__PURE__*/function (_Component) {
|
|
|
406
608
|
}, {
|
|
407
609
|
key: "bindEvents",
|
|
408
610
|
value: function bindEvents() {
|
|
409
|
-
var
|
|
611
|
+
var _this5 = this;
|
|
410
612
|
var _this$props = this.props,
|
|
411
613
|
setProps = _this$props.setProps,
|
|
412
614
|
clear_on_unhover = _this$props.clear_on_unhover,
|
|
@@ -468,12 +670,14 @@ var PlotlyGraph = /*#__PURE__*/function (_Component) {
|
|
|
468
670
|
// copy and the figure prop (used as the base for Patch
|
|
469
671
|
// updates) would otherwise go stale.
|
|
470
672
|
if (eventData && gd.layout) {
|
|
471
|
-
var
|
|
472
|
-
|
|
673
|
+
var _ref, _this5$_pendingFigure;
|
|
674
|
+
// React may batch several relayouts before delivering props.
|
|
675
|
+
// Build on the latest sync rather than losing its changes.
|
|
676
|
+
var figure = (_ref = (_this5$_pendingFigure = _this5._pendingFigures[_this5._pendingFigures.length - 1]) !== null && _this5$_pendingFigure !== void 0 ? _this5$_pendingFigure : _this5.props.figure) !== null && _ref !== void 0 ? _ref : {};
|
|
473
677
|
var updates = {};
|
|
474
|
-
for (var
|
|
678
|
+
for (var _i4 = 0, _Object$keys2 = Object.keys(eventData); _i4 < _Object$keys2.length; _i4++) {
|
|
475
679
|
var _figure$layout;
|
|
476
|
-
var eventKey = _Object$
|
|
680
|
+
var eventKey = _Object$keys2[_i4];
|
|
477
681
|
// 'xaxis.range[0]' -> 'xaxis', 'shapes[1].x0' -> 'shapes'
|
|
478
682
|
var key = eventKey.split('.')[0].split('[')[0];
|
|
479
683
|
if (
|
|
@@ -484,10 +688,13 @@ var PlotlyGraph = /*#__PURE__*/function (_Component) {
|
|
|
484
688
|
}
|
|
485
689
|
}
|
|
486
690
|
if (Object.keys(updates).length) {
|
|
691
|
+
_this5.trackSyncedEdits(updates);
|
|
692
|
+
var syncedFigure = _objectSpread(_objectSpread({}, figure), {}, {
|
|
693
|
+
layout: _objectSpread(_objectSpread({}, figure === null || figure === void 0 ? void 0 : figure.layout), updates)
|
|
694
|
+
});
|
|
695
|
+
_this5._pendingFigures.push(syncedFigure);
|
|
487
696
|
setProps({
|
|
488
|
-
figure:
|
|
489
|
-
layout: _objectSpread(_objectSpread({}, figure === null || figure === void 0 ? void 0 : figure.layout), updates)
|
|
490
|
-
})
|
|
697
|
+
figure: syncedFigure
|
|
491
698
|
});
|
|
492
699
|
}
|
|
493
700
|
}
|
|
@@ -533,19 +740,27 @@ var PlotlyGraph = /*#__PURE__*/function (_Component) {
|
|
|
533
740
|
}, {
|
|
534
741
|
key: "UNSAFE_componentWillReceiveProps",
|
|
535
742
|
value: function UNSAFE_componentWillReceiveProps(nextProps) {
|
|
536
|
-
var
|
|
743
|
+
var _this6 = this;
|
|
537
744
|
var idChanged = this.props.id !== nextProps.id;
|
|
538
745
|
if (idChanged) {
|
|
746
|
+
this._pendingFigures = [];
|
|
747
|
+
this._syncedEdits = {};
|
|
539
748
|
/*
|
|
540
749
|
* then the dom needs to get re-rendered with a new ID.
|
|
541
750
|
* the graph will get updated in componentDidUpdate
|
|
542
751
|
*/
|
|
543
752
|
return;
|
|
544
753
|
}
|
|
754
|
+
if (this.props.figure !== nextProps.figure) {
|
|
755
|
+
// An acknowledgement may skip batched figures or arrive before
|
|
756
|
+
// a later sync. An external figure supersedes all pending syncs.
|
|
757
|
+
var syncedIndex = this._pendingFigures.indexOf(nextProps.figure);
|
|
758
|
+
this._pendingFigures = syncedIndex === -1 ? [] : this._pendingFigures.slice(syncedIndex + 1);
|
|
759
|
+
}
|
|
545
760
|
var p = this._queue;
|
|
546
761
|
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) {
|
|
547
762
|
p = p.then(function () {
|
|
548
|
-
return
|
|
763
|
+
return _this6.plot(nextProps);
|
|
549
764
|
});
|
|
550
765
|
}
|
|
551
766
|
this._queue = this.amendTraces(p, this.props, nextProps);
|
|
@@ -553,10 +768,10 @@ var PlotlyGraph = /*#__PURE__*/function (_Component) {
|
|
|
553
768
|
}, {
|
|
554
769
|
key: "componentDidUpdate",
|
|
555
770
|
value: function componentDidUpdate(prevProps) {
|
|
556
|
-
var
|
|
771
|
+
var _this7 = this;
|
|
557
772
|
if (prevProps.id !== this.props.id || prevProps.mathjax !== this.props.mathjax) {
|
|
558
773
|
this._queue = this._queue.then(function () {
|
|
559
|
-
return
|
|
774
|
+
return _this7.plot(_this7.props);
|
|
560
775
|
});
|
|
561
776
|
}
|
|
562
777
|
}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
+
import '../utils/markdown/polyfills';
|
|
1
2
|
import React, {useCallback, useMemo} from 'react';
|
|
2
|
-
import ReactMarkdown
|
|
3
|
+
import ReactMarkdown, {
|
|
4
|
+
defaultUrlTransform,
|
|
5
|
+
type UrlTransform,
|
|
6
|
+
} from 'react-markdown';
|
|
3
7
|
import type {PluggableList} from 'unified';
|
|
4
8
|
|
|
5
9
|
import LoadingElement from '../utils/_LoadingElement';
|
|
@@ -7,13 +11,19 @@ import {MarkdownContentProps, MarkdownProps} from '../types';
|
|
|
7
11
|
import {components} from '../utils/markdown/components';
|
|
8
12
|
import {MarkdownContext} from '../utils/markdown/context';
|
|
9
13
|
import {
|
|
14
|
+
linkTargetPlugins,
|
|
10
15
|
rawHtmlPlugins,
|
|
16
|
+
rehypeBlockCodePlugins,
|
|
11
17
|
rehypeMathPlugins,
|
|
12
18
|
remarkMathPlugins,
|
|
13
19
|
remarkGfmPlugins,
|
|
14
20
|
} from '../utils/markdown/plugins';
|
|
15
21
|
import {dedentText} from '../utils/markdown/text';
|
|
16
22
|
|
|
23
|
+
// react-markdown 9 dropped `tel:` from its safe protocols; v8 allowed it.
|
|
24
|
+
const urlTransform: UrlTransform = url =>
|
|
25
|
+
/^tel:/i.test(url) ? url : defaultUrlTransform(url);
|
|
26
|
+
|
|
17
27
|
const MarkdownContent = React.memo(function MarkdownContent({
|
|
18
28
|
children,
|
|
19
29
|
dedent,
|
|
@@ -32,11 +42,15 @@ const MarkdownContent = React.memo(function MarkdownContent({
|
|
|
32
42
|
if (dangerously_allow_html) {
|
|
33
43
|
rehypePlugins.push(...rawHtmlPlugins);
|
|
34
44
|
}
|
|
45
|
+
rehypePlugins.push(...rehypeBlockCodePlugins);
|
|
46
|
+
if (link_target) {
|
|
47
|
+
rehypePlugins.push(...linkTargetPlugins(link_target));
|
|
48
|
+
}
|
|
35
49
|
|
|
36
50
|
return (
|
|
37
51
|
<ReactMarkdown
|
|
38
|
-
linkTarget={link_target}
|
|
39
52
|
remarkPlugins={remarkPlugins}
|
|
53
|
+
urlTransform={urlTransform}
|
|
40
54
|
rehypePlugins={rehypePlugins}
|
|
41
55
|
components={components}
|
|
42
56
|
>
|
|
@@ -10,8 +10,9 @@ var _reactDropzone = _interopRequireDefault(require("react-dropzone"));
|
|
|
10
10
|
var _Upload = require("../components/Upload.react");
|
|
11
11
|
var _LoadingElement = _interopRequireDefault(require("../utils/LoadingElement"));
|
|
12
12
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
13
|
-
|
|
14
|
-
function
|
|
13
|
+
var cache;
|
|
14
|
+
function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var r, c, a = Object.defineProperty, n = { __proto__: null, default: e }; if (Object(e) !== e) return n; if (cache || "function" != typeof WeakMap || (cache = new WeakMap()), cache) { if (cache.has(e)) return cache.get(e); cache.set(e, n); } for (c in e) "default" !== c && {}.hasOwnProperty.call(e, c) && ((r = a && Object.getOwnPropertyDescriptor(e, c)) && (r.get || r.set) ? a(n, c, r) : n[c] = e[c]); return n; }
|
|
15
|
+
function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? (c > 1 && (G.n = c < 3 ? -1 : u), d(c, u)) : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i.return) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
|
|
15
16
|
function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); } r ? i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2)); }, _regeneratorDefine2(e, r, n, t); }
|
|
16
17
|
function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
|
|
17
18
|
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
@@ -26,7 +27,7 @@ function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Can
|
|
|
26
27
|
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
|
|
27
28
|
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
28
29
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
29
|
-
function _toPrimitive(t,
|
|
30
|
+
function _toPrimitive(t, e) { if ("object" != _typeof(t) || !t) return t; var r; if ("undefined" != typeof Symbol && void 0 !== (r = t[Symbol.toPrimitive])) { var i = r.call(t, e || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === e ? String : Number)(t); }
|
|
30
31
|
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
31
32
|
function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); }
|
|
32
33
|
function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
|
package/lib/types.ts
CHANGED
|
@@ -12,7 +12,7 @@ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbol
|
|
|
12
12
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
13
13
|
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
14
14
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
15
|
-
function _toPrimitive(t,
|
|
15
|
+
function _toPrimitive(t, e) { if ("object" != _typeof(t) || !t) return t; var r; if ("undefined" != typeof Symbol && void 0 !== (r = t[Symbol.toPrimitive])) { var i = r.call(t, e || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === e ? String : Number)(t); }
|
|
16
16
|
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
|
|
17
17
|
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
|
|
18
18
|
/**
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
@@ -8,7 +7,8 @@ exports.default = void 0;
|
|
|
8
7
|
var _react = _interopRequireWildcard(require("react"));
|
|
9
8
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
10
9
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
|
-
|
|
10
|
+
var cache;
|
|
11
|
+
function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var r, c, a = Object.defineProperty, n = { __proto__: null, default: e }; if (Object(e) !== e) return n; if (cache || "function" != typeof WeakMap || (cache = new WeakMap()), cache) { if (cache.has(e)) return cache.get(e); cache.set(e, n); } for (c in e) "default" !== c && {}.hasOwnProperty.call(e, c) && ((r = a && Object.getOwnPropertyDescriptor(e, c)) && (r.get || r.set) ? a(n, c, r) : n[c] = e[c]); return n; }
|
|
12
12
|
// Debounce 50 ms
|
|
13
13
|
var DELAY = 50;
|
|
14
14
|
var ResizeDetector = function ResizeDetector(props) {
|
|
@@ -26,11 +26,11 @@ function HighlightedCode({className, children}: ReactMarkdownCodeProps) {
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
export default function CodeRenderer({
|
|
29
|
-
|
|
29
|
+
node,
|
|
30
30
|
className,
|
|
31
31
|
children,
|
|
32
32
|
}: ReactMarkdownCodeProps) {
|
|
33
|
-
if (
|
|
33
|
+
if (!node?.data?.block) {
|
|
34
34
|
return <code className={className}>{children}</code>;
|
|
35
35
|
}
|
|
36
36
|
return <HighlightedCode className={className}>{children}</HighlightedCode>;
|
|
@@ -3,13 +3,12 @@ import type {Element} from 'hast';
|
|
|
3
3
|
|
|
4
4
|
// Here we declare react-markdown's internal types that it will pass to our
|
|
5
5
|
// components. See:
|
|
6
|
-
// https://github.com/remarkjs/react-markdown/tree/
|
|
6
|
+
// https://github.com/remarkjs/react-markdown/tree/10.1.0#appendix-b-components
|
|
7
7
|
export type ReactMarkdownGenericProps = {
|
|
8
8
|
node?: Element;
|
|
9
9
|
children?: ReactNode;
|
|
10
10
|
};
|
|
11
11
|
|
|
12
12
|
export type ReactMarkdownCodeProps = ReactMarkdownGenericProps & {
|
|
13
|
-
inline?: boolean;
|
|
14
13
|
className?: string;
|
|
15
14
|
};
|
|
@@ -3,8 +3,10 @@ import remarkGfm from 'remark-gfm';
|
|
|
3
3
|
import remarkMath from 'remark-math';
|
|
4
4
|
import rehypeRaw from 'rehype-raw';
|
|
5
5
|
|
|
6
|
+
import rehypeBlockCode from './rehypeBlockCode';
|
|
6
7
|
import rehypeDashMath from './rehypeDashMath';
|
|
7
8
|
import rehypeDccComponents from './rehypeDccComponents';
|
|
9
|
+
import rehypeLinkTarget from './rehypeLinkTarget';
|
|
8
10
|
import rehypeStripTags from './rehypeStripTags';
|
|
9
11
|
|
|
10
12
|
// remark plugin for GitHub Flavored Markdown: tables, strikethrough,
|
|
@@ -26,3 +28,9 @@ export const rawHtmlPlugins: PluggableList = [
|
|
|
26
28
|
rehypeStripTags,
|
|
27
29
|
rehypeDccComponents,
|
|
28
30
|
];
|
|
31
|
+
|
|
32
|
+
// Always last, so they also see elements that rehype-raw parsed from raw HTML.
|
|
33
|
+
export const rehypeBlockCodePlugins: PluggableList = [rehypeBlockCode];
|
|
34
|
+
export const linkTargetPlugins = (target: string): PluggableList => [
|
|
35
|
+
[rehypeLinkTarget, target],
|
|
36
|
+
];
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type {Plugin} from 'unified';
|
|
2
|
+
import type {Root} from 'hast';
|
|
3
|
+
import {visit} from 'unist-util-visit';
|
|
4
|
+
|
|
5
|
+
declare module 'hast' {
|
|
6
|
+
interface ElementData {
|
|
7
|
+
block?: boolean;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// Flags `<code>` inside `<pre>` so the code renderer knows to highlight it.
|
|
12
|
+
// Replaces the `inline` prop react-markdown dropped in v9.
|
|
13
|
+
const rehypeBlockCode: Plugin<[], Root> = () => tree => {
|
|
14
|
+
visit(tree, 'element', (node, _index, parent) => {
|
|
15
|
+
if (
|
|
16
|
+
node.tagName === 'code' &&
|
|
17
|
+
parent?.type === 'element' &&
|
|
18
|
+
parent.tagName === 'pre'
|
|
19
|
+
) {
|
|
20
|
+
node.data = {...node.data, block: true};
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export default rehypeBlockCode;
|