Skip to content

Better errors #135

New issue

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

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

Already on GitHub? # to your account

Merged
merged 4 commits into from
Feb 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 6 additions & 3 deletions packages/mdx/src/client/scrollycoding.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
}

.ch-scrollycoding-content {
width: 50%;
box-sizing: border-box;
padding-right: 16px;
flex: 1;
}

.ch-scrollycoding-step-content {
Expand Down Expand Up @@ -39,7 +39,7 @@
align-self: start;
flex-flow: column;
justify-content: center;
width: 420px;
width: var(--ch-scrollycoding-sticker-width, 420px);
// capitalized Min to avoid usint the sass min
// min-height: Min(100%, 80vh);
max-height: 80vh;
Expand All @@ -66,7 +66,10 @@
.ch-codegroup {
width: 100%;
min-width: 100%;
min-height: 200px;
min-height: var(
--ch-scrollycoding-code-min-height,
200px
);
max-height: 80vh;
margin-top: 0;
margin-bottom: 0;
Expand Down
2 changes: 2 additions & 0 deletions packages/mdx/src/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

& > * {
height: 100%;
max-height: inherit;
min-height: inherit;
}
}

Expand Down
12 changes: 11 additions & 1 deletion packages/mdx/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ type CodeHikeConfig = {
lineNumbers?: boolean
}

export function remarkCodeHike(config: CodeHikeConfig) {
export function remarkCodeHike(
unsafeConfig: CodeHikeConfig
) {
return async (tree: Node) => {
// TODO add opt-in config
let hasCodeHikeImport = false
Expand All @@ -30,6 +32,8 @@ export function remarkCodeHike(config: CodeHikeConfig) {
}
})

const config = addConfigDefaults(unsafeConfig)

addConfig(tree as Parent, config)

if (!hasCodeHikeImport) {
Expand All @@ -52,6 +56,12 @@ export function remarkCodeHike(config: CodeHikeConfig) {
}
}

function addConfigDefaults(
config: Partial<CodeHikeConfig> | undefined
): CodeHikeConfig {
return { ...config, theme: config?.theme || {} }
}

function addConfig(tree: Parent, config: CodeHikeConfig) {
tree.children.unshift({
type: "mdxjsEsm",
Expand Down
21 changes: 18 additions & 3 deletions packages/mini-editor/src/editor-frame.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ export const EditorFrame = React.forwardRef<
},
ref
) {
const c = useClasser("ch-editor")

return (
<div
ref={ref}
Expand Down Expand Up @@ -185,7 +183,7 @@ function TabsContainer({
}}
onClick={onTabClick && (() => onTabClick(title))}
>
<div>{title}</div>
<TabTitle title={title} />
</div>
))}
<div style={{ flex: 1 }} />
Expand All @@ -194,6 +192,23 @@ function TabsContainer({
)
}

function TabTitle({ title }: { title: string }) {
if (!title) {
return <div />
}

const separatorIndex = title.lastIndexOf("/") + 1
const filename = title.substring(separatorIndex)
const folder = title.substring(0, separatorIndex)

return (
<div>
<span style={{ opacity: 0.5 }}>{folder}</span>
{filename}
</div>
)
}

type TabsSnapshot = Record<
string,
{ left: number; active: boolean; width: number }
Expand Down
6 changes: 1 addition & 5 deletions packages/mini-editor/src/editor-tween.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
import { TerminalPanel } from "./terminal-panel"
import { useTransition, EditorStep } from "./editor-shift"
import { CodeConfig } from "@code-hike/smooth-code"
import { useLayoutEffect } from "@code-hike/utils"

export {
EditorTransition,
Expand All @@ -14,11 +15,6 @@ export {
EditorTweenProps,
}

const useLayoutEffect =
typeof window !== "undefined"
? React.useLayoutEffect
: React.useEffect

type EditorTransitionProps = {
prev?: EditorStep
next?: EditorStep
Expand Down
2 changes: 2 additions & 0 deletions packages/playground/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ div#__next > div {
flex-direction: column;
font-family: sans-serif;
background-color: #444;
/* --ch-scrollycoding-code-min-height: 500px;
--ch-scrollycoding-sticker-width: 500px; */
}

nav {
Expand Down
2 changes: 1 addition & 1 deletion packages/smooth-code/src/code-tween.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ function AfterDimensions({
opacity: 1,
backgroundColor: bg,
color: fg,
["color-scheme" as any]: getColorScheme(theme),
["colorScheme" as any]: getColorScheme(theme),
["--ch-selection-background" as any]: getColor(
theme,
ColorName.SelectionBackground
Expand Down
6 changes: 1 addition & 5 deletions packages/smooth-code/src/use-dimensions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
FocusString,
getFocusIndexes,
Tween,
useLayoutEffect,
} from "@code-hike/utils"

type Dimensions = {
Expand All @@ -16,11 +17,6 @@ type Dimensions = {
lineNumberWidth: number
} | null

const useLayoutEffect =
typeof window !== "undefined"
? React.useLayoutEffect
: React.useEffect

export { useDimensions, Dimensions }

const DEFAULT_WIDTH = 200
Expand Down
12 changes: 12 additions & 0 deletions packages/utils/src/hooks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import React from "react"

export const useLayoutEffect =
typeof window !== "undefined"
? React.useLayoutEffect
: React.useEffect

// for debugging:
// export const useLayoutEffect = (
// effect: any,
// deps?: any
// ) => {}
1 change: 1 addition & 0 deletions packages/utils/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export * from "./tween"
export * from "./code"
export * from "./focus"
export * from "./theme"
export * from "./hooks"