@readme/markdown 6.75.0-beta.3 → 6.75.0-beta.31

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 (52) hide show
  1. package/components/Callout/index.tsx +27 -0
  2. package/components/Code/index.tsx +73 -0
  3. package/components/CodeTabs/{index.jsx → index.tsx} +8 -19
  4. package/components/GlossaryItem/index.tsx +31 -0
  5. package/components/HTMLBlock/index.tsx +36 -0
  6. package/components/Image/index.tsx +96 -0
  7. package/components/Table/index.tsx +19 -0
  8. package/components/TableOfContents/index.jsx +4 -4
  9. package/dist/components/Callout/index.d.ts +9 -0
  10. package/dist/components/Code/index.d.ts +10 -0
  11. package/dist/components/CodeTabs/index.d.ts +3 -0
  12. package/dist/components/GlossaryItem/index.d.ts +9 -0
  13. package/dist/components/HTMLBlock/index.d.ts +7 -0
  14. package/dist/components/Image/index.d.ts +14 -0
  15. package/dist/components/Table/index.d.ts +6 -0
  16. package/dist/components/index.d.ts +12 -0
  17. package/dist/contexts/GlossaryTerms.d.ts +15 -0
  18. package/dist/enums.d.ts +7 -0
  19. package/dist/errors/mdx-syntax-error.d.ts +5 -0
  20. package/dist/example/App.d.ts +3 -0
  21. package/dist/example/Doc.d.ts +3 -0
  22. package/dist/example/Form.d.ts +3 -0
  23. package/dist/example/Header.d.ts +3 -0
  24. package/dist/example/RenderError.d.ts +23 -0
  25. package/dist/example/Root.d.ts +3 -0
  26. package/dist/example/docs.d.ts +2 -0
  27. package/dist/example/index.d.ts +1 -0
  28. package/dist/index.d.ts +26 -0
  29. package/dist/lib/owlmoji.d.ts +4 -0
  30. package/dist/main.js +81787 -2
  31. package/dist/main.node.js +83665 -2
  32. package/dist/processor/compile/code-tabs.d.ts +3 -0
  33. package/dist/processor/compile/gemoji.d.ts +3 -0
  34. package/dist/processor/compile/html-block.d.ts +3 -0
  35. package/dist/processor/compile/image.d.ts +3 -0
  36. package/dist/processor/compile/index.d.ts +2 -0
  37. package/dist/processor/compile/table.d.ts +0 -0
  38. package/dist/processor/transform/callouts.d.ts +2 -0
  39. package/dist/processor/transform/code-tabs.d.ts +2 -0
  40. package/dist/processor/transform/gemoji+.d.ts +3 -0
  41. package/dist/processor/transform/index.d.ts +2 -0
  42. package/package.json +39 -22
  43. package/components/Callout/index.jsx +0 -42
  44. package/components/Code/index.jsx +0 -101
  45. package/components/GlossaryItem/index.jsx +0 -44
  46. package/components/HTMLBlock/index.jsx +0 -69
  47. package/components/Image/index.jsx +0 -111
  48. package/components/Table/index.jsx +0 -19
  49. package/dist/main.css +0 -399
  50. package/dist/main.js.LICENSE.txt +0 -17
  51. package/dist/main.node.js.LICENSE.txt +0 -50
  52. /package/components/{index.js → index.ts} +0 -0
