Skip to content

Commit 221e7e8

Browse files
committed
fixed all broken examples
1 parent b27b687 commit 221e7e8

File tree

9 files changed

+41
-44
lines changed

9 files changed

+41
-44
lines changed

docs/app/guides/display/images/page.tsx

+14-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import ImageExample from "guide-examples/display/images/ImageExample"
55
import ImageAnchorExample from "guide-examples/display/images/ImageAnchorExample"
66
import type { Metadata } from "next"
77

8+
import mafsImage from "../../../../components/guide-examples/display/images/mafs.png"
9+
810
export const metadata: Metadata = {
911
title: "Images",
1012
}
@@ -17,7 +19,12 @@ function Images() {
1719
quality of life improvements tacked on (see below).
1820
</p>
1921

20-
<CodeAndExample example={ImageExample} />
22+
<CodeAndExample
23+
example={ImageExample}
24+
extraImports={{
25+
"./mafs.png": mafsImage,
26+
}}
27+
/>
2128

2229
<PropTable of={"Image"} />
2330

@@ -48,7 +55,12 @@ function Images() {
4855
the image.
4956
</p>
5057

51-
<CodeAndExample example={ImageAnchorExample} />
58+
<CodeAndExample
59+
example={ImageAnchorExample}
60+
extraImports={{
61+
"./mafs.png": mafsImage,
62+
}}
63+
/>
5264
</>
5365
)
5466
}

docs/app/guides/examples/bezier-curves/page.tsx

+8-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import BezierCurves from "guide-examples/examples/BezierCurves"
33
import Link from "next/link"
44
import type { Metadata } from "next"
55

6+
import * as easingFunctions from "js-easing-functions"
7+
68
export const metadata: Metadata = {
79
title: "Bezier curves",
810
}
@@ -15,7 +17,12 @@ export default function BezierCurvesPage() {
1517
<Link href="https://www.youtube.com/watch?v=aVwxzDHniEw">video on Bézier curves</Link>.
1618
</p>
1719

18-
<CodeAndExample example={BezierCurves} />
20+
<CodeAndExample
21+
example={BezierCurves}
22+
extraImports={{
23+
"js-easing-functions": easingFunctions,
24+
}}
25+
/>
1926
</>
2027
)
2128
}

docs/components/CodeAndExample.tsx

+8-27
Original file line numberDiff line numberDiff line change
@@ -28,44 +28,25 @@ interface Props {
2828
// eslint-disable-next-line @typescript-eslint/no-explicit-any
2929
example: any
3030
collapsible?: boolean
31+
extraImports?: Record<string, any>
3132
}
3233

