Skip to content

Commit 1c2b679

Browse files
committed
terminalコンポーネントはapp/に戻してみる
1 parent 5ff99e5 commit 1c2b679

32 files changed

+183
-194
lines changed

app/[lang]/[pageId]/chatForm.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { useState, FormEvent, useEffect } from "react";
88
// } from "../actions/questionExample";
99
// import { getLanguageName } from "../pagesList";
1010
import { DynamicMarkdownSection } from "./pageContent";
11-
import { useEmbedContext } from "@my-code/runtime/embedContext";
11+
import { useEmbedContext } from "@/terminal/embedContext";
1212
import { useChatHistoryContext } from "./chatHistory";
1313
import { askAI } from "@/actions/chatActions";
1414

app/[lang]/[pageId]/markdown.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@ import Markdown, { Components, ExtraProps } from "react-markdown";
22
import remarkGfm from "remark-gfm";
33
import removeComments from "remark-remove-comments";
44
import remarkCjkFriendly from "remark-cjk-friendly";
5-
import { EditorComponent, getAceLang } from "@my-code/runtime/editor";
6-
import { ExecFile } from "@my-code/runtime/exec";
5+
import { EditorComponent } from "@/terminal/editor";
6+
import { ExecFile } from "@/terminal/exec";
77
import { JSX, ReactNode } from "react";
8-
import { getRuntimeLang } from "@my-code/runtime/languages";
9-
import { ReplTerminal } from "@my-code/runtime/repl";
8+
import { getAceLang, getRuntimeLang, MarkdownLang } from "@my-code/runtime/languages";
9+
import { ReplTerminal } from "@/terminal/repl";
1010
import {
1111
getSyntaxHighlighterLang,
12-
MarkdownLang,
1312
StyledSyntaxHighlighter,
1413
} from "./styledSyntaxHighlighter";
1514

app/[lang]/[pageId]/styledSyntaxHighlighter.tsx

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
tomorrowNight,
77
} from "react-syntax-highlighter/dist/esm/styles/hljs";
88
import { lazy, Suspense, useEffect, useState } from "react";
9+
import { MarkdownLang, SyntaxHighlighterLang } from "@my-code/runtime/languages";
910