@@ -0,0 +1,27 @@
1
+ import * as React from 'react';
2
+
3
+ interface Props extends React.PropsWithChildren<React.HTMLAttributes<HTMLQuoteElement>> {
4
+ attributes: {};
5
+ icon: string;
6
+ theme: string;
7
+ heading?: React.ReactElement;
8
+ }
9
+
10
+ const Callout = (props: Props) => {
11
+ const { attributes, children, theme, icon, heading } = props;
12
+
13
+ return (
14
+ // @ts-ignore
15
+ <blockquote {...attributes} className={`callout callout_${theme}`} theme={icon}>
16
+ {heading && (
17
+ <h3 className={`callout-heading${heading ? '' : ' empty'}`}>
18
+ <span className="callout-icon">{icon}</span>
19
+ {heading}
20
+ </h3>
21
+ )}
22
+ {children}
23
+ </blockquote>
24
+ );
25
+ };
26
+
27
+ export default Callout;
@@ -0,0 +1,73 @@
1
+ import copy from 'copy-to-clipboard';
2
+ import React, { createRef } from 'react';
3
+
4
+ // Only load CodeMirror in the browser, for SSR
5
+ // apps. Necessary because of people like this:
6
+ // https://github.com/codemirror/CodeMirror/issues/3701#issuecomment-164904534
7
+ let syntaxHighlighter;
8
+ let canonicalLanguage = _ => '';
9
+ if (typeof window !== 'undefined') {
10
+ // eslint-disable-next-line global-require
11
+ syntaxHighlighter = require('@readme/syntax-highlighter').default;
12
+ // eslint-disable-next-line global-require
13
+ ({ canonical: canonicalLanguage } = require('@readme/syntax-highlighter'));
14
+ }
15
+
16
+ function CopyCode({ codeRef, rootClass = 'rdmd-code-copy', className = '' }) {
17
+ const copyClass = `${rootClass}_copied`;
18
+ const button = createRef<HTMLButtonElement>();
19
+
20
+ const copier = () => {
21
+ const code = codeRef.current.textContent;
22
+
23
+ if (copy(code)) {
24
+ const el = button.current;
25
+ el.classList.add(copyClass);
26
+
27
+ setTimeout(() => el.classList.remove(copyClass), 1500);
28
+ }
29
+ };
30
+
31
+ return <button ref={button} aria-label="Copy Code" className={`${rootClass} ${className}`} onClick={copier} />;
32
+ }
33
+
34
+ interface Props extends Omit<HTMLElement, 'lang'> {
35
+ copyButtons?: boolean;
36
+ lang?: string;
37
+ meta?: string;
38
+ theme?: string;
39
+ value?: string;
40
+ }
41
+
42
+ const Code = (props: Props) => {
43
+ const { children, copyButtons, lang, theme, value } = props;
44
+
45
+ const language = canonicalLanguage(lang);
46
+
47
+ const codeRef = createRef<HTMLElement>();
48
+
49
+ const codeOpts = {
50
+ inline: !lang,
51
+ tokenizeVariables: true,
52
+ dark: theme === 'dark',
53
+ };
54
+
55
+ const code = value ?? children?.[0] ?? children ?? '';
56
+ const highlightedCode = syntaxHighlighter && code ? syntaxHighlighter(code, language, codeOpts) : code;
57
+
58
+ return (
59
+ <>
60
+ {copyButtons && <CopyCode className="fa" codeRef={codeRef} />}
61
+ <code
62
+ ref={codeRef}
63
+ className={['rdmd-code', `lang-${language}`, `theme-${theme}`].join(' ')}
64
+ data-lang={language}
65
+ suppressHydrationWarning={true}
66
+ >
67
+ {highlightedCode}
68
+ </code>
69
+ </>
70
+ );
71
+ };
72
+
73
+ export default Code;
@@ -1,14 +1,13 @@
1
- const { uppercase } = require('@readme/syntax-highlighter');
2
- const PropTypes = require('prop-types');
3
- const React = require('react');
1
+ import { uppercase } from '@readme/syntax-highlighter';
2
+ import React from 'react';
4
3
 
