Skip to content

Commit d32feb5

Browse files
committed
Better height for next file
1 parent 5c1465b commit d32feb5

File tree

4 files changed

+137
-22
lines changed

4 files changed

+137
-22
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export const EditorFrame = React.forwardRef<
8989
<div
9090
className={"ch-frame-title-bar"}
9191
style={{
92-
transform: southPanel.style.transform,
92+
transform: southPanel.style?.transform,
9393
}}
9494
>
9595
<TabsContainer

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ function startingPosition(
176176
<CodeTransition
177177
codeConfig={codeConfig}
178178
prevFile={prevNorthFile}
179-
nextFile={nextNorthFile}
179+
nextFile={prevNorthFile}
180180
t={0}
181181
parentHeight={"0"}
182182
/>
@@ -196,7 +196,7 @@ function startingPosition(
196196
<CodeTransition
197197
codeConfig={codeConfig}
198198
prevFile={prevSouthFile!}
199-
nextFile={nextSouthFile!}
199+
nextFile={prevSouthFile!}
200200
t={0}
201201
parentHeight={"0"}
202202
/>
@@ -242,7 +242,7 @@ function endingPosition(
242242
children: (
243243
<CodeTransition
244244
codeConfig={codeConfig}
245-
prevFile={prevNorthFile}
245+
prevFile={nextNorthFile}
246246
nextFile={nextNorthFile}
247247
t={1}
248248
parentHeight={"1"}
@@ -262,7 +262,7 @@ function endingPosition(
262262
children: (
263263
<CodeTransition
264264
codeConfig={codeConfig}
265-
prevFile={prevSouthFile!}
265+
prevFile={nextSouthFile!}
266266
nextFile={nextSouthFile!}
267267
t={1}
268268
parentHeight={"1"}
@@ -782,6 +782,7 @@ function useSnapshots(
782782

783783
useLayoutEffect(() => {
784784
if (!prevSnapshot) {
785+
// debugger
785786
setState(s => ({
786787
...s,
787788
prevSnapshot: {
@@ -790,6 +791,7 @@ function useSnapshots(
790791
},
791792
}))
792793
} else if (!nextSnapshot) {
794+
// debugger
793795
setState(s => ({
794796
...s,
795797
nextSnapshot: {

packages/playground/content/spotlight-demo.mdx

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ This is how to use the `<CH.Spotlight>` component. Lorem ipsum dolor sit amet co
44

55
<CH.Spotlight>
66

7-
<CH.Code>
8-
97
```js app.js
108
function lorem(ipsum, dolor = 1) {
119
const sit = ipsum == null && 0
@@ -14,14 +12,6 @@ function lorem(ipsum, dolor = 1) {
1412
}
1513
```
1614

17-
```css styles.css
18-
.lorem {
19-
color: red;
20-
}
21-
```
22-
23-
</CH.Code>
24-
2515
---
2616

2717
Change focus
@@ -53,13 +43,7 @@ Or change the file
5343

5444
<CH.Code>
5545

56-
```js app.js focus=6:10
57-
function lorem(ipsum, dolor = 1) {
58-
const sit = ipsum == null && 0
59-
dolor = sit - amet(dolor)
60-
return sit ? consectetur(ipsum) : []
61-
}
62-
46+
```js app.js focus=1:4
6347
function adipiscing(...elit) {
6448
console.log(elit)
6549
return elit.map(ipsum => ipsum.sit)
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
import React from "react"
2+
import { EditorTween } from "@code-hike/mini-editor"
3+
import { WithProgress } from "./utils"
4+
import "@code-hike/mini-editor/dist/index.css"
5+
import theme from "shiki/themes/github-light.json"
6+
import { highlight } from "@code-hike/highlighter"
7+
8+
export default {
9+
title: "Test/Editor Tween Two",
10+
}
11+
12+
export const smartHeight = () => {
13+
const prev = {
14+
files: [
15+
{
16+
name: "app.js",
17+
code: `
18+
function lorem(ipsum, dolor = 1) {
19+
const sit = ipsum == null && 0
20+
dolor = sit - amet(dolor)
21+
return sit ? consectetur(ipsum) : []
22+
}
23+
24+
function adipiscing(...elit) {
25+
console.log(elit)
26+
return elit.map(ipsum => ipsum.sit)
27+
}`.trim(),
28+
lang: "js",
29+
focus: "6:10",
30+
annotations: [],
31+
},
32+
],
33+
northPanel: {
34+
tabs: ["app.js"],
35+
active: "app.js",
36+
heightRatio: 1,
37+
},
38+
southPanel: undefined,
39+
}
40+
const next = {
41+
files: [
42+
{
43+
name: "app.js",
44+
code: `
45+
function adipiscing(...elit) {
46+
console.log(elit)
47+
return elit.map(ipsum => ipsum.sit)
48+
}`.trim(),
49+
lang: "js",
50+
focus: "1:4",
51+
annotations: [],
52+
},
53+
{
54+
name: "styles.css",
55+
code: `
56+
.lorem {
57+
color: #fff;
58+
padding: 10px;
59+
background: #000;
60+
}`.trim(),
61+
lang: "css",
62+
focus: "",
63+
annotations: [],
64+
},
65+
],
66+
northPanel: {
67+
tabs: ["app.js"],
68+
active: "app.js",
69+
heightRatio: 1,
70+
},
71+
southPanel: {
72+
tabs: ["styles.css"],
73+
active: "styles.css",
74+
heightRatio: 1,
75+
},
76+
}
77+
return <TestTransition prev={prev} next={next} />
78+
}
79+
80+
function TestTransition({ prev, next }) {
81+
const [data, setData] = React.useState(null)
82+
React.useEffect(() => {
83+
const prevFilePromises = prev.files.map(
84+
({ code, lang, ...rest }) =>
85+
highlight({ code, lang, theme }).then(code => ({
86+
code,
87+
...rest,
88+
}))
89+
)
90+
const nextFilePromises = next.files.map(
91+
({ code, lang, ...rest }) =>
92+
highlight({ code, lang, theme }).then(code => ({
93+
code,
94+
...rest,
95+
}))
96+
)
97+
98+
Promise.all([
99+
Promise.all(prevFilePromises),
100+
Promise.all(nextFilePromises),
101+
]).then(([prevFiles, nextFiles]) =>
102+
setData({
103+
prev: { ...prev, files: prevFiles },
104+
next: { ...next, files: nextFiles },
105+
})
106+
)
107+
}, [])
108+
109+
if (!data) {
110+
return "Loading..."
111+
}
112+
113+
return (
114+
<WithProgress length={2}>
115+
{(progress, backward) => (
116+
<>
117+
<EditorTween
118+
frameProps={{ style: { height: 300 } }}
119+
prev={data.prev}
120+
next={data.next}
121+
t={progress}
122+
backward={backward}
123+
codeConfig={{ theme }}
124+
/>
125+
</>
126+
)}
127+
</WithProgress>
128+
)
129+
}

0 commit comments

Comments
 (0)