33-
function CodeAndExample({ collapsible: collapsibleProp = true, example }: Props) {
34+
function CodeAndExample({ collapsible: collapsibleProp = true, extraImports = {}, example }: Props) {
3435
const typedExample = example as {
3536
$component: React.ComponentType
3637
$source: string
3738
$highlightedSource: React.ReactNode
38-
$width: number
39-
$height: number
4039
}
4140

4241
const runnerScope = React.useMemo(
4342
() => ({
4443
import: {
4544
react: React,
4645
mafs: {
47-
...mafs,
48-
Mafs: (props: mafs.MafsProps) => (
49-
<mafs.Mafs
50-
{...props}
51-
width={
52-
props.width
53-
? props.width
54-
: isNaN(typedExample.$width)
55-
? undefined
56-
: typedExample.$width
57-
}
58-
height={
59-
props.height
60-
? props.height
61-
: isNaN(typedExample.$height)
62-
? undefined
63-
: typedExample.$height
64-
}
65-
/>
66-
),
46+
...mafs
6747
},
68-
lodash
48+
lodash,
49+
...extraImports
6950
},
7051
}),
7152
[],
@@ -95,13 +76,13 @@ function CodeAndExample({ collapsible: collapsibleProp = true, example }: Props)
9576

9677
return (
9778
<div className="w-auto sm:text-base text-sm -m-6 md:m-0 dark:shadow-xl">
98-
<div className={`unround-mafs z-10 relative`} style={{ minHeight: isNaN(typedExample.$height) ? 300 : typedExample.$height }}>
79+
<div className={`unround-mafs z-10 relative`} style={{ minHeight: 100 }}>
9980
{!clientLoaded ? <Component /> : element}
10081
<div
101-
className="w-full h-full absolute top-0 left-0 bg-black/50 p-12"
82+
className="w-full h-full absolute top-0 left-0 bg-black/50 p-6"
10283
style={{ display: error ? "block" : "none" }}
10384
>
104-
<div className="w-full h-full bg-gray-900 dark:bg-black text-gray-100 rounded-lg border-[1px] border-red-300 p-4">
85+
<div className="w-full h-full overflow-y-auto bg-gray-900 dark:bg-black text-gray-100 rounded-lg border-[1px] border-red-300 p-4">
10586
<h4 className="text-gray-100">An error occured in your code!</h4>
10687
<hr className="my-2" />
10788
<code>{error}</code>

docs/components/RiemannHomepage.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
ConstraintFunction,
1212
} from "mafs"
1313

14-
import range from "lodash/range"
14+
import { range } from "lodash"
1515
import { easeInOutCubic } from "js-easing-functions"
1616

1717
interface Partition {

docs/components/guide-examples/SnapPoint.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
// prettier-ignore
44
import { Mafs, Transform, Vector, Coordinates, useMovablePoint, Circle, Polygon, vec, Theme } from "mafs"
5-
import clamp from "lodash/clamp"
5+
import { clamp } from "lodash"
66

77
export default function SnapPoint() {
88
return (

docs/components/guide-examples/display/DynamicMovablePoints.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
// prettier-ignore
44
import { Mafs, Coordinates, MovablePoint, useMovablePoint, Line, Theme, vec } from "mafs"
5-
import range from "lodash/range"
5+
import { range } from "lodash"
66

77
export default function DynamicMovablePoints() {
88
const start = useMovablePoint([-3, -1])

docs/components/guide-examples/display/PointsAlongFunction.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
// prettier-ignore
44
import { Mafs, Plot, Point, Coordinates, useMovablePoint } from "mafs"
5-
import range from "lodash/range"
5+
import { range } from "lodash"
66

77
export default function PointsAlongFunction() {
88
const fn = (x: number) => (x / 2) ** 2

docs/components/guide-examples/examples/Riemann.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ import {
1010
Coordinates,
1111
} from "mafs"
1212

13-
import sumBy from "lodash/sumBy"
14-
import range from "lodash/range"
13+
import {range, sumBy} from "lodash"
1514

1615
interface Partition {
1716
polygon: [number, number][]

docs/guide-example-loader.mjs

+6-8
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,19 @@ const starryNightPromise = createStarryNight(all)
1919
export default async function guideExampleLoader(source) {
2020
let cleanedSource = source
2121

22-
const heightRegex = /\s+height=\{([^}]*)\}/g
23-
const widthRegex = /\s+width=\{([^}]*)\}/g
22+
// const heightRegex = /\s+height=\{([^}]*)\}/g
23+
// const widthRegex = /\s+width=\{([^}]*)\}/g
2424

2525
const remove = [
26-
heightRegex,
27-
widthRegex,
26+
// heightRegex,
27+
// widthRegex,
2828
/.*prettier-ignore.*\n/gm,
2929
/^import React.* from "react"/gm,
3030
/"use client"/m,
3131
]
3232

33-
const height = parseFloat(heightRegex.exec(cleanedSource)?.[1] || "300");
34-
const width = parseFloat(widthRegex.exec(cleanedSource)?.[1] || "NaN");
33+
// const height = parseFloat(heightRegex.exec(cleanedSource)?.[1] || "300");
34+
// const width = parseFloat(widthRegex.exec(cleanedSource)?.[1] || "NaN");
3535

3636
remove.forEach((regex) => {
3737
cleanedSource = cleanedSource.replace(regex, "")
@@ -65,8 +65,6 @@ export default async function guideExampleLoader(source) {
6565
$default.$source = ${JSON.stringify(cleanedSource)};
6666
$default.$component = $default;
6767
$default.$highlightedSource = toJsxRuntime(${JSON.stringify(tree)}, { Fragment, jsx, jsxs });
68-
$default.$width = ${isNaN(width) ? "undefined" : JSON.stringify(width)};
69-
$default.$height = ${isNaN(width) ? "300" : JSON.stringify(height)};
7068
export default $default;
7169
`
7270
}

0 commit comments

Comments
 (0)