dash-core-components 4.4.0 → 4.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dash_core_components/async-datepicker.js +2 -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 -1
- package/dash_core_components/async-markdown.js.map +1 -1
- package/dash_core_components/async-mathjax.js +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 -2
- 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 +19 -0
- package/lib/components/Graph.react.js +1 -1
- package/lib/components/Input.tsx +3 -3
- package/lib/components/Link.tsx +74 -0
- package/lib/components/Markdown.tsx +35 -0
- package/lib/fragments/Graph.react.js +31 -25
- package/lib/fragments/Markdown.tsx +101 -0
- package/lib/fragments/Upload.react.js +39 -27
- package/lib/index.ts +2 -2
- package/lib/types.ts +127 -0
- package/lib/utils/LazyLoader/markdown.ts +2 -0
- package/lib/utils/LazyLoader/third-party/highlight.ts +42 -0
- package/lib/utils/LazyLoader/third-party/hljs.ts +18 -0
- package/lib/utils/LazyLoader/third-party/mathjax.ts +23 -0
- package/lib/utils/LazyLoader/third-party/tex-svg.ts +5 -0
- package/lib/utils/markdown/components/Code.tsx +37 -0
- package/lib/utils/markdown/components/DccLink.tsx +25 -0
- package/lib/utils/markdown/components/DccMarkdown.tsx +13 -0
- package/lib/utils/markdown/components/MathJax.tsx +26 -0
- package/lib/utils/markdown/components/index.ts +13 -0
- package/lib/utils/markdown/components/jsx-renderers.d.ts +14 -0
- package/lib/utils/markdown/components/types.ts +15 -0
- package/lib/utils/markdown/context.ts +18 -0
- package/lib/utils/markdown/plugins/index.ts +28 -0
- package/lib/utils/markdown/plugins/rehypeDashMath.ts +69 -0
- package/lib/utils/markdown/plugins/rehypeDccComponents.ts +33 -0
- package/lib/utils/markdown/plugins/rehypeStripTags.ts +23 -0
- package/lib/utils/markdown/text.ts +64 -0
- package/package.json +13 -10
- package/lib/components/Link.react.js +0 -150
- package/lib/components/Markdown.react.js +0 -124
- package/lib/fragments/Markdown.react.js +0 -195
- package/lib/fragments/Math.react.js +0 -72
- package/lib/third-party/highlight.js +0 -46
- package/lib/utils/LazyLoader/hljs.js +0 -11
- package/lib/utils/LazyLoader/markdown.js +0 -9
- package/lib/utils/LazyLoader/mathjax.js +0 -11
- package/lib/utils/MarkdownHighlighter.js +0 -23
- package/lib/utils/mathjax.js +0 -4
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
interface MathJaxObject {
|
|
2
|
+
typeset: (elements?: (HTMLElement | null)[]) => void;
|
|
3
|
+
config: {startup: {typeset: boolean}};
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
declare global {
|
|
7
|
+
interface Window {
|
|
8
|
+
MathJax?: MathJaxObject;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export default function lazyLoadMathJax(
|
|
13
|
+
mathjax?: boolean
|
|
14
|
+
): Promise<MathJaxObject | undefined> {
|
|
15
|
+
return Promise.resolve(
|
|
16
|
+
window.MathJax ||
|
|
17
|
+
(mathjax === false
|
|
18
|
+
? undefined
|
|
19
|
+
: import(/* webpackChunkName: "mathjax" */ './tex-svg').then(
|
|
20
|
+
() => window.MathJax
|
|
21
|
+
))
|
|
22
|
+
);
|
|
23
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import React, {useEffect, useRef} from 'react';
|
|
2
|
+
|
|
3
|
+
import lazyLoadHljs from '../../LazyLoader/third-party/hljs';
|
|
4
|
+
import {reactNodeToText} from '../text';
|
|
5
|
+
import type {ReactMarkdownCodeProps} from './types';
|
|
6
|
+
|
|
7
|
+
function HighlightedCode({className, children}: ReactMarkdownCodeProps) {
|
|
8
|
+
const ref = useRef<HTMLElement>(null);
|
|
9
|
+
const code = reactNodeToText(children);
|
|
10
|
+
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
const node = ref.current;
|
|
13
|
+
if (!node) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
// Reset to the raw source first so any stale highlight spans from a
|
|
17
|
+
// previous render are discarded before re-highlighting.
|
|
18
|
+
node.textContent = code;
|
|
19
|
+
lazyLoadHljs().then(hljs => {
|
|
20
|
+
node.removeAttribute('data-highlighted');
|
|
21
|
+
hljs.highlightElement(node);
|
|
22
|
+
});
|
|
23
|
+
}, [code, className]);
|
|
24
|
+
|
|
25
|
+
return <code ref={ref} className={className} />;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export default function CodeRenderer({
|
|
29
|
+
inline,
|
|
30
|
+
className,
|
|
31
|
+
children,
|
|
32
|
+
}: ReactMarkdownCodeProps) {
|
|
33
|
+
if (inline) {
|
|
34
|
+
return <code className={className}>{children}</code>;
|
|
35
|
+
}
|
|
36
|
+
return <HighlightedCode className={className}>{children}</HighlightedCode>;
|
|
37
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type {Properties} from 'hast';
|
|
3
|
+
|
|
4
|
+
import DccLink from '../../../components/Link';
|
|
5
|
+
import type {ReactMarkdownGenericProps} from './types';
|
|
6
|
+
|
|
7
|
+
export default function DccLinkRenderer({
|
|
8
|
+
node,
|
|
9
|
+
children,
|
|
10
|
+
}: ReactMarkdownGenericProps) {
|
|
11
|
+
const properties: Properties = node?.properties ?? {};
|
|
12
|
+
const content =
|
|
13
|
+
node && node.children.length
|
|
14
|
+
? children
|
|
15
|
+
: (properties.children as React.ReactNode);
|
|
16
|
+
return (
|
|
17
|
+
<DccLink
|
|
18
|
+
href={properties.href as string}
|
|
19
|
+
target={properties.target as string}
|
|
20
|
+
title={properties.title as string}
|
|
21
|
+
>
|
|
22
|
+
{content}
|
|
23
|
+
</DccLink>
|
|
24
|
+
);
|
|
25
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
import {useMarkdownContext} from '../context';
|
|
4
|
+
import {collectText} from '../text';
|
|
5
|
+
import type {ReactMarkdownGenericProps} from './types';
|
|
6
|
+
|
|
7
|
+
export default function DccMarkdownRenderer({node}: ReactMarkdownGenericProps) {
|
|
8
|
+
const {renderMarkdown} = useMarkdownContext();
|
|
9
|
+
const content = String(
|
|
10
|
+
node?.properties?.children ?? collectText(node?.children)
|
|
11
|
+
);
|
|
12
|
+
return <>{renderMarkdown(content)}</>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import React, {useEffect, useRef} from 'react';
|
|
2
|
+
|
|
3
|
+
import lazyLoadMathJax from '../../LazyLoader/third-party/mathjax';
|
|
4
|
+
import {collectText} from '../text';
|
|
5
|
+
import type {ReactMarkdownGenericProps} from './types';
|
|
6
|
+
|
|
7
|
+
export default function MathJaxRenderer({node}: ReactMarkdownGenericProps) {
|
|
8
|
+
const tex = collectText(node?.children);
|
|
9
|
+
const inline = node?.properties?.inline !== 'false';
|
|
10
|
+
const spanRef = useRef<HTMLSpanElement>(null);
|
|
11
|
+
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
const current = spanRef.current;
|
|
14
|
+
lazyLoadMathJax().then(mathjax => {
|
|
15
|
+
mathjax?.typeset([current]);
|
|
16
|
+
});
|
|
17
|
+
}, [tex, inline]);
|
|
18
|
+
|
|
19
|
+
return (
|
|
20
|
+
<span ref={spanRef}>
|
|
21
|
+
{inline ? '\\(' : '\\['}
|
|
22
|
+
{tex}
|
|
23
|
+
{inline ? '\\)' : '\\]'}
|
|
24
|
+
</span>
|
|
25
|
+
);
|
|
26
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type {Components} from 'react-markdown';
|
|
2
|
+
|
|
3
|
+
import CodeRenderer from './Code';
|
|
4
|
+
import DccLinkRenderer from './DccLink';
|
|
5
|
+
import DccMarkdownRenderer from './DccMarkdown';
|
|
6
|
+
import MathJaxRenderer from './MathJax';
|
|
7
|
+
|
|
8
|
+
export const components: Components = {
|
|
9
|
+
dcclink: DccLinkRenderer,
|
|
10
|
+
dccmarkdown: DccMarkdownRenderer,
|
|
11
|
+
dashmathjax: MathJaxRenderer,
|
|
12
|
+
code: CodeRenderer,
|
|
13
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// Custom HTML tags need to be added to a global namespace for type safety
|
|
2
|
+
// Registering them here is the approach react-markdown's authors endorse
|
|
3
|
+
// (https://github.com/remarkjs/react-markdown/issues/622)
|
|
4
|
+
import 'react';
|
|
5
|
+
|
|
6
|
+
declare global {
|
|
7
|
+
namespace JSX {
|
|
8
|
+
interface IntrinsicElements {
|
|
9
|
+
dcclink: React.HTMLAttributes<HTMLElement>;
|
|
10
|
+
dccmarkdown: React.HTMLAttributes<HTMLElement>;
|
|
11
|
+
dashmathjax: React.HTMLAttributes<HTMLElement>;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type {ReactNode} from 'react';
|
|
2
|
+
import type {Element} from 'hast';
|
|
3
|
+
|
|
4
|
+
// Here we declare react-markdown's internal types that it will pass to our
|
|
5
|
+
// components. See:
|
|
6
|
+
// https://github.com/remarkjs/react-markdown/tree/8.0.7#appendix-b-components
|
|
7
|
+
export type ReactMarkdownGenericProps = {
|
|
8
|
+
node?: Element;
|
|
9
|
+
children?: ReactNode;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export type ReactMarkdownCodeProps = ReactMarkdownGenericProps & {
|
|
13
|
+
inline?: boolean;
|
|
14
|
+
className?: string;
|
|
15
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import {createContext, useContext} from 'react';
|
|
2
|
+
import type {ReactNode} from 'react';
|
|
3
|
+
|
|
4
|
+
export type MarkdownContextValue = {
|
|
5
|
+
renderMarkdown: (text: string) => ReactNode;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export const MarkdownContext = createContext<MarkdownContextValue | undefined>(
|
|
9
|
+
undefined
|
|
10
|
+
);
|
|
11
|
+
|
|
12
|
+
export function useMarkdownContext(): MarkdownContextValue {
|
|
13
|
+
const value = useContext(MarkdownContext);
|
|
14
|
+
if (!value) {
|
|
15
|
+
throw new Error('MarkdownContext used outside of its provider');
|
|
16
|
+
}
|
|
17
|
+
return value;
|
|
18
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type {PluggableList} from 'unified';
|
|
2
|
+
import remarkGfm from 'remark-gfm';
|
|
3
|
+
import remarkMath from 'remark-math';
|
|
4
|
+
import rehypeRaw from 'rehype-raw';
|
|
5
|
+
|
|
6
|
+
import rehypeDashMath from './rehypeDashMath';
|
|
7
|
+
import rehypeDccComponents from './rehypeDccComponents';
|
|
8
|
+
import rehypeStripTags from './rehypeStripTags';
|
|
9
|
+
|
|
10
|
+
// remark plugin for GitHub Flavored Markdown: tables, strikethrough,
|
|
11
|
+
// task lists, autolinks, etc.
|
|
12
|
+
export const remarkGfmPlugins: PluggableList = [remarkGfm];
|
|
13
|
+
|
|
14
|
+
// remark plugin for the `mathjax` prop: remark-math parses `$...$`/`$$...$$` in
|
|
15
|
+
// Markdown at the token level, so it leaves `\$` and `$` as literal dollars.
|
|
16
|
+
export const remarkMathPlugins: PluggableList = [remarkMath];
|
|
17
|
+
|
|
18
|
+
// rehype plugin for the `mathjax` prop: routes both Markdown and raw-HTML math
|
|
19
|
+
// into <dashmathjax>. Must run before rehype-raw.
|
|
20
|
+
export const rehypeMathPlugins: PluggableList = [rehypeDashMath];
|
|
21
|
+
|
|
22
|
+
// rehype pipeline that powers raw-HTML support for `dangerously_allow_html`.
|
|
23
|
+
// Order matters: rehype-raw must come first.
|
|
24
|
+
export const rawHtmlPlugins: PluggableList = [
|
|
25
|
+
rehypeRaw,
|
|
26
|
+
rehypeStripTags,
|
|
27
|
+
rehypeDccComponents,
|
|
28
|
+
];
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type {Plugin} from 'unified';
|
|
2
|
+
import type {Element, Root} from 'hast';
|
|
3
|
+
import {visit} from 'unist-util-visit';
|
|
4
|
+
|
|
5
|
+
// Inline `$...$` or display `$$...$$` math.
|
|
6
|
+
const MATH_RE = /(\${1,2})((?:\\.|[^$])+)\1/g;
|
|
7
|
+
|
|
8
|
+
function escapeHtml(value: string): string {
|
|
9
|
+
return value
|
|
10
|
+
.replace(/&/g, '&')
|
|
11
|
+
.replace(/</g, '<')
|
|
12
|
+
.replace(/>/g, '>');
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// Rewrite `$...$` runs inside a raw-HTML string into `<dashmathjax>` tags. This
|
|
16
|
+
// runs on the raw string *before* rehype-raw decodes entities, so an escaped
|
|
17
|
+
// `$` is left alone and renders as a literal `$`.
|
|
18
|
+
function rewriteRawMath(value: string): string {
|
|
19
|
+
return value.replace(MATH_RE, (_full, delimiter, source) => {
|
|
20
|
+
const inline = delimiter.length === 1 || source.indexOf('\n') === -1;
|
|
21
|
+
return `<dashmathjax inline="${inline}">${escapeHtml(
|
|
22
|
+
source
|
|
23
|
+
)}</dashmathjax>`;
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// remark-math emits `<span class="math math-inline">` / `<div class="math
|
|
28
|
+
// math-display">`; report which (if either) an element is.
|
|
29
|
+
function mathKind(node: Element): 'inline' | 'display' | null {
|
|
30
|
+
const className = node.properties?.className;
|
|
31
|
+
if (Array.isArray(className)) {
|
|
32
|
+
if (className.includes('math-inline')) {
|
|
33
|
+
return 'inline';
|
|
34
|
+
}
|
|
35
|
+
if (className.includes('math-display')) {
|
|
36
|
+
return 'display';
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Routes both math sources into the Math component as `<dashmathjax>` elements:
|
|
44
|
+
* - Markdown `$...$` parsed by remark-math (as `.math-inline`/`.math-display`).
|
|
45
|
+
* - raw-HTML `$...$`, rewritten in place before rehype-raw runs.
|
|
46
|
+
*
|
|
47
|
+
* in markdown: Euler: $e=mc^2$
|
|
48
|
+
* transformed: Euler: <dashmathjax inline="true">e=mc^2</dashmathjax>
|
|
49
|
+
*/
|
|
50
|
+
const rehypeDashMath: Plugin<[], Root> = () => tree => {
|
|
51
|
+
visit(tree, node => {
|
|
52
|
+
if (node.type === 'raw') {
|
|
53
|
+
const raw = node as unknown as {value: string};
|
|
54
|
+
raw.value = rewriteRawMath(raw.value);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
if (node.type === 'element') {
|
|
58
|
+
const kind = mathKind(node);
|
|
59
|
+
if (kind) {
|
|
60
|
+
node.tagName = 'dashmathjax';
|
|
61
|
+
node.properties = {
|
|
62
|
+
inline: kind === 'inline' ? 'true' : 'false',
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
export default rehypeDashMath;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type {Plugin} from 'unified';
|
|
2
|
+
import type {Root} from 'hast';
|
|
3
|
+
import {visit} from 'unist-util-visit';
|
|
4
|
+
|
|
5
|
+
const DCC_ALLOWED_TAGS_LOWERCASE = ['dcclink', 'dccmarkdown'];
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Renders supported dash components according to the allowlist.
|
|
9
|
+
* Slightly obscure because HTML on its own ignores the self-closing `/>` form
|
|
10
|
+
* of custom tags, so we correct for that here:
|
|
11
|
+
*
|
|
12
|
+
* in markdown: Click <dccLink href="#" children="here" /> for info
|
|
13
|
+
* received here (wrong): Click <dccLink href="#" children="here"> for info</dccLink>
|
|
14
|
+
* corrected here: Click <dccLink href="#" children="here"></dccLink> for info
|
|
15
|
+
*/
|
|
16
|
+
const rehypeDccComponents: Plugin<[], Root> = () => tree => {
|
|
17
|
+
visit(tree, 'element', (node, index, parent) => {
|
|
18
|
+
if (!parent || typeof index !== 'number') {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const isDccTag = DCC_ALLOWED_TAGS_LOWERCASE.includes(node.tagName);
|
|
23
|
+
const hasChildrenAttribute = node.properties?.children !== undefined;
|
|
24
|
+
if (!isDccTag || !hasChildrenAttribute) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
parent.children.splice(index + 1, 0, ...node.children);
|
|
29
|
+
node.children = [];
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export default rehypeDccComponents;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type {Plugin} from 'unified';
|
|
2
|
+
import type {Root} from 'hast';
|
|
3
|
+
import {visit, SKIP} from 'unist-util-visit';
|
|
4
|
+
|
|
5
|
+
// Tags removed from raw HTML even when `dangerously_allow_html` is True.
|
|
6
|
+
// New additions here may require a major version bump
|
|
7
|
+
const STRIPPED_TAGS = ['script', 'style'];
|
|
8
|
+
|
|
9
|
+
const rehypeStripTags: Plugin<[], Root> = () => tree => {
|
|
10
|
+
visit(tree, 'element', (node, index, parent) => {
|
|
11
|
+
if (
|
|
12
|
+
STRIPPED_TAGS.includes(node.tagName) &&
|
|
13
|
+
parent &&
|
|
14
|
+
typeof index === 'number'
|
|
15
|
+
) {
|
|
16
|
+
parent.children.splice(index, 1);
|
|
17
|
+
return [SKIP, index];
|
|
18
|
+
}
|
|
19
|
+
return undefined;
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export default rehypeStripTags;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type {ReactNode} from 'react';
|
|
2
|
+
import type {Content} from 'hast';
|
|
3
|
+
|
|
4
|
+
// Concatenate the text content of hast nodes, descending into element children.
|
|
5
|
+
export function collectText(nodes: Content[] | undefined): string {
|
|
6
|
+
if (!nodes) {
|
|
7
|
+
return '';
|
|
8
|
+
}
|
|
9
|
+
return nodes
|
|
10
|
+
.map(node => {
|
|
11
|
+
if (node.type === 'text') {
|
|
12
|
+
return node.value;
|
|
13
|
+
}
|
|
14
|
+
if (node.type === 'element') {
|
|
15
|
+
return collectText(node.children);
|
|
16
|
+
}
|
|
17
|
+
return '';
|
|
18
|
+
})
|
|
19
|
+
.join('');
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function reactNodeToText(node: ReactNode): string {
|
|
23
|
+
if (node === null || node === undefined || typeof node === 'boolean') {
|
|
24
|
+
return '';
|
|
25
|
+
}
|
|
26
|
+
if (typeof node === 'string' || typeof node === 'number') {
|
|
27
|
+
return String(node);
|
|
28
|
+
}
|
|
29
|
+
if (Array.isArray(node)) {
|
|
30
|
+
return node.map(reactNodeToText).join('');
|
|
31
|
+
}
|
|
32
|
+
const element = node as {props?: {children?: ReactNode}};
|
|
33
|
+
return element.props ? reactNodeToText(element.props.children) : '';
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function dedentText(text: string): string {
|
|
37
|
+
const lines = text.split(/\r\n|\r|\n/);
|
|
38
|
+
let commonPrefix: string | null = null;
|
|
39
|
+
for (const line of lines) {
|
|
40
|
+
const preMatch = line && line.match(/^\s*(?=\S)/);
|
|
41
|
+
if (preMatch) {
|
|
42
|
+
const prefix = preMatch[0];
|
|
43
|
+
if (commonPrefix !== null) {
|
|
44
|
+
for (let i = 0; i < commonPrefix.length; i++) {
|
|
45
|
+
// Like Python's textwrap.dedent, we'll remove both space
|
|
46
|
+
// and tab characters, but only if they match
|
|
47
|
+
if (prefix[i] !== commonPrefix[i]) {
|
|
48
|
+
commonPrefix = commonPrefix.substr(0, i);
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
} else {
|
|
53
|
+
commonPrefix = prefix;
|
|
54
|
+
}
|
|
55
|
+
if (!commonPrefix) {
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
const commonLen = commonPrefix ? commonPrefix.length : 0;
|
|
61
|
+
return lines
|
|
62
|
+
.map(line => (line.match(/\S/) ? line.substr(commonLen) : ''))
|
|
63
|
+
.join('\n');
|
|
64
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dash-core-components",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.5.0",
|
|
4
4
|
"description": "Core component suite for Dash",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"build:js": "webpack --mode production",
|
|
28
28
|
"build:backends": "dash-generate-components ./src/components dash_core_components -p package-info.json && cp dash_core_components_base/** dash_core_components/ && dash-generate-components ./src/components dash_core_components -p package-info.json -k RangeSlider,Slider,Dropdown,RadioItems,Checklist,DatePickerSingle,DatePickerRange,Input,Link --r-prefix 'dcc' --r-suggests 'dash,dashHtmlComponents,jsonlite,plotly' --jl-prefix 'dcc' && black dash_core_components",
|
|
29
29
|
"build": "run-s prepublishOnly build:js build:backends",
|
|
30
|
-
"postbuild": "es-check
|
|
30
|
+
"postbuild": "es-check es2018 dash_core_components/*.js",
|
|
31
31
|
"build:watch": "watch 'npm run build' src",
|
|
32
32
|
"format": "run-s private::format.*",
|
|
33
33
|
"lint": "run-s private::lint.*"
|
|
@@ -41,10 +41,10 @@
|
|
|
41
41
|
"@fortawesome/free-solid-svg-icons": "^5.15.4",
|
|
42
42
|
"@fortawesome/react-fontawesome": "^0.1.17",
|
|
43
43
|
"@radix-ui/react-icons": "^1.3.2",
|
|
44
|
-
"@radix-ui/react-popover": "^1.1.
|
|
45
|
-
"@radix-ui/react-select": "^2.
|
|
46
|
-
"@radix-ui/react-slider": "^1.
|
|
47
|
-
"@radix-ui/react-tooltip": "^1.2.
|
|
44
|
+
"@radix-ui/react-popover": "^1.1.20",
|
|
45
|
+
"@radix-ui/react-select": "^2.3.4",
|
|
46
|
+
"@radix-ui/react-slider": "^1.4.4",
|
|
47
|
+
"@radix-ui/react-tooltip": "^1.2.13",
|
|
48
48
|
"base64-js": "^1.5.1",
|
|
49
49
|
"d3-format": "^1.4.5",
|
|
50
50
|
"date-fns": "^4.1.0",
|
|
@@ -61,10 +61,13 @@
|
|
|
61
61
|
"react-dropzone": "^4.1.2",
|
|
62
62
|
"react-fast-compare": "^3.2.2",
|
|
63
63
|
"react-input-autosize": "^3.0.0",
|
|
64
|
-
"react-markdown": "^
|
|
64
|
+
"react-markdown": "^8.0.7",
|
|
65
65
|
"react-window": "^1.8.11",
|
|
66
|
-
"
|
|
67
|
-
"
|
|
66
|
+
"rehype-raw": "^6.1.1",
|
|
67
|
+
"remark-math": "^5.1.1",
|
|
68
|
+
"remark-gfm": "^3.0.1",
|
|
69
|
+
"uniqid": "^5.4.0",
|
|
70
|
+
"unist-util-visit": "^4.1.2"
|
|
68
71
|
},
|
|
69
72
|
"devDependencies": {
|
|
70
73
|
"@babel/cli": "^7.28.6",
|
|
@@ -81,6 +84,7 @@
|
|
|
81
84
|
"@testing-library/react": "^16.3.2",
|
|
82
85
|
"@types/d3-format": "^3.0.4",
|
|
83
86
|
"@types/fast-isnumeric": "^1.1.2",
|
|
87
|
+
"@types/hast": "^2.3.10",
|
|
84
88
|
"@types/jest": "^29.5.14",
|
|
85
89
|
"@types/js-search": "^1.4.4",
|
|
86
90
|
"@types/ramda": "^0.31.0",
|
|
@@ -106,7 +110,6 @@
|
|
|
106
110
|
"prettier": "^2.8.8",
|
|
107
111
|
"react": "^18",
|
|
108
112
|
"react-dom": "^18",
|
|
109
|
-
"react-jsx-parser": "2.4.1",
|
|
110
113
|
"rimraf": "^6.1.3",
|
|
111
114
|
"style-loader": "^3.3.3",
|
|
112
115
|
"styled-jsx": "^5.1.7",
|
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
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
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.default = void 0;
|
|
8
|
-
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
9
|
-
var _react = _interopRequireWildcard(require("react"));
|
|
10
|
-
var _ramda = require("ramda");
|
|
11
|
-
var _excluded = ["refresh"];
|
|
12
|
-
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); }
|
|
13
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
14
|
-
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; }
|
|
15
|
-
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; }
|
|
16
|
-
/*
|
|
17
|
-
* event polyfill for IE
|
|
18
|
-
* https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent/CustomEvent
|
|
19
|
-
*/
|
|
20
|
-
function CustomEvent(event, params) {
|
|
21
|
-
// eslint-disable-next-line no-param-reassign
|
|
22
|
-
params = params || {
|
|
23
|
-
bubbles: false,
|
|
24
|
-
cancelable: false,
|
|
25
|
-
// eslint-disable-next-line no-undefined
|
|
26
|
-
detail: undefined
|
|
27
|
-
};
|
|
28
|
-
var evt = document.createEvent('CustomEvent');
|
|
29
|
-
evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail);
|
|
30
|
-
return evt;
|
|
31
|
-
}
|
|
32
|
-
CustomEvent.prototype = window.Event.prototype;
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Link allows you to create a clickable link within a multi-page app.
|
|
36
|
-
*
|
|
37
|
-
* For links with destinations outside the current app, `html.A` is a better
|
|
38
|
-
* component to use.
|
|
39
|
-
*/
|
|
40
|
-
var Link = function Link(_ref) {
|
|
41
|
-
var _ref$refresh = _ref.refresh,
|
|
42
|
-
refresh = _ref$refresh === void 0 ? false : _ref$refresh,
|
|
43
|
-
props = _objectWithoutProperties(_ref, _excluded);
|
|
44
|
-
var className = props.className,
|
|
45
|
-
style = props.style,
|
|
46
|
-
id = props.id,
|
|
47
|
-
href = props.href,
|
|
48
|
-
children = props.children,
|
|
49
|
-
title = props.title,
|
|
50
|
-
target = props.target,
|
|
51
|
-
setProps = props.setProps;
|
|
52
|
-
var cleanUrl = window.dash_clientside.clean_url;
|
|
53
|
-
var sanitizedUrl = (0, _react.useMemo)(function () {
|
|
54
|
-
return href ? cleanUrl(href) : undefined;
|
|
55
|
-
}, [href]);
|
|
56
|
-
var ctx = window.dash_component_api.useDashContext();
|
|
57
|
-
var loading = ctx.useLoading();
|
|
58
|
-
var updateLocation = function updateLocation(e) {
|
|
59
|
-
var hasModifiers = e.metaKey || e.shiftKey || e.altKey || e.ctrlKey;
|
|
60
|
-
if (hasModifiers) {
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
if (target !== '_self' && !(0, _ramda.isNil)(target)) {
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
// prevent anchor from updating location
|
|
67
|
-
e.preventDefault();
|
|
68
|
-
if (refresh) {
|
|
69
|
-
window.location = sanitizedUrl;
|
|
70
|
-
} else {
|
|
71
|
-
window.history.pushState({}, '', sanitizedUrl);
|
|
72
|
-
window.dispatchEvent(new CustomEvent('_dashprivate_pushstate'));
|
|
73
|
-
}
|
|
74
|
-
// scroll back to top
|
|
75
|
-
window.scrollTo(0, 0);
|
|
76
|
-
};
|
|
77
|
-
(0, _react.useEffect)(function () {
|
|
78
|
-
if (sanitizedUrl && sanitizedUrl !== href) {
|
|
79
|
-
setProps({
|
|
80
|
-
_dash_error: new Error("Dangerous link detected:: ".concat(href))
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
}, [href, sanitizedUrl]);
|
|
84
|
-
return /*#__PURE__*/_react.default.createElement("a", {
|
|
85
|
-
"data-dash-is-loading": loading || undefined,
|
|
86
|
-
id: id,
|
|
87
|
-
className: className,
|
|
88
|
-
style: style,
|
|
89
|
-
href: sanitizedUrl,
|
|
90
|
-
onClick: updateLocation,
|
|
91
|
-
title: title,
|
|
92
|
-
target: target
|
|
93
|
-
}, (0, _ramda.isNil)(children) ? sanitizedUrl : children);
|
|
94
|
-
};
|
|
95
|
-
Link.propTypes = {
|
|
96
|
-
/**
|
|
97
|
-
* The children of this component
|
|
98
|
-
*/
|
|
99
|
-
children: _propTypes.default.node,
|
|
100
|
-
/**
|
|
101
|
-
* The URL of a linked resource.
|
|
102
|
-
*/
|
|
103
|
-
href: _propTypes.default.string.isRequired,
|
|
104
|
-
/**
|
|
105
|
-
* Specifies where to open the link reference.
|
|
106
|
-
*/
|
|
107
|
-
target: _propTypes.default.string,
|
|
108
|
-
/**
|
|
109
|
-
* Controls whether or not the page will refresh when the link is clicked
|
|
110
|
-
*/
|
|
111
|
-
refresh: _propTypes.default.bool,
|
|
112
|
-
/**
|
|
113
|
-
* Adds the title attribute to your link, which can contain supplementary
|
|
114
|
-
* information.
|
|
115
|
-
*/
|
|
116
|
-
title: _propTypes.default.string,
|
|
117
|
-
/**
|
|
118
|
-
* Often used with CSS to style elements with common properties.
|
|
119
|
-
*/
|
|
120
|
-
className: _propTypes.default.string,
|
|
121
|
-
/**
|
|
122
|
-
* Defines CSS styles which will override styles previously set.
|
|
123
|
-
*/
|
|
124
|
-
style: _propTypes.default.object,
|
|
125
|
-
/**
|
|
126
|
-
* The ID of this component, used to identify dash components
|
|
127
|
-
* in callbacks. The ID needs to be unique across all of the
|
|
128
|
-
* components in an app.
|
|
129
|
-
*/
|
|
130
|
-
id: _propTypes.default.string,
|
|
131
|
-
/**
|
|
132
|
-
* Object that holds the loading state object coming from dash-renderer
|
|
133
|
-
*/
|
|
134
|
-
loading_state: _propTypes.default.shape({
|
|
135
|
-
/**
|
|
136
|
-
* Determines if the component is loading or not
|
|
137
|
-
*/
|
|
138
|
-
is_loading: _propTypes.default.bool,
|
|
139
|
-
/**
|
|
140
|
-
* Holds which property is loading
|
|
141
|
-
*/
|
|
142
|
-
prop_name: _propTypes.default.string,
|
|
143
|
-
/**
|
|
144
|
-
* Holds the name of the component that is loading
|
|
145
|
-
*/
|
|
146
|
-
component_name: _propTypes.default.string
|
|
147
|
-
}),
|
|
148
|
-
setProps: _propTypes.default.func
|
|
149
|
-
};
|
|
150
|
-
var _default = exports.default = Link;
|