diff --git a/contributing.md b/contributing.md index 31bccc45..da48e509 100644 --- a/contributing.md +++ b/contributing.md @@ -11,17 +11,3 @@ Remove a submodule: ```bash $ ./scripts/rm-submodule.sh react-tutorial-demo ``` - -## change version - -Change all packages versions (will change to `0.0.0+last-commit-sha`): - -```bash -$ yarn new-version -``` - -Or specific version: - -```bash -$ yarn new-version 1.0.0 -``` diff --git a/packages/mini-editor/src/code-walk.tsx b/packages/mini-editor/src/code-walk.tsx deleted file mode 100644 index 7b0f0d08..00000000 --- a/packages/mini-editor/src/code-walk.tsx +++ /dev/null @@ -1,34 +0,0 @@ -import React from "react" - -interface CodeWalkStep { - code?: string - focus?: string - // TODO this shoudln't change between steps - lang?: string -} - -interface CodeWalkProps - extends React.PropsWithoutRef< - JSX.IntrinsicElements["div"] - > { - /** A number between 0 and `steps.length - 1`. */ - progress?: number - /** Default code for all steps. */ - code?: string - /** Default focus for all steps. */ - focus?: string - lang?: string - steps?: CodeWalkStep[] - parentHeight?: number - minColumns?: number -} - -export { CodeWalk } - -function CodeWalk({ - steps = [], - ...rest -}: CodeWalkProps): React.ReactNode { - if (steps.length === 0) return null - return
-} diff --git a/packages/mini-editor/src/code.tsx b/packages/mini-editor/src/code.tsx index 8342365c..1d6e37d5 100644 --- a/packages/mini-editor/src/code.tsx +++ b/packages/mini-editor/src/code.tsx @@ -7,7 +7,7 @@ import { getFocusIndexes, } from "./focus-parser" -type CodeProps = { +export type CodeProps = { prevCode: string prevFocus: string | null nextCode: string @@ -15,10 +15,10 @@ type CodeProps = { progress: number language: string parentHeight?: number - minColumns: number - minZoom: number - maxZoom: number - horizontalCenter: boolean + minColumns?: number + minZoom?: number + maxZoom?: number + horizontalCenter?: boolean } export function Code({ @@ -29,10 +29,10 @@ export function Code({ progress, language, parentHeight, - minColumns, - minZoom, - maxZoom, - horizontalCenter, + minColumns = 40, + minZoom = 0.5, + maxZoom = 1.5, + horizontalCenter = false, }: CodeProps) { const { prevLines, diff --git a/packages/mini-editor/src/editor-frame.tsx b/packages/mini-editor/src/editor-frame.tsx index b6e19a0c..a5af1dd3 100644 --- a/packages/mini-editor/src/editor-frame.tsx +++ b/packages/mini-editor/src/editor-frame.tsx @@ -3,77 +3,154 @@ import { MiniFrame, FrameButtons, } from "@code-hike/mini-frame" -import { Classes, useClasser } from "@code-hike/classer" -import "./index.scss" +import { useClasser, Classes } from "@code-hike/classer" -export { EditorFrame, TerminalPanel } +export { + EditorFrameProps, + getPanelStyles, + Snapshot, + OutputPanel, + TabsSnapshot, + Tab, +} -const DEFAULT_HEIGHT = 200 +type Tab = { + title: string + active: boolean + style: React.CSSProperties +} + +type OutputPanel = { + tabs: Tab[] + style: React.CSSProperties + children: React.ReactNode +} type EditorFrameProps = { - files: string[] - active: string + northPanel: OutputPanel + southPanel?: OutputPanel | null + terminalPanel?: React.ReactNode height?: number - terminalPanel: React.ReactNode button?: React.ReactNode classes?: Classes } & React.PropsWithoutRef
)
}
-function useSteps(
- ogSteps: MiniEditorStep[] | undefined,
- { code = "", focus, lang, file, tabs }: MiniEditorStep
-) {
- return React.useMemo(() => {
- const steps = ogSteps?.map(s => ({
- code,
- focus,
- lang,
- file,
- tabs,
- ...s,
- })) || [{ code, focus, lang, file, tabs }]
-
- const files = [
- ...new Set(
- steps
- .map((s: any) => s.file)
- .filter((f: any) => f != null)
- ),
- ]
-
- const stepsByFile: Record
+ )
+}
+
+/**
+ * Get the StepFiles for a transition
+ * in each panel, if the prev and next active files are the same
+ * we return the prev and next version of that panel
+ * if the active files are different, we return the same file twice,
+ * if backward is true we return the prev active file twice,
+ * or else the next active file twice
+ */
+function getStepFiles(
+ prev: EditorStep,
+ next: EditorStep,
+ backward: boolean
+) {
+ // The active file in each panel before and after:
+ // +----+----+
+ // | pn | nn |
+ // +----+----+
+ // | ps | ns |
+ // +----+----+
+ //
+ const pn = prev.northPanel.active
+ const nn = next.northPanel.active
+ const ps = prev.southPanel?.active
+ const ns = next.southPanel?.active
+
+ const pnFile = prev.files.find(f => f.name === pn)!
+ const nnFile = next.files.find(f => f.name === nn)!
+ const psFile = ps
+ ? prev.files.find(f => f.name === ps)
+ : null
+ const nsFile = ns
+ ? next.files.find(f => f.name === ns)
+ : null
+
+ const oneToTwoSouth = !ps && pn === ns
+ if (oneToTwoSouth) {
+ return {
+ prevNorthFile: nnFile,
+ nextNorthFile: nnFile,
+ prevSouthFile: pnFile,
+ nextSouthFile: nsFile,
+ }
+ }
+
+ const twoToOneSouth = !ns && nn === ps
+ if (twoToOneSouth) {
+ return {
+ prevNorthFile: pnFile,
+ nextNorthFile: pnFile,
+ prevSouthFile: psFile,
+ nextSouthFile: nnFile,
+ }
+ }
+
+ const prevNorthFile =
+ pn === nn ? pnFile : backward ? pnFile : nnFile
+
+ const nextNorthFile =
+ pn === nn ? nnFile : backward ? pnFile : nnFile
+
+ const prevSouthFile =
+ ps === ns
+ ? psFile
+ : backward
+ ? psFile || nsFile
+ : nsFile || psFile
+
+ const nextSouthFile =
+ ps === ns
+ ? nsFile
+ : backward
+ ? psFile || nsFile
+ : nsFile || psFile
+
+ return {
+ prevNorthFile,
+ nextNorthFile,
+ prevSouthFile,
+ nextSouthFile,
+ }
+}
diff --git a/packages/mini-editor/src/mini-editor.tsx b/packages/mini-editor/src/mini-editor.tsx
deleted file mode 100644
index f3a6fd6e..00000000
--- a/packages/mini-editor/src/mini-editor.tsx
+++ /dev/null
@@ -1,58 +0,0 @@
-import React from "react"
-import { useSpring } from "use-spring"
-import {
- MiniEditorHike,
- MiniEditorHikeProps,
-} from "./mini-editor-hike"
-
-export { MiniEditor }
-
-export type MiniEditorProps = Omit<
- MiniEditorHikeProps,
- "progress" | "steps" | "backward"
->
-
-function MiniEditor({
- focus,
- code,
- ...rest
-}: MiniEditorProps) {
- const [steps, progress] = usePrevFocus(code, focus)
-
- return (
-
+