dash-core-components 4.4.1 → 4.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/dash_core_components/async-datepicker.js +2 -1
  2. package/dash_core_components/async-datepicker.js.map +1 -1
  3. package/dash_core_components/async-dropdown.js.map +1 -1
  4. package/dash_core_components/async-graph.js +1 -1
  5. package/dash_core_components/async-graph.js.map +1 -1
  6. package/dash_core_components/async-highlight.js +1 -1
  7. package/dash_core_components/async-highlight.js.map +1 -1
  8. package/dash_core_components/async-markdown.js +1 -1
  9. package/dash_core_components/async-markdown.js.map +1 -1
  10. package/dash_core_components/async-mathjax.js +1 -1
  11. package/dash_core_components/async-slider.js +1 -1
  12. package/dash_core_components/async-slider.js.map +1 -1
  13. package/dash_core_components/async-upload.js +1 -1
  14. package/dash_core_components/async-upload.js.map +1 -1
  15. package/dash_core_components/dash_core_components-shared.js +1 -2
  16. package/dash_core_components/dash_core_components-shared.js.map +1 -1
  17. package/dash_core_components/dash_core_components.js +1 -1
  18. package/dash_core_components/dash_core_components.js.map +1 -1
  19. package/dash_core_components/proptypes.js +20 -0
  20. package/lib/components/Graph.react.js +1 -1
  21. package/lib/components/Input.tsx +3 -3
  22. package/lib/components/Link.tsx +79 -0
  23. package/lib/components/Markdown.tsx +35 -0
  24. package/lib/fragments/DatePickerRange.tsx +2 -0
  25. package/lib/fragments/DatePickerSingle.tsx +1 -0
  26. package/lib/fragments/Graph.react.js +6 -7
  27. package/lib/fragments/Markdown.tsx +101 -0
  28. package/lib/fragments/Upload.react.js +39 -27
  29. package/lib/index.ts +2 -2
  30. package/lib/types.ts +133 -0
  31. package/lib/utils/LazyLoader/markdown.ts +2 -0
  32. package/lib/utils/LazyLoader/third-party/highlight.ts +42 -0
  33. package/lib/utils/LazyLoader/third-party/hljs.ts +18 -0
  34. package/lib/utils/LazyLoader/third-party/mathjax.ts +23 -0
  35. package/lib/utils/LazyLoader/third-party/tex-svg.ts +5 -0
  36. package/lib/utils/markdown/components/Code.tsx +37 -0
  37. package/lib/utils/markdown/components/DccLink.tsx +25 -0
  38. package/lib/utils/markdown/components/DccMarkdown.tsx +13 -0
  39. package/lib/utils/markdown/components/MathJax.tsx +26 -0
  40. package/lib/utils/markdown/components/index.ts +13 -0
  41. package/lib/utils/markdown/components/jsx-renderers.d.ts +14 -0
  42. package/lib/utils/markdown/components/types.ts +15 -0
  43. package/lib/utils/markdown/context.ts +18 -0
  44. package/lib/utils/markdown/plugins/index.ts +28 -0
  45. package/lib/utils/markdown/plugins/rehypeDashMath.ts +69 -0
  46. package/lib/utils/markdown/plugins/rehypeDccComponents.ts +33 -0
  47. package/lib/utils/markdown/plugins/rehypeStripTags.ts +23 -0
  48. package/lib/utils/markdown/text.ts +64 -0
  49. package/package.json +10 -7
  50. package/lib/components/Link.react.js +0 -150
  51. package/lib/components/Markdown.react.js +0 -124
  52. package/lib/fragments/Markdown.react.js +0 -195
  53. package/lib/fragments/Math.react.js +0 -72
  54. package/lib/third-party/highlight.js +0 -46
  55. package/lib/utils/LazyLoader/hljs.js +0 -11
  56. package/lib/utils/LazyLoader/markdown.js +0 -9
  57. package/lib/utils/LazyLoader/mathjax.js +0 -11
  58. package/lib/utils/MarkdownHighlighter.js +0 -23
  59. package/lib/utils/mathjax.js +0 -4
