Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore/spectacle mdx loader addition #1228

Merged
merged 24 commits into from
Feb 25, 2023
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
762b177
spectacle-mdx-loader addition setup
paulmarsicloud Aug 26, 2022
251d16b
mdx example updates
paulmarsicloud Aug 26, 2022
484f51e
Merge branch 'main' into chore/spectacle-mdx-loader-addition
paulmarsicloud Sep 16, 2022
9221a69
trying to add spectacle-mdx-loader
paulmarsicloud Sep 16, 2022
daffbc5
trying to add spectacle-mdx-loader
paulmarsicloud Sep 16, 2022
5ba53a8
testing out spectacle-mdx-loader
paulmarsicloud Sep 20, 2022
3c07137
testing out spectacle-mdx-loader
paulmarsicloud Sep 20, 2022
e96eb8e
Merge branch 'main' into chore/spectacle-mdx-loader-addition
paulmarsicloud Sep 20, 2022
8eaac34
testing out spectacle-mdx-loader
paulmarsicloud Sep 20, 2022
4de10ee
testing out spectacle-mdx-loader
paulmarsicloud Sep 20, 2022
0e8feb5
testing out spectacle-mdx-loader
paulmarsicloud Sep 20, 2022
78e1771
contributing update
paulmarsicloud Sep 20, 2022
298ee03
contributing update
paulmarsicloud Sep 20, 2022
daa02e8
webpack.config.js update
paulmarsicloud Sep 20, 2022
5586b52
PR feedback suggestions
paulmarsicloud Sep 20, 2022
6bdaec9
Clean up package and webpack config for mdx example.
ryan-roemer Sep 21, 2022
77009dc
Remove loop
ryan-roemer Sep 21, 2022
d9c59dd
Minor other cleanup
ryan-roemer Sep 21, 2022
a825036
Minor code cleanup
ryan-roemer Sep 21, 2022
6ce2d1e
Add ./examples/mdx:build
ryan-roemer Sep 22, 2022
910ce2e
Add changelog, fix deps
ryan-roemer Sep 23, 2022
b640452
lol ERR_PNPM_OUTDATED_LOCKFILE
ryan-roemer Sep 26, 2022
8d6e3d6
merge main into branch
paulmarsicloud Oct 7, 2022
b39de2f
Merge branch 'chore/spectacle-mdx-loader-addition' of github.com:Form…
paulmarsicloud Oct 7, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ We follow the convention of `start:NAME` to run an in-memory dev server for a sp
- [`examples/typescript`](https://github.com/FormidableLabs/spectacle/tree/main/examples/typescript)
- [`examples/one-page`](https://github.com/FormidableLabs/spectacle/tree/main/examples/one-page)
- `spectacle-mdx-loader`
- [`examples/mdx`](https://github.com/FormidableLabs/spectacle-mdx-loader/tree/main/examples/mdx)
- [`examples/mdx`](https://github.com/FormidableLabs/spectacle/tree/main/examples/mdx)

Here's how you can run the various examples:

Expand All @@ -49,6 +49,10 @@ $ open http://localhost:3100/
$ pnpm start:md
$ open http://localhost:3200/

# MDX demo app (in two different terminals)
$ pnpm start:mdx
$ open http://localhost:3300/

# One-page (no build, HTML page only) demo app (in two different terminals)
$ pnpm start:one-page
$ open examples/one-page/index.html
Expand Down
3 changes: 3 additions & 0 deletions examples/mdx/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "../../.babelrc.js"
}
14 changes: 14 additions & 0 deletions examples/mdx/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title><%= htmlWebpackPlugin.options.title %></title>
<link
href="https://fonts.googleapis.com/css?family=Open+Sans+Condensed:300,700&display=swap"
rel="stylesheet"
/>
</head>
<body>
<div id="root"></div>
</body>
</html>
60 changes: 60 additions & 0 deletions examples/mdx/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import React from 'react';
import { render } from 'react-dom';

import { MDXProvider } from '@mdx-js/react';

import {
Deck,
FlexBox,
Slide,
Box,
Progress,
FullScreen,
Notes,
mdxComponentMap
} from 'spectacle';

// SPECTACLE_CLI_MDX_START
import slides, { notes } from './slides.mdx';
// SPECTACLE_CLI_MDX_END

// SPECTACLE_CLI_THEME_START
const theme = {};
// SPECTACLE_CLI_THEME_END

// SPECTACLE_CLI_TEMPLATE_START
const template = () => (
<FlexBox
justifyContent="space-between"
position="absolute"
bottom={0}
width={1}
>
<Box padding="0 1em">
<FullScreen />
</Box>
<Box padding="1em">
<Progress />
</Box>
</FlexBox>
);
// SPECTACLE_CLI_TEMPLATE_END

const Presentation = () => (
<MDXProvider components={mdxComponentMap}>
<Deck loop theme={theme} template={template}>
ryan-roemer marked this conversation as resolved.
Show resolved Hide resolved
{slides
.map((MDXSlide, i) => [MDXSlide, notes[i]])
.map(([MDXSlide, MDXNote], i) => (
<Slide key={`slide-${i}`} slideNum={i}>
<MDXSlide />
<Notes>
<MDXNote />
</Notes>
</Slide>
))}
</Deck>
</MDXProvider>
);

render(<Presentation />, document.getElementById('root'));
71 changes: 71 additions & 0 deletions examples/mdx/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
{
"name": "spectacle-example-mdx",
"private": true,
"dependencies": {
"spectacle": "*",
"react": "^18.1.0",
"react-dom": "^18.1.0"
},
"devDependencies": {
"@mdx-js/react": "^1.5.3",
ryan-roemer marked this conversation as resolved.
Show resolved Hide resolved
"prop-types": "^15.7.2",
ryan-roemer marked this conversation as resolved.
Show resolved Hide resolved
"spectacle-mdx-loader": "*"
},
"scripts": {
"start": "webpack-dev-server --port=3300 --hot --config ./webpack.config.js",
"lint": "wireit",
"lint:fix": "wireit",
"prettier": "wireit",
"prettier:fix": "wireit"
},
"wireit": {
"lint": {
"command": "nps \"lint:base *.js\"",
"files": [
"../../.eslintignore",
"../../.eslintrc",
"*.{js,jsx,ts,tsx}"
],
"output": [],
"packageLocks": [
"pnpm-lock.yaml"
]
},
"lint:fix": {
"command": "pnpm run lint || nps \"lint:base --fix *.js\"",
"files": [
"../../.eslintignore",
"../../.eslintrc",
"*.{js,jsx,ts,tsx}"
],
"output": [],
"packageLocks": [
"pnpm-lock.yaml"
]
},
"prettier": {
"command": "nps prettier:pkg -- -- \"*\"",
"files": [
"../../.prettierignore",
"../../.prettierrc",
"*.{js,html}"
],
"output": [],
"packageLocks": [
"pnpm-lock.yaml"
]
},
"prettier:fix": {
"command": "pnpm run prettier || nps prettier:pkg:fix -- -- \"*\"",
"files": [
"../../.prettierignore",
"../../.prettierrc",
"*.{js,html}"
],
"output": [],
"packageLocks": [
"pnpm-lock.yaml"
]
}
}
}
64 changes: 64 additions & 0 deletions examples/mdx/slides.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import Test from './test-component';
export const testProp = 50;

# Spectacle Presentation (MDX) 👋

This example uses:

- `mdx`
- `@babel/preset-react` for the React components we import

Notes: These are presenter notes. This text will be automatically exported as `notes` from your MDX file (e.g. `import {notes} from './my-file.mdx'`).

---

## Yellow div from a JSX component

<Test height={testProp} />

Notes: here are some more notes.

---

# Write your Spectacle Presentations in Markdown

## And seamlessly use React Components

**How sweet is that**
**(super sweet)**

---

![datboi](https://pbs.twimg.com/media/CkjFUyTXEAEysBY.jpg)

---

###### Typography

# Heading 1

## Heading 2

### Heading 3

#### Heading 4

##### Heading 5

###### Heading 6

Standard Text

---

> Example Quote

---

```jsx
class SuperCoolComponent extends React.Component {
render() {
return <p>code slide works in markdown too whaaaaat</p>;
}
}
```
12 changes: 12 additions & 0 deletions examples/mdx/test-component.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import React from 'react';
import PropTypes from 'prop-types';
fritz-c marked this conversation as resolved.
Show resolved Hide resolved

const Test = ({ height }) => {
return <div style={{ height, width: '100%', backgroundColor: 'yellow' }} />;
};

Test.propTypes = {
height: PropTypes.number.isRequired
};

export default Test;
56 changes: 56 additions & 0 deletions examples/mdx/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const base = require('../../webpack.config.base');

// Customized babel loader with the minimum we need to get `mdx` libraries
// working, which unfortunately codegen JSX instead of JS.
const babelLoader = {
loader: require.resolve('babel-loader')
ryan-roemer marked this conversation as resolved.
Show resolved Hide resolved
};

/**
* Base configuration for the CLI, core, and examples.
*/
module.exports = {
...base,
mode: 'development',
context: __dirname,
entry: './index.js',
output: {
path: path.join(__dirname, 'dist'),
filename: 'example.js'
},
externals: {},
devtool: 'source-map',
module: {
// Not we use `require.resolve` to make sure to use the loader installed
// within _this_ project's `node_modules` traversal tree.
rules: [
{
test: /\.jsx?$/,
use: [babelLoader]
},
// `.md` files are processed as pure text.
{
test: /\.md$/,
use: [require.resolve('raw-loader')]
ryan-roemer marked this conversation as resolved.
Show resolved Hide resolved
},
// `.mdx` files go through babel and mdx transforming loader.
{
test: /\.mdx$/,
use: [babelLoader, require.resolve('spectacle-mdx-loader')]
},
{
test: /\.(png|svg|jpg|gif)$/,
use: [require.resolve('file-loader')]
ryan-roemer marked this conversation as resolved.
Show resolved Hide resolved
}
]
},
plugins: [
...base.plugins,
new HtmlWebpackPlugin({
title: 'Spectacle MDX Development Example',
template: `./index.html`
})
]
};
9 changes: 9 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"changeset": "changeset",
"start:js": "concurrently --raw pnpm:build:spectacle:esm:watch pnpm:build:spectacle:types:watch \"pnpm run --filter ./examples/js start\"",
"start:md": "concurrently --raw pnpm:build:spectacle:esm:watch pnpm:build:spectacle:types:watch \"pnpm run --filter ./examples/md start\"",
"start:mdx": "concurrently --raw pnpm:build:spectacle:esm:watch pnpm:build:spectacle:types:watch \"pnpm run --filter ./examples/mdx start\"",
"start:ts": "concurrently --raw pnpm:build:spectacle:esm:watch pnpm:build:spectacle:types:watch \"pnpm run --filter ./examples/typescript start\"",
"start:one-page": "concurrently --raw pnpm:build:spectacle:dev:watch pnpm:build:spectacle:dev:watch",
"start:examples": "concurrently --raw pnpm:build:spectacle:esm:watch pnpm:build:spectacle:dev:watch pnpm:build:spectacle:dev:watch \"pnpm run --parallel --filter \\\"./examples/*\\\" start\"",
Expand Down Expand Up @@ -168,9 +169,11 @@
"dependencies": [
"./packages/spectacle:lint",
"./packages/create-spectacle:lint",
"./packages/spectacle-mdx-loader:lint",
"./website:lint",
ryan-roemer marked this conversation as resolved.
Show resolved Hide resolved
"./examples/js:lint",
"./examples/md:lint",
"./examples/mdx:lint",
"./examples/one-page:lint",
"./examples/typescript:lint"
]
Expand All @@ -179,9 +182,11 @@
"dependencies": [
"./packages/spectacle:lint:fix",
"./packages/create-spectacle:lint:fix",
"./packages/spectacle-mdx-loader:lint:fix",
"./website:lint:fix",
"./examples/js:lint:fix",
"./examples/md:lint:fix",
"./examples/mdx:lint:fix",
"./examples/one-page:lint:fix",
"./examples/typescript:lint:fix"
]
Expand Down Expand Up @@ -228,9 +233,11 @@
"dependencies": [
"./packages/spectacle:prettier",
"./packages/create-spectacle:prettier",
"./packages/spectacle-mdx-loader:prettier",
"./website:prettier",
"./examples/js:prettier",
"./examples/md:prettier",
"./examples/mdx:prettier",
"./examples/one-page:prettier",
"./examples/typescript:prettier"
]
Expand All @@ -239,9 +246,11 @@
"dependencies": [
"./packages/spectacle:prettier:fix",
"./packages/create-spectacle:prettier:fix",
"./packages/spectacle-mdx-loader:prettier:fix",
"./website:prettier:fix",
"./examples/js:prettier:fix",
"./examples/md:prettier:fix",
"./examples/mdx:prettier:fix",
"./examples/one-page:prettier:fix",
"./examples/typescript:prettier:fix"
]
Expand Down
7 changes: 7 additions & 0 deletions packages/spectacle-mdx-loader/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
node_modules
package-lock.json
dist
*.log
.DS_Store
.vscode
.examples-boilerplate
21 changes: 21 additions & 0 deletions packages/spectacle-mdx-loader/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)
ryan-roemer marked this conversation as resolved.
Show resolved Hide resolved

Copyright (c) 2019 Formidable Labs

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Loading