-
-
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.
* feat(vue): implemented context for vue * test(vue): documented vue tests * bump vue versions, fix loader test, get example app running with MDX and MDXProvider * Update examples/vue/package.json * Update examples/vue/package.json * Update package.json * Update packages/vue-loader/package.json * Update packages/vue-loader/package.json * Update packages/vue/package.json Co-authored-by: codebender828 <[email protected]> Co-authored-by: John Otander <[email protected]>
- Loading branch information
1 parent
a5389a1
commit 47b2c62
Showing
19 changed files
with
266 additions
and
499 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,30 @@ | ||
<template> | ||
<div id="app"> | ||
<h1>Hello MDX</h1> | ||
<Test /> | ||
<MDXProvider v-bind:components="components"> | ||
<Test /> | ||
</MDXProvider> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
import {MDXProvider} from '@mdx-js/vue' | ||
import HelloWorld from './components/HelloWorld' | ||
import Test from './test.mdx' | ||
export default { | ||
name: 'app', | ||
components: { | ||
Test: Test | ||
Test, | ||
MDXProvider | ||
}, | ||
data() { | ||
return { | ||
components: { | ||
section: props => HelloWorld, | ||
wrapper: props => 'article' | ||
} | ||
} | ||
} | ||
} | ||
</script> |
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
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,7 +15,8 @@ | |
"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)", | ||
"Jonathan Bakebwa <[email protected]> (https://jbakebwa.dev)" | ||
], | ||
"license": "MIT", | ||
"files": [ | ||
|
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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -2,29 +2,41 @@ | |
"name": "@mdx-js/vue", | ||
"version": "1.5.9", | ||
"description": "MDX support for Vue components", | ||
"repository": "mdx-js/mdx", | ||
"funding": { | ||
"type": "opencollective", | ||
"url": "https://opencollective.com/unified" | ||
}, | ||
"contributors": [ | ||
"JounQin <[email protected]> (https://www.1stg.me)" | ||
], | ||
"license": "MIT", | ||
"main": "dist/cjs.js", | ||
"module": "dist/esm.js", | ||
"license": "MIT", | ||
"author": "Jonathan Bakebwa <[email protected]> (https://jbakebwa.dev)", | ||
"files": [ | ||
"dist" | ||
], | ||
"scripts": { | ||
"dev": "watch 'yarn build' src", | ||
"build": "yarn build:cjs && yarn build:es", | ||
"build:cjs": "cross-env NODE_ENV=production BABEL_ENV=cjs babel src -d dist --copy-files", | ||
"build:es": "cross-env NODE_ENV=production BABEL_ENV=es babel src -d dist/es --copy-files", | ||
"test": "jest" | ||
}, | ||
"devDependencies": { | ||
"@babel/cli": "^7.8.4", | ||
"@babel/core": "^7.9.0", | ||
"@babel/preset-env": "^7.9.5", | ||
"cross-env": "^7.0.2", | ||
"watch": "^1.0.2" | ||
}, | ||
"babel": { | ||
"presets": [ | ||
"@babel/preset-env" | ||
], | ||
"exclude": [ | ||
"node_modules" | ||
] | ||
}, | ||
"keywords": [ | ||
"markdown", | ||
"vue", | ||
"mdx", | ||
"remark" | ||
], | ||
"scripts": { | ||
"no-test": "jest" | ||
}, | ||
"jest": { | ||
"testEnvironment": "jsdom" | ||
} | ||
|
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 |
---|---|---|
@@ -1,3 +1,61 @@ | ||
/** | ||
* MDX default components | ||
*/ | ||
const DEFAULTS = { | ||
inlineCode: 'code', | ||
wrapper: 'div' | ||
} | ||
|
||
/** | ||
* Renders final tag/component | ||
* @param {Vue.Component|String} type Element or tag to render | ||
* @param {Object|Array} props Props and attributes for element | ||
* @param {Array} children Array of child nodes for component | ||
* @returns {Vue.VNode} VNode of final rendered element | ||
*/ | ||
export default function(type, props, children) { | ||
return this.vueCreateElement(type, props, children) | ||
|
||
const h = this.createElement | ||
const components = this.components | ||
const defaults = Object.keys(DEFAULTS) | ||
|
||
let tag | ||
let elProps = props | ||
|
||
// We check context to see if the element/tag | ||
// is provided in the MDXProvider context. | ||
if (Object.keys(components).includes(type)) { | ||
// We check to see if props is of type object. | ||
// If it is, then we pass them into the MDXContext component | ||
const componentProps = typeof props === 'object' ? props : undefined | ||
tag = components[type](componentProps) | ||
|
||
} else if (defaults.includes(type)) { | ||
|
||
tag = DEFAULTS[type] | ||
// Remove components object from attrs | ||
const { components, ...attrs } = elProps.attrs | ||
elProps = { | ||
attrs | ||
} | ||
|
||
// Render final tag if component is not provided in context | ||
} else { | ||
tag = type | ||
|
||
if (['a', 'input', 'img'].includes(tag)) { | ||
const { attrs, ...domProps } = elProps | ||
const data = { | ||
attrs: attrs, | ||
domProps | ||
} | ||
|
||
elProps = { | ||
...elProps, | ||
...data | ||
} | ||
} | ||
} | ||
|
||
return h(tag, elProps, children) | ||
} |
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
export {default as mdx} from './create-element' | ||
export { default as mdx } from './create-element'; | ||
export { default as MDXProvider } from './mdx-provider' |
Oops, something went wrong.