@@ -173,6 +173,17 @@ pk.Input.propTypes = {value:pt.oneOfType([pt.string,pt.number]),
173
173
  persistence_type:pt.oneOf(['local','session','memory']),
174
174
  id:pt.oneOfType([pt.string]),
175
175
  componentPath:pt.any};
176
+ pk.Link.propTypes = {children:pt.node,
177
+ href:pt.string,
178
+ target:pt.oneOfType([pt.string]),
179
+ refresh:pt.oneOfType([pt.bool]),
180
+ scrollToTop:pt.oneOfType([pt.bool]),
181
+ title:pt.oneOfType([pt.string]),
182
+ className:pt.oneOfType([pt.string]),
183
+ style:pt.any,
184
+ id:pt.oneOfType([pt.string]),
185
+ loading_state:pt.oneOfType([pt.shape({is_loading:pt.oneOfType([pt.bool]),prop_name:pt.oneOfType([pt.string]),component_name:pt.oneOfType([pt.string])})]),
186
+ setProps:pt.oneOfType([pt.any])};
176
187
  pk.Loading.propTypes = {children:pt.node,
177
188
  type:pt.oneOf(['graph','cube','circle','dot','default']),
178
189
  fullscreen:pt.oneOfType([pt.bool]),
@@ -195,6 +206,15 @@ pk.Loading.propTypes = {children:pt.node,
195
206
  persistence_type:pt.oneOf(['local','session','memory']),
196
207
  id:pt.oneOfType([pt.string]),
197
208
  componentPath:pt.any};
209
+ pk.Markdown.propTypes = {id:pt.oneOfType([pt.string]),
210
+ className:pt.oneOfType([pt.string]),
211
+ children:pt.oneOfType([pt.string,pt.arrayOf(pt.string)]),
212
+ highlight_config:pt.oneOfType([pt.shape({theme:pt.oneOf(['dark','light'])})]),
213
+ style:pt.any,
214
+ mathjax:pt.oneOfType([pt.bool]),
215
+ dangerously_allow_html:pt.oneOfType([pt.bool]),
216
+ link_target:pt.oneOfType([pt.string]),
217
+ dedent:pt.oneOfType([pt.bool])};
198
218
  pk.RadioItems.propTypes = {options:pt.any,
199
219
  value:pt.oneOfType([pt.string,pt.number,pt.bool]),
200
220
  inline:pt.oneOfType([pt.bool]),
@@ -10,7 +10,7 @@ var _propTypes = _interopRequireDefault(require("prop-types"));
10
10
  var _dashComponentPlugins = require("@plotly/dash-component-plugins");
11
11
  var _graph = _interopRequireDefault(require("../utils/LazyLoader/graph"));
12
12
  var _plotly = _interopRequireDefault(require("../utils/LazyLoader/plotly"));
13
- var _mathjax = _interopRequireDefault(require("../utils/LazyLoader/mathjax"));
13
+ var _mathjax = _interopRequireDefault(require("../utils/LazyLoader/third-party/mathjax"));
14
14
  var _Graph = require("../fragments/Graph.privateprops");
15
15
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
16
16
  function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
@@ -128,7 +128,7 @@ function Input({
128
128
  setValue(value);
129
129
  }, []);
130
130
 
131
- const onKeyPress: KeyboardEventHandler<HTMLInputElement> = useCallback(
131
+ const onKeyDown: KeyboardEventHandler<HTMLInputElement> = useCallback(
132
132
  (e: KeyboardEvent) => {
133
133
  if (e.key === 'Enter') {
134
134
  props.setProps({
@@ -194,7 +194,7 @@ function Input({
194
194
  parseFloat(props.min as string)
195
195
  );
196
196
  }
197
- if (props.max !== null && props.min !== undefined) {
197
+ if (props.max !== null && props.max !== undefined) {
198
198
  constrainedValue = Math.min(
199
199
  constrainedValue,
200
200
  parseFloat(props.max as string)
@@ -288,7 +288,7 @@ function Input({
288
288
  className="dash-input-element"
289
289
  onBlur={onBlur}
290
290
  onChange={onChange}
291
- onKeyPress={onKeyPress}
291
+ onKeyDown={onKeyDown}
292
292
  {...valprops}
293
293
  {...pickedInputs}
294
294
  {...loadingProps}
@@ -0,0 +1,79 @@
1
+ import React, {useEffect, useMemo} from 'react';
2
+ import {isNil} from 'ramda';
3
+
4
+ import LoadingElement from '../utils/_LoadingElement';
5
+ import {LinkProps} from '../types';
6
+
7
+ type LinkComponentProps = LinkProps & {
8
+ setProps?: (props: Record<string, unknown>) => void;
9
+ };
10
+
11
+ /**
12
+ * Link allows you to create a clickable link within a multi-page app.
13
+ *
14
+ * For links with destinations outside the current app, `html.A` is a better
15
+ * component to use.
16
+ */
17
+ const Link = ({
18
+ refresh = false,
19
+ scrollToTop = true,
20
+ ...props
21
+ }: LinkComponentProps) => {
22
+ const {className, style, id, href, children, title, target, setProps} =
23
+ props;
24
+ const cleanUrl = window.dash_clientside.clean_url;
25
+ const sanitizedUrl = useMemo(() => {
26
+ return href ? cleanUrl(href) : undefined;
27
+ }, [href]);
28
+
29
+ const updateLocation = (e: React.MouseEvent<HTMLAnchorElement>) => {
30
+ const hasModifiers = e.metaKey || e.shiftKey || e.altKey || e.ctrlKey;
31
+
32
+ if (hasModifiers) {
33
+ return;
34
+ }
35
+ if (target !== '_self' && !isNil(target)) {
36
+ return;
37
+ }
38
+ // prevent anchor from updating location
39
+ e.preventDefault();
40
+ if (refresh) {
41
+ window.location.href = sanitizedUrl as string;
42
+ } else {
43
+ window.history.pushState({}, '', sanitizedUrl);
44
+ window.dispatchEvent(new CustomEvent('_dashprivate_pushstate'));
45
+ }
46
+ if (scrollToTop) {
47
+ window.scrollTo(0, 0);
48
+ }
49
+ };
50
+
51
+ useEffect(() => {
52
+ if (sanitizedUrl && sanitizedUrl !== href) {
53
+ setProps?.({
54
+ _dash_error: new Error(`Dangerous link detected:: ${href}`),
55
+ });
56
+ }
57
+ }, [href, sanitizedUrl]);
58
+
59
+ return (
60
+ <LoadingElement>
61
+ {loadingProps => (
62
+ <a
63
+ id={id}
64
+ className={className}
65
+ style={style}
66
+ href={sanitizedUrl}
67
+ onClick={updateLocation}
68
+ title={title}
69
+ target={target}
70
+ {...loadingProps}
71
+ >
72
+ {isNil(children) ? sanitizedUrl : children}
73
+ </a>
74
+ )}
75
+ </LoadingElement>
76
+ );
77
+ };
78
+
79
+ export default Link;
@@ -0,0 +1,35 @@
1
+ import React, {lazy, Suspense, useEffect} from 'react';
2
+ import {MarkdownProps} from '../types';
3
+ import markdown from '../utils/LazyLoader/markdown';
4
+ import lazyLoadMathJax from '../utils/LazyLoader/third-party/mathjax';
5
+
6
+ const RealMarkdown = lazy(markdown);
7
+
8
+ /**
9
+ * A component that renders Markdown text as specified by the
10
+ * GitHub Markdown spec. These component uses
11
+ * [react-markdown](https://github.com/remarkjs/react-markdown) under the hood.
12
+ */
13
+ export default function Markdown({
14
+ mathjax = false,
15
+ dangerously_allow_html = false,
16
+ dedent = true,
17
+ ...props
18
+ }: MarkdownProps) {
19
+ useEffect(() => {
20
+ if (mathjax) {
21
+ lazyLoadMathJax();
22
+ }
23
+ }, [mathjax]);
24
+
25
+ return (
26
+ <Suspense fallback={null}>
27
+ <RealMarkdown
28
+ mathjax={mathjax}
29
+ dangerously_allow_html={dangerously_allow_html}
30
+ dedent={dedent}
31
+ {...props}
32
+ />
33
+ </Suspense>
34
+ );
35
+ }
@@ -405,6 +405,7 @@ const DatePickerRange = ({
405
405
  disabled={disabled}
406
406
  dir={direction}
407
407
  aria-label={start_date_placeholder_text}
408
+ autoComplete="off"
408
409
  />
409
410
  <ArrowIcon className="dash-datepicker-range-arrow" />
410
411
  <AutosizeInput
@@ -427,6 +428,7 @@ const DatePickerRange = ({
427
428
  disabled={disabled}
428
429
  dir={direction}
429
430
  aria-label={end_date_placeholder_text}
431
+ autoComplete="off"
430
432
  />
431
433
  {clearable && !disabled && (
432
434
  <a
@@ -204,6 +204,7 @@ const DatePickerSingle = ({
204
204
  disabled={disabled}
205
205
  dir={direction}
206
206
  aria-label={placeholder}
207
+ autoComplete="off"
207
208
  />
208
209
  {clearable && !disabled && !!date && (
209
210
  <a
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- var _mathjax = _interopRequireDefault(require("../utils/LazyLoader/mathjax"));
7
+ var _mathjax = _interopRequireDefault(require("../utils/LazyLoader/third-party/mathjax"));
8
8
  var _react = _interopRequireWildcard(require("react"));
9
9
  var _ramda = require("ramda");
10
10
  var _propTypes = _interopRequireDefault(require("prop-types"));
@@ -121,12 +121,11 @@ var filterEventData = function filterEventData(gd, eventData, event) {
121
121
  };
122
122
  var includeXYVals = event === 'hover' && gd._fullLayout.hoveranywhere === true || event === 'click' && gd._fullLayout.clickanywhere === true;
123
123
  if (includeXYVals) {
124
- if ((0, _ramda.has)('xvals', eventData)) {
125
- filteredEventData.xvals = eventData.xvals;
126
- }
127
- if ((0, _ramda.has)('yvals', eventData)) {
128
- filteredEventData.yvals = eventData.yvals;
129
- }
124
+ ['xvals', 'yvals', 'xPixel', 'yPixel'].forEach(function (key) {
125
+ if ((0, _ramda.has)(key, eventData)) {
126
+ filteredEventData[key] = eventData[key];
127
+ }
128
+ });
130
129
  if ((0, _ramda.has)('xaxes', eventData)) {
131
130
  filteredEventData.xaxes_id = eventData.xaxes[0]._id;
132
131
  }
@@ -0,0 +1,101 @@
1
+ import React, {useCallback, useMemo} from 'react';
2
+ import ReactMarkdown from 'react-markdown';
3
+ import type {PluggableList} from 'unified';
4
+
5
+ import LoadingElement from '../utils/_LoadingElement';
6
+ import {MarkdownContentProps, MarkdownProps} from '../types';
7
+ import {components} from '../utils/markdown/components';
8
+ import {MarkdownContext} from '../utils/markdown/context';
9
+ import {
10
+ rawHtmlPlugins,
11
+ rehypeMathPlugins,
12
+ remarkMathPlugins,
13
+ remarkGfmPlugins,
14
+ } from '../utils/markdown/plugins';
15
+ import {dedentText} from '../utils/markdown/text';
16
+
17
+ const MarkdownContent = React.memo(function MarkdownContent({
18
+ children,
19
+ dedent,
20
+ dangerously_allow_html,
21
+ mathjax,
22
+ link_target,
23
+ }: MarkdownContentProps & {children: string}) {
24
+ const displayText = dedent && children ? dedentText(children) : children;
25
+
26
+ const remarkPlugins: PluggableList = [...remarkGfmPlugins];
27
+ const rehypePlugins: PluggableList = [];
28
+ if (mathjax) {
29
+ remarkPlugins.push(...remarkMathPlugins);
30
+ rehypePlugins.push(...rehypeMathPlugins);
31
+ }
32
+ if (dangerously_allow_html) {
33
+ rehypePlugins.push(...rawHtmlPlugins);
34
+ }
35
+
36
+ return (
37
+ <ReactMarkdown
38
+ linkTarget={link_target}
39
+ remarkPlugins={remarkPlugins}
40
+ rehypePlugins={rehypePlugins}
41
+ components={components}
42
+ >
43
+ {displayText}
44
+ </ReactMarkdown>
45
+ );
46
+ });
47
+
48
+ function MarkdownContainer({
49
+ id,
50
+ style,
51
+ className,
52
+ highlight_config,
53
+ dangerously_allow_html,
54
+ link_target,
55
+ mathjax,
56
+ children,
57
+ dedent,
58
+ }: MarkdownProps) {
59
+ const textProp = Array.isArray(children) ? children.join('\n') : children;
60
+
61
+ const classNames = [
62
+ className,
63
+ highlight_config?.theme === 'dark' ? 'hljs-dark' : '',
64
+ ].filter(Boolean);
65
+
66
+ // provides a recursive method to render nested markdown elements
67
+ const renderMarkdown = useCallback(
68
+ (text: string) => (
69
+ <MarkdownContent
70
+ dedent={dedent}
71
+ dangerously_allow_html={dangerously_allow_html}
72
+ mathjax={mathjax}
73
+ link_target={link_target}
74
+ >
75
+ {text}
76
+ </MarkdownContent>
77
+ ),
78
+ [dedent, dangerously_allow_html, mathjax, link_target]
79
+ );
80
+
81
+ const markdownContext = useMemo(() => ({renderMarkdown}), [renderMarkdown]);
82
+
83
+ return (
84
+ <LoadingElement>
85
+ {loadingProps => (
86
+ <div
87
+ id={id}
88
+ style={style}
89
+ className={classNames.join(' ')}
90
+ {...loadingProps}
91
+ >
92
+ <MarkdownContext.Provider value={markdownContext}>
93
+ {renderMarkdown(textProp ?? '')}
94
+ </MarkdownContext.Provider>
95
+ </div>
96
+ )}
97
+ </LoadingElement>
98
+ );
99
+ }
100
+
101
+ export default MarkdownContainer;
@@ -195,7 +195,7 @@ var Upload = exports.default = /*#__PURE__*/function (_Component) {
195
195
  key: "getDataTransferItems",
196
196
  value: function () {
197
197
  var _getDataTransferItems = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(event) {
198
- var multiple, items, files, _i, _items, item, entry, entryFiles, file;
198
+ var multiple, items, entries, files, _i, _items, item, entry, file, _i2, _entries, _entry, entryFiles;
199
199
  return _regenerator().w(function (_context3) {
200
200
  while (1) switch (_context3.n) {
201
201
  case 0:
@@ -219,59 +219,71 @@ var Upload = exports.default = /*#__PURE__*/function (_Component) {
219
219
  return _context3.a(2, []);
220
220
  case 3:
221
221
  if (!(event.dataTransfer && event.dataTransfer.items)) {
222
- _context3.n = 9;
222
+ _context3.n = 12;
223
223
  break;
224
224
  }
225
- items = Array.from(event.dataTransfer.items);
225
+ items = Array.from(event.dataTransfer.items); // Get all entries synchronously before the first await
226
+ entries = [];
226
227
  files = [];
227
228
  _i = 0, _items = items;
228
229
  case 4:
229
230
  if (!(_i < _items.length)) {
230
- _context3.n = 8;
231
+ _context3.n = 7;
231
232
  break;
232
233
  }
233
234
  item = _items[_i];
234
- if (!(item.kind === 'file')) {
235
- _context3.n = 7;
235
+ if (!(item.kind !== 'file')) {
236
+ _context3.n = 5;
236
237
  break;
237
238
  }
239
+ return _context3.a(3, 6);
240
+ case 5:
238
241
  entry = item.webkitGetAsEntry ? item.webkitGetAsEntry() : null;
239
- if (!entry) {
240
- _context3.n = 6;
241
- break;
242
+ if (entry) {
243
+ entries.push(entry);
244
+ } else {
245
+ // Fallback for browsers without webkitGetAsEntry
246
+ file = item.getAsFile();
247
+ if (file) {
248
+ files.push(file);
249
+ }
242
250
  }
243
- _context3.n = 5;
244
- return this.traverseFileTree(entry);
245
- case 5:
246
- entryFiles = _context3.v;
247
- files.push.apply(files, _toConsumableArray(entryFiles));
248
- _context3.n = 7;
249
- break;
250
251
  case 6:
251
- // Fallback for browsers without webkitGetAsEntry
252
- file = item.getAsFile();
253
- if (file) {
254
- files.push(file);
255
- }
256
- case 7:
257
252
  _i++;
258
253
  _context3.n = 4;
259
254
  break;
255
+ case 7:
256
+ _i2 = 0, _entries = entries;
260
257
  case 8:
261
- return _context3.a(2, files);
258
+ if (!(_i2 < _entries.length)) {
259
+ _context3.n = 11;
260
+ break;
261
+ }
262
+ _entry = _entries[_i2];
263
+ _context3.n = 9;
264
+ return this.traverseFileTree(_entry);
262
265
  case 9:
266
+ entryFiles = _context3.v;
267
+ files.push.apply(files, _toConsumableArray(entryFiles));
268
+ case 10:
269
+ _i2++;
270
+ _context3.n = 8;
271
+ break;
272
+ case 11:
273
+ return _context3.a(2, files);
274
+ case 12:
263
275
  if (!(event.target && event.target.files)) {
264
- _context3.n = 10;
276
+ _context3.n = 13;
265
277
  break;
266
278
  }
267
279
  return _context3.a(2, Array.from(event.target.files));
268
- case 10:
280
+ case 13:
269
281
  if (!(event.dataTransfer && event.dataTransfer.files)) {
270
- _context3.n = 11;
282
+ _context3.n = 14;
271
283
  break;
272
284
  }
273
285
  return _context3.a(2, Array.from(event.dataTransfer.files));
274
- case 11:
286
+ case 14:
275
287
  return _context3.a(2, []);
276
288
  }
277
289
  }, _callee3, this);
package/lib/index.ts CHANGED
@@ -12,10 +12,10 @@ import Geolocation from './components/Geolocation.react';
12
12
  import Graph from './components/Graph.react';
13
13
  import Input from './components/Input';
14
14
  import Interval from './components/Interval.react';
15
- import Link from './components/Link.react';
15
+ import Link from './components/Link';
16
16
  import Loading from './components/Loading';
17
17
  import Location from './components/Location.react';
18
- import Markdown from './components/Markdown.react';
18
+ import Markdown from './components/Markdown';
19
19
  import RadioItems from './components/RadioItems';
20
20
  import RangeSlider from './components/RangeSlider';
21
21
  import Slider from './components/Slider';
package/lib/types.ts CHANGED
@@ -1492,3 +1492,136 @@ export interface DatePickerRangeProps
1492
1492
 
1493
1493
  setProps: (props: Partial<DatePickerRangeProps>) => void;
1494
1494
  }
1495
+
1496
+ export interface LinkProps {
1497
+ /**
1498
+ * The children of this component
1499
+ */
1500
+ children?: React.ReactNode;
1501
+
1502
+ /**
1503
+ * The URL of a linked resource.
1504
+ */
1505
+ href: string;
1506
+
1507
+ /**
1508
+ * Specifies where to open the link reference.
1509
+ */
1510
+ target?: string;
1511
+
1512
+ /**
1513
+ * Controls whether or not the page will refresh when the link is clicked
1514
+ */
1515
+ refresh?: boolean;
1516
+
1517
+ /**
1518
+ * Controls whether or not the page will scroll to the top when the link is
1519
+ * clicked. Defaults to true.
1520
+ */
1521
+ scrollToTop?: boolean;
1522
+
1523
+ /**
1524
+ * Adds the title attribute to your link, which can contain supplementary
1525
+ * information.
1526
+ */
1527
+ title?: string;
1528
+
1529
+ /**
1530
+ * Often used with CSS to style elements with common properties.
1531
+ */
1532
+ className?: string;
1533
+
1534
+ /**
1535
+ * Defines CSS styles which will override styles previously set.
1536
+ */
1537
+ style?: React.CSSProperties;
1538
+
1539
+ /**
1540
+ * The ID of this component, used to identify dash components
1541
+ * in callbacks. The ID needs to be unique across all of the
1542
+ * components in an app.
1543
+ */
1544
+ id?: string;
1545
+
1546
+ /**
1547
+ * Object that holds the loading state object coming from dash-renderer
1548
+ */
1549
+ loading_state?: {
1550
+ /**
1551
+ * Determines if the component is loading or not
1552
+ */
1553
+ is_loading?: boolean;
1554
+ /**
1555
+ * Holds which property is loading
1556
+ */
1557
+ prop_name?: string;
1558
+ /**
1559
+ * Holds the name of the component that is loading
1560
+ */
1561
+ component_name?: string;
1562
+ };
1563
+ }
1564
+
1565
+ export interface MarkdownContentProps {
1566
+ /**
1567
+ * If true, loads mathjax v3 (tex-svg) into the page and use it in the markdown
1568
+ */
1569
+ mathjax?: boolean;
1570
+
1571
+ /**
1572
+ * A boolean to control raw HTML escaping.
1573
+ * Setting HTML from code is risky because it's easy to
1574
+ * inadvertently expose your users to a cross-site scripting (XSS)
1575
+ * (https://en.wikipedia.org/wiki/Cross-site_scripting) attack.
1576
+ */
1577
+ dangerously_allow_html?: boolean;
1578
+
1579
+ /**
1580
+ * A string for the target attribute to use on links (such as "_blank")
1581
+ */
1582
+ link_target?: string;
1583
+
1584
+ /**
1585
+ * Remove matching leading whitespace from all lines.
1586
+ * Lines that are empty, or contain *only* whitespace, are ignored.
1587
+ * Both spaces and tab characters are removed, but only if they match;
1588
+ * we will not convert tabs to spaces or vice versa.
1589
+ */
1590
+ dedent?: boolean;
1591
+ }
1592
+
1593
+ // Markdown is a display-only component: it has no persistence and does not
1594
+ // call `setProps`, so it deliberately does not extend `BaseDccProps`.
1595
+ export interface MarkdownProps extends MarkdownContentProps {
1596
+ /**
1597
+ * The ID of this component, used to identify dash components
1598
+ * in callbacks. The ID needs to be unique across all of the
1599
+ * components in an app.
1600
+ */
1601
+ id?: string;
1602
+
1603
+ /**
1604
+ * Class name of the container element
1605
+ */
1606
+ className?: string;
1607
+
1608
+ /**
1609
+ * A markdown string (or array of strings) that adheres to the CommonMark spec
1610
+ */
1611
+ children?: string | string[];
1612
+
1613
+ /**
1614
+ * Config options for syntax highlighting.
1615
+ */
1616
+ highlight_config?: {
1617
+ /**
1618
+ * Color scheme; default 'light'
1619
+ */
1620
+ theme?: 'dark' | 'light';
1621
+ };
1622
+
1623
+ /**
1624
+ * User-defined inline styles for the rendered Markdown
1625
+ */
1626
+ style?: React.CSSProperties;
1627
+ }
@@ -0,0 +1,2 @@
1
+ export default () =>
2
+ import(/* webpackChunkName: "markdown" */ '../../fragments/Markdown');
@@ -0,0 +1,42 @@
1
+ import highlightjs from 'highlight.js/lib/core';
2
+ import 'highlight.js/styles/github.css';
3
+
4
+ import bash from 'highlight.js/lib/languages/bash';
5
+ import csharp from 'highlight.js/lib/languages/csharp';
6
+ import css from 'highlight.js/lib/languages/css';
7
+ import fsharp from 'highlight.js/lib/languages/fsharp';
8
+ import http from 'highlight.js/lib/languages/http';
9
+ import javascript from 'highlight.js/lib/languages/javascript';
10
+ import json from 'highlight.js/lib/languages/json';
11
+ import julia from 'highlight.js/lib/languages/julia';
12
+ import markdown from 'highlight.js/lib/languages/markdown';
13
+ import matlab from 'highlight.js/lib/languages/matlab';
14
+ import plaintext from 'highlight.js/lib/languages/plaintext';
15
+ import python from 'highlight.js/lib/languages/python';
16
+ import r from 'highlight.js/lib/languages/r';
17
+ import ruby from 'highlight.js/lib/languages/ruby';
18
+ import shell from 'highlight.js/lib/languages/shell';
19
+ import sql from 'highlight.js/lib/languages/sql';
20
+ import xml from 'highlight.js/lib/languages/xml';
21
+ import yaml from 'highlight.js/lib/languages/yaml';
22
+
23
+ highlightjs.registerLanguage('bash', bash);
24
+ highlightjs.registerLanguage('csharp', csharp);
25
+ highlightjs.registerLanguage('css', css);
26
+ highlightjs.registerLanguage('fsharp', fsharp);
27
+ highlightjs.registerLanguage('http', http);
28
+ highlightjs.registerLanguage('javascript', javascript);
29
+ highlightjs.registerLanguage('json', json);
30
+ highlightjs.registerLanguage('julia', julia);
31
+ highlightjs.registerLanguage('markdown', markdown);
32
+ highlightjs.registerLanguage('matlab', matlab);
33
+ highlightjs.registerLanguage('plaintext', plaintext);
34
+ highlightjs.registerLanguage('python', python);
35
+ highlightjs.registerLanguage('r', r);
36
+ highlightjs.registerLanguage('ruby', ruby);
37
+ highlightjs.registerLanguage('shell', shell);
38
+ highlightjs.registerLanguage('sql', sql);
39
+ highlightjs.registerLanguage('xml', xml);
40
+ highlightjs.registerLanguage('yaml', yaml);
41
+
42
+ export default highlightjs;
@@ -0,0 +1,18 @@
1
+ import type {HLJSApi} from 'highlight.js';
2
+
3
+ declare global {
4
+ interface Window {
5
+ hljs?: HLJSApi;
6
+ }
7
+ }
8
+
9
+ // Reuse a highlight.js instance already on `window` (e.g. supplied by the host
10
+ // page), otherwise lazily load the bundled third-party build.
11
+ export default function lazyLoadHljs(): Promise<HLJSApi> {
12
+ return Promise.resolve(
13
+ window.hljs ??
14
+ import(/* webpackChunkName: "highlight" */ './highlight').then(
15
+ mod => mod.default as HLJSApi
16
+ )
17
+ );
18
+ }