-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
types: add typescript typings for @mdx-js/mdx, @mdx-js/react, @mdx-js…
…/runtime, and @mdx-js/vue (#1079)
- Loading branch information
1 parent
08c809a
commit 4bf052c
Showing
30 changed files
with
804 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,11 +15,14 @@ | |
"Tim Neutkens <[email protected]>", | ||
"Matija Marohnić <[email protected]>", | ||
"Titus Wormer <[email protected]> (https://wooorm.com)", | ||
"JounQin <[email protected]> (https://www.1stg.me)" | ||
"JounQin <[email protected]> (https://www.1stg.me)", | ||
"Christian Murphy <[email protected]>" | ||
], | ||
"license": "MIT", | ||
"types": "types/index.d.ts", | ||
"files": [ | ||
"index.js" | ||
"index.js", | ||
"types/index.d.ts" | ||
], | ||
"keywords": [ | ||
"mdx", | ||
|
@@ -31,6 +34,9 @@ | |
"webpack", | ||
"loader" | ||
], | ||
"scripts": { | ||
"test-types": "dtslint types" | ||
}, | ||
"dependencies": { | ||
"@mdx-js/mdx": "^2.0.0-next.0", | ||
"@mdx-js/react": "^2.0.0-next.0", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// TypeScript Version: 3.4 | ||
|
||
import {ComponentType} from 'react' | ||
|
||
declare module '*.mdx' { | ||
const MDXComponent: ComponentType | ||
export default MDXComponent | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "commonjs", | ||
"lib": ["dom", "es6"], | ||
"strict": true, | ||
"skipLibCheck": true, | ||
"baseUrl": ".", | ||
"jsx": "react", | ||
"paths": { | ||
"@mdx-js/react": ["index.d.ts"] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"extends": "dtslint/dtslint.json", | ||
"rules": { | ||
"whitespace": false, | ||
"semicolon": false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,13 +15,16 @@ | |
"Tim Neutkens <[email protected]>", | ||
"Matija Marohnić <[email protected]>", | ||
"Titus Wormer <[email protected]> (https://wooorm.com)", | ||
"JounQin <[email protected]> (https://www.1stg.me)" | ||
"JounQin <[email protected]> (https://www.1stg.me)", | ||
"Christian Murphy <[email protected]>" | ||
], | ||
"license": "MIT", | ||
"types": "types/index.d.ts", | ||
"files": [ | ||
"index.js", | ||
"mdx-ast-to-mdx-hast.js", | ||
"mdx-hast-to-jsx.js", | ||
"types/index.d.ts", | ||
"util.js" | ||
], | ||
"keywords": [ | ||
|
@@ -32,6 +35,9 @@ | |
"remark", | ||
"mdxast" | ||
], | ||
"scripts": { | ||
"test-types": "dtslint types" | ||
}, | ||
"dependencies": { | ||
"@babel/core": "7.9.6", | ||
"@babel/plugin-syntax-jsx": "7.8.3", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// TypeScript Version: 3.4 | ||
|
||
import {Plugin, Compiler, Processor} from 'unified' | ||
|
||
declare namespace mdx { | ||
interface Options { | ||
/** | ||
* support footnotes | ||
* | ||
* @default true | ||
*/ | ||
footnotes?: boolean | ||
|
||
/** | ||
* remark plugins to transform markdown content | ||
* | ||
* @default [] | ||
*/ | ||
remarkPlugins?: Plugin[] | ||
|
||
/** | ||
* rehype plugins html content | ||
* | ||
* @default [] | ||
*/ | ||
rehypePlugins?: Plugin[] | ||
|
||
/** | ||
* compilers to customize output | ||
* | ||
* @default [] | ||
*/ | ||
compilers?: Compiler[] | ||
} | ||
|
||
/** | ||
* compile mdx text to jsx text asynchronously | ||
* | ||
* @param mdx content as a text | ||
* @param options transform and compiler options | ||
* @returns jsx text | ||
*/ | ||
function sync(mdx: string, options?: Options): string | ||
|
||
/** | ||
* Generated an MDX compiler | ||
* | ||
* @param options transform and compiler options | ||
* @returns Unified Processor for MDX | ||
*/ | ||
function createMdxAstCompiler(options?: Options): Processor | ||
} | ||
|
||
/** | ||
* compile mdx text to jsx text asynchronously | ||
* | ||
* @param mdx content as a text | ||
* @param options transform and compiler options | ||
* @returns jsx text | ||
*/ | ||
declare function mdx(mdx: string, options?: mdx.Options): Promise<string> | ||
|
||
export = mdx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import * as mdx from '@mdx-js/mdx' | ||
|
||
mdx('# title') // $ExpectType Promise<string> | ||
mdx('# title', {}) // $ExpectType Promise<string> | ||
mdx('# title', {footnotes: false}) // $ExpectType Promise<string> | ||
mdx('# title', {rehypePlugins: [() => () => ({type: 'test'})]}) // $ExpectType Promise<string> | ||
mdx('# title', {remarkPlugins: [() => () => ({type: 'test'})]}) // $ExpectType Promise<string> | ||
mdx('# title', {compilers: []}) // $ExpectType Promise<string> | ||
|
||
mdx.sync('# title') // $ExpectType string | ||
mdx.sync('# title', {}) // $ExpectType string | ||
mdx.sync('# title', {footnotes: false}) // $ExpectType string | ||
mdx.sync('# title', {rehypePlugins: [() => () => ({type: 'test'})]}) // $ExpectType string | ||
mdx.sync('# title', {remarkPlugins: [() => () => ({type: 'test'})]}) // $ExpectType string | ||
mdx.sync('# title', {compilers: []}) // $ExpectType string | ||
|
||
mdx.createMdxAstCompiler() // $ExpectType Processor<Settings> | ||
mdx.createMdxAstCompiler({}) // $ExpectType Processor<Settings> | ||
mdx.createMdxAstCompiler({footnotes: false}) // $ExpectType Processor<Settings> | ||
mdx.createMdxAstCompiler({rehypePlugins: [() => () => ({type: 'test'})]}) // $ExpectType Processor<Settings> | ||
mdx.createMdxAstCompiler({remarkPlugins: [() => () => ({type: 'test'})]}) // $ExpectType Processor<Settings> | ||
mdx.createMdxAstCompiler({compilers: []}) // $ExpectType Processor<Settings> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "commonjs", | ||
"lib": ["dom", "es6"], | ||
"strict": true, | ||
"skipLibCheck": true, | ||
"baseUrl": ".", | ||
"jsx": "react", | ||
"paths": { | ||
"@mdx-js/mdx": ["index.d.ts"] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"extends": "dtslint/dtslint.json", | ||
"rules": { | ||
"whitespace": false, | ||
"semicolon": false, | ||
"no-redundant-jsdoc": false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,13 +15,16 @@ | |
"Tim Neutkens <[email protected]>", | ||
"Matija Marohnić <[email protected]>", | ||
"Titus Wormer <[email protected]> (https://wooorm.com)", | ||
"JounQin <[email protected]> (https://www.1stg.me)" | ||
"JounQin <[email protected]> (https://www.1stg.me)", | ||
"Christian Murphy <[email protected]>" | ||
], | ||
"license": "MIT", | ||
"main": "dist/cjs.js", | ||
"module": "dist/esm.js", | ||
"types": "types/index.d.ts", | ||
"files": [ | ||
"dist" | ||
"dist", | ||
"types/index.d.ts" | ||
], | ||
"keywords": [ | ||
"mdx", | ||
|
@@ -31,6 +34,9 @@ | |
"remark", | ||
"mdxast" | ||
], | ||
"scripts": { | ||
"test-types": "dtslint types" | ||
}, | ||
"peerDependencies": { | ||
"react": "^16.9.0" | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// TypeScript Version: 3.4 | ||
|
||
import { | ||
Context, | ||
Consumer, | ||
ComponentType, | ||
FunctionComponent, | ||
ReactElement, | ||
createElement | ||
} from 'react' | ||
|
||
/** | ||
* Mapping of names for JSX components to React components | ||
*/ | ||
interface ComponentDictionary { | ||
[name: string]: ComponentType<any> | ||
} | ||
|
||
/** | ||
* Prop type that includes a component dictionary | ||
*/ | ||
interface ComponentsProp { | ||
/** | ||
* Mapping of names for JSX components to React components | ||
*/ | ||
components: ComponentDictionary | ||
} | ||
|
||
/** | ||
* Direct access to the MDX React Context | ||
*/ | ||
declare const MDXContext: Context<ComponentsProp> | ||
|
||
/** | ||
* Provider for MDX context | ||
*/ | ||
declare const MDXProvider: FunctionComponent<ComponentsProp> | ||
|
||
/** | ||
* Gets components from the MDX Context | ||
* | ||
* @param components additional components to include | ||
* @returns all components from context with overrides from components parameter | ||
*/ | ||
declare function useMDXComponents( | ||
components: ComponentDictionary | (() => ComponentDictionary) | ||
): ComponentDictionary | ||
|
||
/** | ||
* High order component that passes components prop to child | ||
* | ||
* @param child Component being wrapped | ||
*/ | ||
declare function withMDXComponents( | ||
child: ComponentType<ComponentsProp> | ||
): ReactElement | null | ||
|
||
/** | ||
* React createElement function wrapped with handler for MDX content | ||
*/ | ||
declare const mdx: typeof createElement | ||
|
||
export { | ||
ComponentDictionary, | ||
ComponentsProp, | ||
MDXContext, | ||
MDXProvider, | ||
useMDXComponents, | ||
withMDXComponents, | ||
mdx | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import * as React from 'react' | ||
import { | ||
MDXProvider, | ||
useMDXComponents, | ||
withMDXComponents, | ||
ComponentsProp, | ||
MDXContext, | ||
mdx | ||
} from '@mdx-js/react' | ||
|
||
const H1 = ({children}: {children: React.ComponentType}) => <h1>{children}</h1> | ||
|
||
const MDXProvideExample = () => ( | ||
<MDXProvider components={{h1: H1}}> | ||
<h1>Hello, world!</h1> | ||
</MDXProvider> | ||
) | ||
|
||
const WithMDXComponentsExample = () => | ||
withMDXComponents(({components}: ComponentsProp) => { | ||
components // $ExpectType ComponentDictionary | ||
return <div /> | ||
}) | ||
|
||
const UseMDXComponentsExample = () => { | ||
useMDXComponents({h1: H1}) // $ExpectType ComponentDictionary | ||
useMDXComponents(() => ({h1: H1})) // $ExpectType ComponentDictionary | ||
} | ||
|
||
const UseMDXContextExample = () => { | ||
const {components} = React.useContext(MDXContext) | ||
components // $ExpectType ComponentDictionary | ||
} | ||
|
||
const MDXCreateElementExample = () => mdx('mdx', {title: 'example'}, []) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "commonjs", | ||
"lib": ["dom", "es6"], | ||
"strict": true, | ||
"skipLibCheck": true, | ||
"baseUrl": ".", | ||
"jsx": "react", | ||
"paths": { | ||
"@mdx-js/react": ["index.d.ts"] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"extends": "dtslint/dtslint.json", | ||
"rules": { | ||
"whitespace": false, | ||
"semicolon": false | ||
} | ||
} |
Oops, something went wrong.