Skip to content

Commit 22c5e04

Browse files
authored
Merge pull request #135 from code-hike/better-errors-1
Better errors
2 parents f222408 + fbbee30 commit 22c5e04

File tree

9 files changed

+54
-17
lines changed

9 files changed

+54
-17
lines changed

packages/mdx/src/client/scrollycoding.scss

+6-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
}
66

77
.ch-scrollycoding-content {
8-
width: 50%;
98
box-sizing: border-box;
109
padding-right: 16px;
10+
flex: 1;
1111
}
1212

1313
.ch-scrollycoding-step-content {
@@ -39,7 +39,7 @@
3939
align-self: start;
4040
flex-flow: column;
4141
justify-content: center;
42-
width: 420px;
42+
width: var(--ch-scrollycoding-sticker-width, 420px);
4343
// capitalized Min to avoid usint the sass min
4444
// min-height: Min(100%, 80vh);
4545
max-height: 80vh;
@@ -66,7 +66,10 @@
6666
.ch-codegroup {
6767
width: 100%;
6868
min-width: 100%;
69-
min-height: 200px;
69+
min-height: var(
70+
--ch-scrollycoding-code-min-height,
71+
200px
72+
);
7073
max-height: 80vh;
7174
margin-top: 0;
7275
margin-bottom: 0;

packages/mdx/src/index.scss

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
& > * {
1717
height: 100%;
18+
max-height: inherit;
19+
min-height: inherit;
1820
}
1921
}
2022

packages/mdx/src/plugin.ts

+11-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ type CodeHikeConfig = {
1616
lineNumbers?: boolean
1717
}
1818

19-
export function remarkCodeHike(config: CodeHikeConfig) {
19+
export function remarkCodeHike(
20+
unsafeConfig: CodeHikeConfig
21+
) {
2022
return async (tree: Node) => {
2123
// TODO add opt-in config
2224
let hasCodeHikeImport = false
@@ -30,6 +32,8 @@ export function remarkCodeHike(config: CodeHikeConfig) {
3032
}
3133
})
3234

35+
const config = addConfigDefaults(unsafeConfig)
36+
3337
addConfig(tree as Parent, config)
3438

3539
if (!hasCodeHikeImport) {
@@ -52,6 +56,12 @@ export function remarkCodeHike(config: CodeHikeConfig) {
5256
}
5357
}
5458

59+
function addConfigDefaults(
60+
config: Partial<CodeHikeConfig> | undefined
61+
): CodeHikeConfig {
62+
return { ...config, theme: config?.theme || {} }
63+
}
64+
5565
function addConfig(tree: Parent, config: CodeHikeConfig) {
5666
tree.children.unshift({
5767
type: "mdxjsEsm",

packages/mini-editor/src/editor-frame.tsx

+18-3
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@ export const EditorFrame = React.forwardRef<
5757
},
5858
ref
5959
) {
60-
const c = useClasser("ch-editor")
61-
6260
return (
6361
<div
6462
ref={ref}
@@ -185,7 +183,7 @@ function TabsContainer({
185183
}}
186184
onClick={onTabClick && (() => onTabClick(title))}
187185
>
188-
<div>{title}</div>
186+
<TabTitle title={title} />
189187
</div>
190188
))}
191189
<div style={{ flex: 1 }} />
@@ -194,6 +192,23 @@ function TabsContainer({
194192
)
195193
}
196194

195+
function TabTitle({ title }: { title: string }) {
196+
if (!title) {
197+
return <div />
198+
}
199+
200+
const separatorIndex = title.lastIndexOf("/") + 1
201+
const filename = title.substring(separatorIndex)
202+
const folder = title.substring(0, separatorIndex)
203+
204+
return (
205+
<div>
206+
<span style={{ opacity: 0.5 }}>{folder}</span>
207+
{filename}
208+
</div>
209+
)
210+
}
211+
197212
type TabsSnapshot = Record<
198213
string,
199214
{ left: number; active: boolean; width: number }

packages/mini-editor/src/editor-tween.tsx

+1-5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
import { TerminalPanel } from "./terminal-panel"
77
import { useTransition, EditorStep } from "./editor-shift"
88
import { CodeConfig } from "@code-hike/smooth-code"
9+
import { useLayoutEffect } from "@code-hike/utils"
910

1011
export {
1112
EditorTransition,
@@ -14,11 +15,6 @@ export {
1415
EditorTweenProps,
1516
}
1617

17-
const useLayoutEffect =
18-
typeof window !== "undefined"
19-
? React.useLayoutEffect
20-
: React.useEffect
21-
2218
type EditorTransitionProps = {
2319
prev?: EditorStep
2420
next?: EditorStep

packages/playground/styles.css

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ div#__next > div {
1010
flex-direction: column;
1111
font-family: sans-serif;
1212
background-color: #444;
13+
/* --ch-scrollycoding-code-min-height: 500px;
14+
--ch-scrollycoding-sticker-width: 500px; */
1315
}
1416

1517
nav {

packages/smooth-code/src/use-dimensions.tsx

+1-5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
FocusString,
44
getFocusIndexes,
55
Tween,
6+
useLayoutEffect,
67
} from "@code-hike/utils"
78

89
type Dimensions = {
@@ -16,11 +17,6 @@ type Dimensions = {
1617
lineNumberWidth: number
1718
} | null
1819

19-
const useLayoutEffect =
20-
typeof window !== "undefined"
21-
? React.useLayoutEffect
22-
: React.useEffect
23-
2420
export { useDimensions, Dimensions }
2521

2622
const DEFAULT_WIDTH = 200

packages/utils/src/hooks.ts

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import React from "react"
2+
3+
export const useLayoutEffect =
4+
typeof window !== "undefined"
5+
? React.useLayoutEffect
6+
: React.useEffect
7+
8+
// for debugging:
9+
// export const useLayoutEffect = (
10+
// effect: any,
11+
// deps?: any
12+
// ) => {}

packages/utils/src/index.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ export * from "./tween"
22
export * from "./code"
33
export * from "./focus"
44
export * from "./theme"
5+
export * from "./hooks"

0 commit comments

Comments
 (0)