1011
// SyntaxHighlighterはファイルサイズがでかいので & HydrationErrorを起こすので、SSRを無効化する
1112
const SyntaxHighlighter = lazy(() => {
@@ -16,49 +17,6 @@ const SyntaxHighlighter = lazy(() => {
1617
}
1718
});
1819

19-
// Markdownで指定される可能性のある言語名を列挙
20-
export type MarkdownLang =
21-
| "python"
22-
| "py"
23-
| "ruby"
24-
| "rb"
25-
| "cpp"
26-
| "c++"
27-
| "rust"
28-
| "rs"
29-
| "javascript"
30-
| "js"
31-
| "typescript"
32-
| "ts"
33-
| "bash"
34-
| "sh"
35-
| "powershell"
36-
| "json"
37-
| "toml"
38-
| "csv"
39-
| "html"
40-
| "makefile"
41-
| "cmake"
42-
| "text"
43-
| "txt";
44-
45-
// react-syntax-highliter (hljs版) が対応している言語
46-
// https://github.com/react-syntax-highlighter/react-syntax-highlighter/blob/master/AVAILABLE_LANGUAGES_HLJS.MD を参照
47-
export type SyntaxHighlighterLang =
48-
| "python"
49-
| "ruby"
50-
| "c"
51-
| "cpp"
52-
| "rust"
53-
| "javascript"
54-
| "typescript"
55-
| "bash"
56-
| "powershell"
57-
| "html"
58-
| "json"
59-
| "ini"
60-
| "makefile"
61-
| "cmake";
6220
export function getSyntaxHighlighterLang(
6321
lang: MarkdownLang | undefined
6422
): SyntaxHighlighterLang | undefined {

app/actions/chatActions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// import { z } from "zod";
44
import { generateContent } from "./gemini";
55
import { DynamicMarkdownSection } from "../[lang]/[pageId]/pageContent";
6-
import { ReplCommand, ReplOutput } from "@my-code/runtime/repl";
6+
import { ReplCommand, ReplOutput } from "@my-code/runtime/interface";
77
import { addChat, ChatWithMessages } from "@/lib/chatHistory";
88

99
type ChatResult =

app/layout.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import "./globals.css";
88
import { Navbar } from "./navbar";
99
import { Sidebar } from "./sidebar";
1010
import { ReactNode } from "react";
11-
import { EmbedContextProvider } from "@my-code/runtime/embedContext";
11+
import { EmbedContextProvider } from "@/terminal/embedContext";
1212
import { AutoAnonymousLogin } from "./accountMenu";
1313
import { SidebarMdProvider } from "./sidebar";
1414
import { RuntimeProvider } from "@my-code/runtime/context";

app/sidebar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
} from "react";
1515
import { DynamicMarkdownSection } from "./[lang]/[pageId]/pageContent";
1616
import clsx from "clsx";
17-
import { LanguageIcon } from "@my-code/runtime/icons";
17+
import { LanguageIcon } from "@/terminal/icons";
1818
import { RuntimeLang } from "@my-code/runtime/languages";
1919

2020
export interface ISidebarMdContext {
Lines changed: 1 addition & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ import { lazy, Suspense, useEffect, useState } from "react";
44
import clsx from "clsx";
55
import { useChangeTheme } from "@/themeToggle";
66
import { useEmbedContext } from "./embedContext";
7-
import { langConstants } from "./languages";
8-
import { MarkdownLang } from "@/[lang]/[pageId]/styledSyntaxHighlighter";
7+
import { AceLang, langConstants } from "@my-code/runtime/languages";
98

109
// https://github.com/securingsincity/react-ace/issues/27 により普通のimportができない
1110
const AceEditor = lazy(async () => {
@@ -32,61 +31,6 @@ const AceEditor = lazy(async () => {
3231
}
3332
});
3433

35-
// mode-xxxx.js のファイル名と、AceEditorの mode プロパティの値が対応する
36-
export type AceLang =
37-
| "python"
38-
| "ruby"
39-
| "c_cpp"
40-
| "rust"
41-
| "javascript"
42-
| "typescript"
43-
| "json"
44-
| "csv"
45-
| "text";
46-
export function getAceLang(lang: MarkdownLang | undefined): AceLang {
47-
// Markdownで指定される可能性のある言語名からAceLangを取得
48-
switch (lang) {
49-
case "python":
50-
case "py":
51-
return "python";
52-
case "ruby":
53-
case "rb":
54-
return "ruby";
55-
case "cpp":
56-
case "c++":
57-
return "c_cpp";
58-
case "rust":
59-
case "rs":
60-
return "rust";
61-
case "javascript":
62-
case "js":
63-
return "javascript";
64-
case "typescript":
65-
case "ts":
66-
return "typescript";
67-
case "json":
68-
return "json";
69-
case "csv":
70-
return "csv";
71-
case "sh":
72-
case "bash":
73-
case "powershell":
74-
case "text":
75-
case "txt":
76-
case "html":
77-
case "toml":
78-
case "makefile":
79-
case "cmake":
80-
case undefined:
81-
console.warn(`Ace editor mode not implemented for language: ${lang}`);
82-
return "text";
83-
default:
84-
lang satisfies never;
85-
console.error(`getAceLang() does not handle language ${lang}`);
86-
return "text";
87-
}
88-
}
89-
9034
interface EditorProps {
9135
language?: AceLang;
9236
filename: string;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"use client";
22

3+
import { ReplCommand, ReplOutput } from "@my-code/runtime/interface";
34
import { usePathname } from "next/navigation";
45
import {
56
createContext,
@@ -9,7 +10,6 @@ import {
910
useEffect,
1011
useState,
1112
} from "react";
12-
import { ReplCommand, ReplOutput } from "./repl";
1313

1414
/*
1515
ファイルの内容や埋め込みターミナルのログを1箇所でまとめて管理し、書き込み・読み込みできるようにする
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import {
1010
import { writeOutput } from "./repl";
1111
import { useEffect, useState } from "react";
1212
import { useEmbedContext } from "./embedContext";
13-
import { RuntimeLang } from "./languages";
1413
import clsx from "clsx";
15-
import { useRuntime } from "./context";
14+
import { RuntimeLang } from "@my-code/runtime/languages";
15+
import { useRuntime } from "@my-code/runtime/context";
1616

1717
interface ExecProps {
1818
/*
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import chalk from "chalk";
22
chalk.level = 3;
3-
import { RuntimeLang } from "./languages";
3+
import { RuntimeLang } from "@my-code/runtime/languages";
44

55
export async function importPrism() {
66
if (typeof window !== "undefined") {

0 commit comments

Comments
 (0)