5
4
  const CodeTabs = props => {
6
5
  const { children, theme } = props;
7
6
 
8
- function handleClick({ target }, index) {
7
+ function handleClick({ target }, index: number) {
9
8
  const $wrap = target.parentElement.parentElement;
10
9
  const $open = [].slice.call($wrap.querySelectorAll('.CodeTabs_active'));
11
- $open.forEach(el => el.classList.remove('CodeTabs_active'));
10
+ $open.forEach((el: Element) => el.classList.remove('CodeTabs_active'));
12
11
  $wrap.classList.remove('CodeTabs_initial');
13
12
 
14
13
  const codeblocks = $wrap.querySelectorAll('pre');
@@ -20,8 +19,9 @@ const CodeTabs = props => {
20
19
  return (
21
20
  <div className={`CodeTabs CodeTabs_initial theme-${theme}`}>
22
21
  <div className="CodeTabs-toolbar">
23
- {children.map(({ props: pre }, i) => {
24
- const { meta, lang } = pre.children[0].props;
22
+ {(Array.isArray(children) ? children : [children]).map((pre, i) => {
23
+ const { meta, lang } = pre.props.children.props;
24
+
25
25
  /* istanbul ignore next */
26
26
  return (
27
27
  <button key={i} onClick={e => handleClick(e, i)} type="button">
@@ -35,15 +35,4 @@ const CodeTabs = props => {
35
35
  );
36
36
  };
37
37
 
38
- CodeTabs.propTypes = {
39
- children: PropTypes.arrayOf(PropTypes.any).isRequired,
40
- theme: PropTypes.string,
41
- };
42
-
43
- function CreateCodeTabs({ theme }) {
44
- // eslint-disable-next-line react/display-name
45
- return props => <CodeTabs {...props} theme={theme} />;
46
- }
47
-
48
- module.exports = CreateCodeTabs;
49
- module.exports.CodeTabs = CodeTabs;
38
+ export default CodeTabs;
@@ -0,0 +1,31 @@
1
+ import React, { useContext } from 'react';
2
+ import Tooltip from '@tippyjs/react';
3
+ import GlossaryContext from '../../contexts/GlossaryTerms';
4
+ import type { GlossaryItem, GlossaryTerm } from '../../contexts/GlossaryTerms';
5
+
6
+ const GlossaryItem = ({ term, terms }: { term: string; terms: GlossaryTerm[] }) => {
7
+ const foundTerm = terms.find(i => term.toLowerCase() === i.term.toLowerCase());
8
+
9
+ if (!foundTerm) return <span>{term}</span>;
10
+
11
+ return (
12
+ <Tooltip
13
+ content={
14
+ <div className="GlossaryItem-tooltip-content">
15
+ <strong className="GlossaryItem-term">{foundTerm.term}</strong> - {foundTerm.definition}
16
+ </div>
17
+ }
18
+ offset={[-5, 5]}
19
+ placement="bottom-start"
20
+ >
21
+ <span className="GlossaryItem-trigger">{term}</span>
22
+ </Tooltip>
23
+ );
24
+ };
25
+
26
+ const GlossaryItemWithContext = props => {
27
+ const terms = useContext(GlossaryContext);
28
+ return terms ? <GlossaryItem {...props} terms={terms} /> : null;
29
+ };
30
+
31
+ export { GlossaryItem, GlossaryItemWithContext as default, GlossaryContext };
@@ -0,0 +1,36 @@
1
+ import React, { useEffect } from 'react';
2
+ import { renderToStaticMarkup } from 'react-dom/server';
3
+
4
+ const MATCH_SCRIPT_TAGS = /<script\b[^>]*>([\s\S]*?)<\/script *>\n?/gim;
5
+
6
+ const extractScripts = (html: string = ''): [string, () => void] => {
7
+ const scripts: string[] = [];
8
+ let match: RegExpExecArray | null;
9
+ while ((match = MATCH_SCRIPT_TAGS.exec(html)) !== null) {
10
+ scripts.push(match[1]);
11
+ }
12
+ const cleaned = html.replace(MATCH_SCRIPT_TAGS, '');
13
+ return [cleaned, () => scripts.map(js => window.eval(js))];
14
+ };
15
+
16
+ const HTMLBlock = ({ children = '', runScripts = false, safeMode = false }) => {
17
+ let html = children;
18
+ if (typeof html !== 'string') html = renderToStaticMarkup(html);
19
+ const [cleanedHtml, exec] = extractScripts(html);
20
+
21
+ useEffect(() => {
22
+ if (typeof window !== 'undefined' && typeof runScripts === 'boolean' && runScripts) exec();
23
+ }, [runScripts, exec]);
24
+
25
+ if (safeMode) {
26
+ return (
27
+ <pre className="html-unsafe">
28
+ <code>{html}</code>
29
+ </pre>
30
+ );
31
+ }
32
+
33
+ return <div className="rdmd-html" dangerouslySetInnerHTML={{ __html: cleanedHtml }} />;
34
+ };
35
+
36
+ export default HTMLBlock;
@@ -0,0 +1,96 @@
1
+ import * as React from 'react';
2
+
3
+ const Image = ({
4
+ align = '',
5
+ alt = '',
6
+ border = false,
7
+ caption,
8
+ className = '',
9
+ height = 'auto',
10
+ src = '',
11
+ title = '',
12
+ width = 'auto',
13
+ lazy = false,
14
+ }) => {
15
+ const [lightbox, setLightbox] = React.useState(false);
16
+
17
+ if (className === 'emoji') {
18
+ return <img src={src} width={width} height={height} title={title} alt={alt} loading={lazy ? 'lazy' : 'eager'} />;
19
+ }
20
+
21
+ const handleKeyDown = ({ key, metaKey: cmd }: React.KeyboardEvent<HTMLImageElement>) => {
22
+ const cmdKey = cmd ? 'cmd+' : '';
23
+ key = `${cmdKey}${key.toLowerCase()}`;
24
+
25
+ switch (key) {
26
+ case 'cmd+.':
27
+ case 'escape':
28
+ // CLOSE
29
+ setLightbox(false);
30
+ break;
31
+ case ' ':
32
+ case 'enter':
33
+ // OPEN
34
+ if (!lightbox) setLightbox(true);
35
+ default:
36
+ }
37
+ };
38
+
39
+ const toggle = () => {
40
+ if (className === 'emoji') return;
41
+ setLightbox(!lightbox);
42
+ };
43
+
44
+ if (caption) {
45
+ return (
46
+ <figure>
47
+ <span
48
+ aria-label={alt}
49
+ className={`img lightbox ${lightbox ? 'open' : 'closed'}`}
50
+ onClick={toggle}
51
+ onKeyDown={handleKeyDown}
52
+ role={'button'}
53
+ tabIndex={0}
54
+ >
55
+ <span className="lightbox-inner">
56
+ <img
57
+ src={src}
58
+ width={width}
59
+ height={height}
60
+ title={title}
61
+ className={`img img-align-center ${border ? 'border' : ''}`}
62
+ alt={alt}
63
+ loading={lazy ? 'lazy' : 'eager'}
64
+ />
65
+ </span>
66
+ </span>
67
+ <figcaption>{caption}</figcaption>
68
+ </figure>
69
+ );
70
+ }
71
+
72
+ return (
73
+ <span
74
+ aria-label={alt}
75
+ className={`img lightbox ${lightbox ? 'open' : 'closed'}`}
76
+ onClick={toggle}
77
+ onKeyDown={handleKeyDown}
78
+ role={'button'}
79
+ tabIndex={0}
80
+ >
81
+ <span className="lightbox-inner">
82
+ <img
83
+ src={src}
84
+ width={width}
85
+ height={height}
86
+ title={title}
87
+ className={`img img-align-${align} ${border ? 'border' : ''}`}
88
+ alt={alt}
89
+ loading={lazy ? 'lazy' : 'eager'}
90
+ />
91
+ </span>
92
+ </span>
93
+ );
94
+ };
95
+
96
+ export default Image;
@@ -0,0 +1,19 @@
1
+ import React from 'react';
2
+
3
+ interface Props extends JSX.IntrinsicAttributes {
4
+ children: [React.ReactElement<HTMLTableCaptionElement | HTMLTableSectionElement | HTMLTableRowElement>];
5
+ }
6
+
7
+ const Table = (props: Props) => {
8
+ const { children } = props;
9
+
10
+ return (
11
+ <div className="rdmd-table">
12
+ <div className="rdmd-table-inner">
13
+ <table>{children}</table>
14
+ </div>
15
+ </div>
16
+ );
17
+ };
18
+
19
+ export default Table;
@@ -1,5 +1,5 @@
1
- const PropTypes = require('prop-types');
2
- const React = require('react');
1
+ import { element } from 'prop-types';
2
+ import React from 'react';
3
3
 
4
4
  function TableOfContents({ children }) {
5
5
  return (
@@ -19,7 +19,7 @@ function TableOfContents({ children }) {
19
19
  }
20
20
 
21
21
  TableOfContents.propTypes = {
22
- children: PropTypes.element,
22
+ children: element,
23
23
  };
24
24
 
25
- module.exports = TableOfContents;
25
+ export default TableOfContents;
@@ -0,0 +1,9 @@
1
+ import * as React from 'react';
2
+ interface Props extends React.PropsWithChildren<React.HTMLAttributes<HTMLQuoteElement>> {
3
+ attributes: {};
4
+ icon: string;
5
+ theme: string;
6
+ heading?: React.ReactElement;
7
+ }
8
+ declare const Callout: (props: Props) => React.JSX.Element;
9
+ export default Callout;
@@ -0,0 +1,10 @@
1
+ import React from 'react';
2
+ interface Props extends Omit<HTMLElement, 'lang'> {
3
+ copyButtons?: boolean;
4
+ lang?: string;
5
+ meta?: string;
6
+ theme?: string;
7
+ value?: string;
8
+ }
9
+ declare const Code: (props: Props) => React.JSX.Element;
10
+ export default Code;
@@ -0,0 +1,3 @@
1
+ import React from 'react';
2
+ declare const CodeTabs: (props: any) => React.JSX.Element;
3
+ export default CodeTabs;
@@ -0,0 +1,9 @@
1
+ import React from 'react';
2
+ import GlossaryContext from '../../contexts/GlossaryTerms';
3
+ import type { GlossaryItem, GlossaryTerm } from '../../contexts/GlossaryTerms';
4
+ declare const GlossaryItem: ({ term, terms }: {
5
+ term: string;
6
+ terms: GlossaryTerm[];
7
+ }) => React.JSX.Element;
8
+ declare const GlossaryItemWithContext: (props: any) => React.JSX.Element;
9
+ export { GlossaryItem, GlossaryItemWithContext as default, GlossaryContext };
@@ -0,0 +1,7 @@
1
+ import React from 'react';
2
+ declare const HTMLBlock: ({ children, runScripts, safeMode }: {
3
+ children?: string;
4
+ runScripts?: boolean;
5
+ safeMode?: boolean;
6
+ }) => React.JSX.Element;
7
+ export default HTMLBlock;
@@ -0,0 +1,14 @@
1
+ import * as React from 'react';
2
+ declare const Image: ({ align, alt, border, caption, className, height, src, title, width, lazy, }: {
3
+ align?: string;
4
+ alt?: string;
5
+ border?: boolean;
6
+ caption: any;
7
+ className?: string;
8
+ height?: string;
9
+ src?: string;
10
+ title?: string;
11
+ width?: string;
12
+ lazy?: boolean;
13
+ }) => React.JSX.Element;
14
+ export default Image;
@@ -0,0 +1,6 @@
1
+ import React from 'react';
2
+ interface Props extends JSX.IntrinsicAttributes {
3
+ children: [React.ReactElement<HTMLTableCaptionElement | HTMLTableSectionElement | HTMLTableRowElement>];
4
+ }
5
+ declare const Table: (props: Props) => React.JSX.Element;
6
+ export default Table;
@@ -0,0 +1,12 @@
1
+ export { default as Anchor } from './Anchor';
2
+ export { default as Callout } from './Callout';
3
+ export { default as Code } from './Code';
4
+ export { default as CodeTabs } from './CodeTabs';
5
+ export { default as Embed } from './Embed';
6
+ export { default as GlossaryItem } from './GlossaryItem';
7
+ export { default as HTMLBlock } from './HTMLBlock';
8
+ export { default as Heading } from './Heading';
9
+ export { default as Image } from './Image';
10
+ export { default as Style } from './Style';
11
+ export { default as Table } from './Table';
12
+ export { default as TableOfContents } from './TableOfContents';
@@ -0,0 +1,15 @@
1
+ import { ReactNode } from "react";
2
+ export type GlossaryTerm = {
3
+ term: string;
4
+ definition: string;
5
+ _id?: string;
6
+ };
7
+ export type GlossaryItem = {
8
+ term?: string;
9
+ terms: GlossaryTerm[];
10
+ };
11
+ declare const GlossaryContext: import("react").Context<GlossaryTerm[]>;
12
+ export default GlossaryContext;
13
+ export declare function Provider(Provider: any, arg1: {
14
+ value: GlossaryTerm[];
15
+ }): ReactNode;
@@ -0,0 +1,7 @@
1
+ export declare enum NodeTypes {
2
+ codeTabs = "code-tabs",
3
+ emoji = "emoji",
4
+ i = "i",
5
+ image = "image",
6
+ htmlBlock = "html-block"
7
+ }
@@ -0,0 +1,5 @@
1
+ import { VFileMessage } from 'vfile-message';
2
+ export default class MdxSyntaxError extends SyntaxError {
3
+ original: VFileMessage;
4
+ constructor(error: VFileMessage, doc: string);
5
+ }
@@ -0,0 +1,3 @@
1
+ import React from 'react';
2
+ declare const App: () => React.JSX.Element;
3
+ export default App;
@@ -0,0 +1,3 @@
1
+ import React from 'react';
2
+ declare const Doc: () => React.JSX.Element;
3
+ export default Doc;
@@ -0,0 +1,3 @@
1
+ import React from 'react';
2
+ declare const Form: () => React.JSX.Element;
3
+ export default Form;
@@ -0,0 +1,3 @@
1
+ import React from 'react';
2
+ declare function Header(): React.JSX.Element;
3
+ export default Header;
@@ -0,0 +1,23 @@
1
+ import React, { PropsWithChildren } from 'react';
2
+ interface Props {
3
+ error?: string;
4
+ }
5
+ interface State {
6
+ hasError: boolean;
7
+ message?: string;
8
+ }
9
+ declare class RenderError extends React.Component<PropsWithChildren<Props>, State> {
10
+ state: {
11
+ hasError: boolean;
12
+ message: any;
13
+ };
14
+ static getDerivedStateFromError(error: Error): {
15
+ hasError: boolean;
16
+ message: string;
17
+ };
18
+ componentDidCatch(error: any, info: {
19
+ componentStack: any;
20
+ }): void;
21
+ render(): string | number | boolean | Iterable<React.ReactNode> | React.JSX.Element;
22
+ }
23
+ export default RenderError;
@@ -0,0 +1,3 @@
1
+ import React from 'react';
2
+ declare const Root: () => React.JSX.Element;
3
+ export default Root;
@@ -0,0 +1,2 @@
1
+ declare const fixtures: {};
2
+ export default fixtures;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,26 @@
1
+ import React from 'react';
2
+ import { RunOptions } from '@mdx-js/mdx';
3
+ import * as Components from './components';
4
+ type RunOpts = Omit<RunOptions, 'Fragment'> & {
5
+ components?: Record<string, () => React.ReactNode>;
6
+ imports?: Record<string, unknown>;
7
+ };
8
+ export { Components };
9
+ export declare const utils: {
10
+ readonly options: any;
11
+ BaseUrlContext: any;
12
+ getHref: any;
13
+ GlossaryContext: React.Context<import("./contexts/GlossaryTerms").GlossaryTerm[]>;
14
+ VariablesContext: any;
15
+ calloutIcons: {};
16
+ };
17
+ export declare const reactProcessor: (opts?: {}) => import("unified").Processor<import("mdast").Root, import("estree").Program, import("estree").Program, import("estree").Program, string>;
18
+ export declare const compile: (text: string, opts?: {}) => string;
19
+ export declare const run: (code: string, _opts?: RunOpts) => Promise<import("mdx/types").MDXContent | (() => any)>;
20
+ export declare const reactTOC: (text: string, opts?: {}) => void;
21
+ export declare const mdx: (tree: any, opts?: {}) => string;
22
+ export declare const html: (text: string, opts?: {}) => void;
23
+ export declare const mdast: any;
24
+ export declare const hast: (text: string, opts?: {}) => import("hast").Root;
25
+ export declare const esast: (text: string, opts?: {}) => void;
26
+ export declare const plain: (text: string, opts?: {}) => void;
@@ -0,0 +1,4 @@
1
+ export default class Owlmoji {
2
+ static kind: (name: string) => "gemoji" | "fontawesome" | "owlmoji";
3
+ static nameToEmoji: Record<string, string>;
4
+ }