Skip to content
Snippets Groups Projects
Commit 7544f46c authored by yisding's avatar yisding
Browse files

prettier

parent 3e488cb9
No related branches found
No related tags found
No related merge requests found
Showing with 91 additions and 91 deletions
......@@ -79,10 +79,10 @@ const program = new Commander.Command(packageJson.name)
const packageManager = !!program.useNpm
? "npm"
: !!program.usePnpm
? "pnpm"
: !!program.useYarn
? "yarn"
: getPkgManager();
? "pnpm"
: !!program.useYarn
? "yarn"
: getPkgManager();
async function run(): Promise<void> {
const conf = new Conf({ projectName: "create-llama" });
......@@ -235,8 +235,8 @@ async function run(): Promise<void> {
program.framework === "express"
? "Express "
: program.framework === "fastapi"
? "FastAPI (Python) "
: "",
? "FastAPI (Python) "
: "",
);
const { frontend } = await prompts({
onState: onPromptState,
......@@ -364,8 +364,8 @@ async function notifyUpdate(): Promise<void> {
packageManager === "yarn"
? "yarn global add create-llama@latest"
: packageManager === "pnpm"
? "pnpm add -g create-llama@latest"
: "npm i -g create-llama@latest";
? "pnpm add -g create-llama@latest"
: "npm i -g create-llama@latest";
console.log(
yellow(bold("A new version of `create-llama` is available!")) +
......
"use client"
"use client";
import React, { FC, memo } from "react"
import { Check, Copy, Download } from "lucide-react"
import { Prism, SyntaxHighlighterProps } from "react-syntax-highlighter"
import { coldarkDark } from "react-syntax-highlighter/dist/cjs/styles/prism"
import { Check, Copy, Download } from "lucide-react";
import { FC, memo } from "react";
import { Prism, SyntaxHighlighterProps } from "react-syntax-highlighter";
import { coldarkDark } from "react-syntax-highlighter/dist/cjs/styles/prism";
import { Button } from "../button"
import { useCopyToClipboard } from "./use-copy-to-clipboard"
import { Button } from "../button";
import { useCopyToClipboard } from "./use-copy-to-clipboard";
// TODO: Remove this when @type/react-syntax-highlighter is updated
const SyntaxHighlighter = Prism as unknown as FC<SyntaxHighlighterProps>
const SyntaxHighlighter = Prism as unknown as FC<SyntaxHighlighterProps>;
interface Props {
language: string
value: string
language: string;
value: string;
}
interface languageMap {
[key: string]: string | undefined
[key: string]: string | undefined;
}
export const programmingLanguages: languageMap = {
......@@ -45,52 +45,52 @@ export const programmingLanguages: languageMap = {
html: ".html",
css: ".css",
// add more file extensions here, make sure the key is same as language prop in CodeBlock.tsx component
}
};
export const generateRandomString = (length: number, lowercase = false) => {
const chars = "ABCDEFGHJKLMNPQRSTUVWXY3456789" // excluding similar looking characters like Z, 2, I, 1, O, 0
let result = ""
const chars = "ABCDEFGHJKLMNPQRSTUVWXY3456789"; // excluding similar looking characters like Z, 2, I, 1, O, 0
let result = "";
for (let i = 0; i < length; i++) {
result += chars.charAt(Math.floor(Math.random() * chars.length))
result += chars.charAt(Math.floor(Math.random() * chars.length));
}
return lowercase ? result.toLowerCase() : result
}
return lowercase ? result.toLowerCase() : result;
};
const CodeBlock: FC<Props> = memo(({ language, value }) => {
const { isCopied, copyToClipboard } = useCopyToClipboard({ timeout: 2000 })
const { isCopied, copyToClipboard } = useCopyToClipboard({ timeout: 2000 });
const downloadAsFile = () => {
if (typeof window === "undefined") {
return
return;
}
const fileExtension = programmingLanguages[language] || ".file"
const fileExtension = programmingLanguages[language] || ".file";
const suggestedFileName = `file-${generateRandomString(
3,
true
)}${fileExtension}`
const fileName = window.prompt("Enter file name" || "", suggestedFileName)
true,
)}${fileExtension}`;
const fileName = window.prompt("Enter file name" || "", suggestedFileName);
if (!fileName) {
// User pressed cancel on prompt.
return
return;
}
const blob = new Blob([value], { type: "text/plain" })
const url = URL.createObjectURL(blob)
const link = document.createElement("a")
link.download = fileName
link.href = url
link.style.display = "none"
document.body.appendChild(link)
link.click()
document.body.removeChild(link)
URL.revokeObjectURL(url)
}
const blob = new Blob([value], { type: "text/plain" });
const url = URL.createObjectURL(blob);
const link = document.createElement("a");
link.download = fileName;
link.href = url;
link.style.display = "none";
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
URL.revokeObjectURL(url);
};
const onCopy = () => {
if (isCopied) return
copyToClipboard(value)
}
if (isCopied) return;
copyToClipboard(value);
};
return (
<div className="codeblock relative w-full bg-zinc-950 font-sans">
......@@ -132,8 +132,8 @@ const CodeBlock: FC<Props> = memo(({ language, value }) => {
{value}
</SyntaxHighlighter>
</div>
)
})
CodeBlock.displayName = "CodeBlock"
);
});
CodeBlock.displayName = "CodeBlock";
export { CodeBlock }
export { CodeBlock };
......@@ -2,4 +2,4 @@ import ChatInput from "./chat-input";
import ChatMessages from "./chat-messages";
export { type ChatHandler, type Message } from "./chat.interface";
export { ChatMessages, ChatInput };
export { ChatInput, ChatMessages };
import { FC, memo } from "react"
import ReactMarkdown, { Options } from "react-markdown"
import remarkGfm from "remark-gfm"
import remarkMath from "remark-math"
import { FC, memo } from "react";
import ReactMarkdown, { Options } from "react-markdown";
import remarkGfm from "remark-gfm";
import remarkMath from "remark-math";
import { CodeBlock } from "./codeblock"
import { CodeBlock } from "./codeblock";
const MemoizedReactMarkdown: FC<Options> = memo(
ReactMarkdown,
(prevProps, nextProps) =>
prevProps.children === nextProps.children &&
prevProps.className === nextProps.className
)
prevProps.className === nextProps.className,
);
export default function Markdown({ content }: { content: string }) {
return (
......@@ -19,27 +19,27 @@ export default function Markdown({ content }: { content: string }) {
remarkPlugins={[remarkGfm, remarkMath]}
components={{
p({ children }) {
return <p className="mb-2 last:mb-0">{children}</p>
return <p className="mb-2 last:mb-0">{children}</p>;
},
code({ node, inline, className, children, ...props }) {
if (children.length) {
if (children[0] == "") {
return (
<span className="mt-1 animate-pulse cursor-default"></span>
)
);
}
children[0] = (children[0] as string).replace("`▍`", "")
children[0] = (children[0] as string).replace("`▍`", "");
}
const match = /language-(\w+)/.exec(className || "")
const match = /language-(\w+)/.exec(className || "");
if (inline) {
return (
<code className={className} {...props}>
{children}
</code>
)
);
}
return (
......@@ -49,11 +49,11 @@ export default function Markdown({ content }: { content: string }) {
value={String(children).replace(/\n$/, "")}
{...props}
/>
)
);
},
}}
>
{content}
</MemoizedReactMarkdown>
)
);
}
'use client'
"use client";
import * as React from 'react'
import * as React from "react";
export interface useCopyToClipboardProps {
timeout?: number
timeout?: number;
}
export function useCopyToClipboard({
timeout = 2000
timeout = 2000,
}: useCopyToClipboardProps) {
const [isCopied, setIsCopied] = React.useState<Boolean>(false)
const [isCopied, setIsCopied] = React.useState<Boolean>(false);
const copyToClipboard = (value: string) => {
if (typeof window === 'undefined' || !navigator.clipboard?.writeText) {
return
if (typeof window === "undefined" || !navigator.clipboard?.writeText) {
return;
}
if (!value) {
return
return;
}
navigator.clipboard.writeText(value).then(() => {
setIsCopied(true)
setIsCopied(true);
setTimeout(() => {
setIsCopied(false)
}, timeout)
})
}
setIsCopied(false);
}, timeout);
});
};
return { isCopied, copyToClipboard }
return { isCopied, copyToClipboard };
}
......@@ -3,4 +3,4 @@ import ChatMessages from "./chat-messages";
export type { ChatInputProps } from "./chat-input";
export type { Message } from "./chat-messages";
export { ChatMessages, ChatInput };
export { ChatInput, ChatMessages };
/** @type {import('next').NextConfig} */
const nextConfig = {
experimental: {
serverComponentsExternalPackages: ["llamaindex"],
},
}
serverComponentsExternalPackages: ["llamaindex"],
},
};
module.exports = nextConfig
module.exports = nextConfig;
......@@ -3,4 +3,4 @@ module.exports = {
tailwindcss: {},
autoprefixer: {},
},
}
};
......@@ -3,4 +3,4 @@ import ChatMessages from "./chat-messages";
export type { ChatInputProps } from "./chat-input";
export type { Message } from "./chat-messages";
export { ChatMessages, ChatInput };
export { ChatInput, ChatMessages };
/** @type {import('next').NextConfig} */
const nextConfig = {
experimental: {
serverComponentsExternalPackages: ["llamaindex"],
},
}
serverComponentsExternalPackages: ["llamaindex"],
},
};
module.exports = nextConfig
module.exports = nextConfig;
......@@ -3,4 +3,4 @@ module.exports = {
tailwindcss: {},
autoprefixer: {},
},
}
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment