mirror of
https://github.com/momo5502/emulator.git
synced 2026-01-11 16:46:16 +00:00
Format code
This commit is contained in:
3
.github/workflows/build.yml
vendored
3
.github/workflows/build.yml
vendored
@@ -67,6 +67,9 @@ jobs:
|
||||
with:
|
||||
clang-format-version: '20'
|
||||
check-path: 'src'
|
||||
|
||||
- name: Verify Page Formatting
|
||||
run: cd page && npx --yes prettier . --check
|
||||
|
||||
build-apiset-dumper:
|
||||
name: Build API Set Dumper
|
||||
|
||||
2
page/.prettierignore
Normal file
2
page/.prettierignore
Normal file
@@ -0,0 +1,2 @@
|
||||
# Ignore artifacts:
|
||||
dist
|
||||
1
page/.prettierrc
Normal file
1
page/.prettierrc
Normal file
@@ -0,0 +1 @@
|
||||
{}
|
||||
@@ -18,4 +18,4 @@
|
||||
"hooks": "@/hooks"
|
||||
},
|
||||
"iconLibrary": "lucide"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,28 +1,28 @@
|
||||
import js from '@eslint/js'
|
||||
import globals from 'globals'
|
||||
import reactHooks from 'eslint-plugin-react-hooks'
|
||||
import reactRefresh from 'eslint-plugin-react-refresh'
|
||||
import tseslint from 'typescript-eslint'
|
||||
import js from "@eslint/js";
|
||||
import globals from "globals";
|
||||
import reactHooks from "eslint-plugin-react-hooks";
|
||||
import reactRefresh from "eslint-plugin-react-refresh";
|
||||
import tseslint from "typescript-eslint";
|
||||
|
||||
export default tseslint.config(
|
||||
{ ignores: ['dist'] },
|
||||
{ ignores: ["dist"] },
|
||||
{
|
||||
extends: [js.configs.recommended, ...tseslint.configs.recommended],
|
||||
files: ['**/*.{ts,tsx}'],
|
||||
files: ["**/*.{ts,tsx}"],
|
||||
languageOptions: {
|
||||
ecmaVersion: 2020,
|
||||
globals: globals.browser,
|
||||
},
|
||||
plugins: {
|
||||
'react-hooks': reactHooks,
|
||||
'react-refresh': reactRefresh,
|
||||
"react-hooks": reactHooks,
|
||||
"react-refresh": reactRefresh,
|
||||
},
|
||||
rules: {
|
||||
...reactHooks.configs.recommended.rules,
|
||||
'react-refresh/only-export-components': [
|
||||
'warn',
|
||||
"react-refresh/only-export-components": [
|
||||
"warn",
|
||||
{ allowConstantExport: true },
|
||||
],
|
||||
},
|
||||
},
|
||||
)
|
||||
);
|
||||
|
||||
@@ -3,22 +3,58 @@
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<meta name="author" content="Maurice Heumann">
|
||||
<link rel="icon" type="image/png" href="https://momo5502.com/emulator/pinata.png" />
|
||||
<meta name="author" content="Maurice Heumann" />
|
||||
<link
|
||||
rel="icon"
|
||||
type="image/png"
|
||||
href="https://momo5502.com/emulator/pinata.png"
|
||||
/>
|
||||
|
||||
<title>Sogen - Windows User Space Emulator</title>
|
||||
|
||||
<meta name="description" content="Sogen is a high-performance Windows user space emulator operating at syscall level that can emulate windows processes. It is ideal for security-, DRM- or malware research." data-react-helmet="true" />
|
||||
<meta property="og:site_name" content="Sogen - Windows User Space Emulator" data-react-helmet="true" />
|
||||
<meta property="og:title" content="Sogen - Windows User Space Emulator" data-react-helmet="true" />
|
||||
<meta property="og:description" content="Sogen is a high-performance Windows user space emulator operating at syscall level that can emulate windows processes. It is ideal for security-, DRM- or malware research." data-react-helmet="true" />
|
||||
<meta
|
||||
name="description"
|
||||
content="Sogen is a high-performance Windows user space emulator operating at syscall level that can emulate windows processes. It is ideal for security-, DRM- or malware research."
|
||||
data-react-helmet="true"
|
||||
/>
|
||||
<meta
|
||||
property="og:site_name"
|
||||
content="Sogen - Windows User Space Emulator"
|
||||
data-react-helmet="true"
|
||||
/>
|
||||
<meta
|
||||
property="og:title"
|
||||
content="Sogen - Windows User Space Emulator"
|
||||
data-react-helmet="true"
|
||||
/>
|
||||
<meta
|
||||
property="og:description"
|
||||
content="Sogen is a high-performance Windows user space emulator operating at syscall level that can emulate windows processes. It is ideal for security-, DRM- or malware research."
|
||||
data-react-helmet="true"
|
||||
/>
|
||||
<meta property="og:locale" content="en-us" data-react-helmet="true" />
|
||||
<meta property="og:type" content="website" data-react-helmet="true" />
|
||||
<meta name="og:image" content="https://repository-images.githubusercontent.com/842883987/9e56f43b-4afd-464d-85b9-d7e555751a39" data-react-helmet="true" />
|
||||
<meta
|
||||
name="og:image"
|
||||
content="https://repository-images.githubusercontent.com/842883987/9e56f43b-4afd-464d-85b9-d7e555751a39"
|
||||
data-react-helmet="true"
|
||||
/>
|
||||
<meta name="twitter:card" content="summary" data-react-helmet="true" />
|
||||
<meta name="twitter:title" content="Sogen - Windows User Space Emulator" data-react-helmet="true" />
|
||||
<meta name="twitter:description" content="Sogen is a high-performance Windows user space emulator operating at syscall level that can emulate windows processes. It is ideal for security-, DRM- or malware research." data-react-helmet="true" />
|
||||
<meta name="twitter:image" content="https://repository-images.githubusercontent.com/842883987/9e56f43b-4afd-464d-85b9-d7e555751a39" data-react-helmet="true" />
|
||||
<meta
|
||||
name="twitter:title"
|
||||
content="Sogen - Windows User Space Emulator"
|
||||
data-react-helmet="true"
|
||||
/>
|
||||
<meta
|
||||
name="twitter:description"
|
||||
content="Sogen is a high-performance Windows user space emulator operating at syscall level that can emulate windows processes. It is ideal for security-, DRM- or malware research."
|
||||
data-react-helmet="true"
|
||||
/>
|
||||
<meta
|
||||
name="twitter:image"
|
||||
content="https://repository-images.githubusercontent.com/842883987/9e56f43b-4afd-464d-85b9-d7e555751a39"
|
||||
data-react-helmet="true"
|
||||
/>
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
|
||||
17
page/package-lock.json
generated
17
page/package-lock.json
generated
@@ -44,6 +44,7 @@
|
||||
"eslint-plugin-react-hooks": "^6.0.0",
|
||||
"eslint-plugin-react-refresh": "^0.4.20",
|
||||
"globals": "^16.0.0",
|
||||
"prettier": "3.5.3",
|
||||
"typescript": "~5.8.3",
|
||||
"typescript-eslint": "^8.31.0",
|
||||
"vite": "^6.3.1"
|
||||
@@ -4424,6 +4425,22 @@
|
||||
"node": ">= 0.8.0"
|
||||
}
|
||||
},
|
||||
"node_modules/prettier": {
|
||||
"version": "3.5.3",
|
||||
"resolved": "https://registry.npmjs.org/prettier/-/prettier-3.5.3.tgz",
|
||||
"integrity": "sha512-QQtaxnoDJeAkDvDKWCLiwIXkTgRhwYDEQCghU9Z6q03iyek/rxRh/2lC3HB7P8sWT2xC/y5JDctPLBIGzHKbhw==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"bin": {
|
||||
"prettier": "bin/prettier.cjs"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=14"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/prettier/prettier?sponsor=1"
|
||||
}
|
||||
},
|
||||
"node_modules/process-nextick-args": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz",
|
||||
|
||||
@@ -46,6 +46,7 @@
|
||||
"eslint-plugin-react-hooks": "^6.0.0",
|
||||
"eslint-plugin-react-refresh": "^0.4.20",
|
||||
"globals": "^16.0.0",
|
||||
"prettier": "3.5.3",
|
||||
"typescript": "~5.8.3",
|
||||
"typescript-eslint": "^8.31.0",
|
||||
"vite": "^6.3.1"
|
||||
|
||||
@@ -1,57 +1,57 @@
|
||||
var logLines = [];
|
||||
var lastFlush = new Date().getTime();
|
||||
|
||||
onmessage = async (event) => {
|
||||
const data = event.data;
|
||||
if (data.message == "run") {
|
||||
const payload = data.data;
|
||||
runEmulation(payload.filesystem, payload.file, payload.options);
|
||||
}
|
||||
};
|
||||
|
||||
function flushLines() {
|
||||
const lines = logLines;
|
||||
logLines = [];
|
||||
lastFlush = new Date().getTime();
|
||||
postMessage({ message: "log", data: lines });
|
||||
}
|
||||
|
||||
function logLine(text) {
|
||||
logLines.push(text);
|
||||
|
||||
const now = new Date().getTime();
|
||||
|
||||
if(lastFlush + 15 < now) {
|
||||
flushLines();
|
||||
}
|
||||
}
|
||||
|
||||
function runEmulation(filesystem, file, options) {
|
||||
globalThis.Module = {
|
||||
arguments: [...options, "-e", "./root", file],
|
||||
onRuntimeInitialized: function () {
|
||||
filesystem.forEach(e => {
|
||||
if (e.name.endsWith("/")) {
|
||||
FS.mkdir(e.name.slice(0, -1));
|
||||
} else {
|
||||
const dirs = e.name.split("/")
|
||||
const file = dirs.pop();
|
||||
const buffer = new Uint8Array(e.data);
|
||||
if (FS.analyzePath(e.name).exists) {
|
||||
FS.unlink(e.name);
|
||||
}
|
||||
FS.createDataFile("/" + dirs.join('/'), file, buffer, true, true);
|
||||
}
|
||||
})
|
||||
},
|
||||
print: logLine,
|
||||
printErr: logLine,
|
||||
postRun: () => {
|
||||
flushLines();
|
||||
postMessage({ message: "end", data: null });
|
||||
self.close();
|
||||
},
|
||||
};
|
||||
|
||||
importScripts('./analyzer.js?1');
|
||||
}
|
||||
var logLines = [];
|
||||
var lastFlush = new Date().getTime();
|
||||
|
||||
onmessage = async (event) => {
|
||||
const data = event.data;
|
||||
if (data.message == "run") {
|
||||
const payload = data.data;
|
||||
runEmulation(payload.filesystem, payload.file, payload.options);
|
||||
}
|
||||
};
|
||||
|
||||
function flushLines() {
|
||||
const lines = logLines;
|
||||
logLines = [];
|
||||
lastFlush = new Date().getTime();
|
||||
postMessage({ message: "log", data: lines });
|
||||
}
|
||||
|
||||
function logLine(text) {
|
||||
logLines.push(text);
|
||||
|
||||
const now = new Date().getTime();
|
||||
|
||||
if (lastFlush + 15 < now) {
|
||||
flushLines();
|
||||
}
|
||||
}
|
||||
|
||||
function runEmulation(filesystem, file, options) {
|
||||
globalThis.Module = {
|
||||
arguments: [...options, "-e", "./root", file],
|
||||
onRuntimeInitialized: function () {
|
||||
filesystem.forEach((e) => {
|
||||
if (e.name.endsWith("/")) {
|
||||
FS.mkdir(e.name.slice(0, -1));
|
||||
} else {
|
||||
const dirs = e.name.split("/");
|
||||
const file = dirs.pop();
|
||||
const buffer = new Uint8Array(e.data);
|
||||
if (FS.analyzePath(e.name).exists) {
|
||||
FS.unlink(e.name);
|
||||
}
|
||||
FS.createDataFile("/" + dirs.join("/"), file, buffer, true, true);
|
||||
}
|
||||
});
|
||||
},
|
||||
print: logLine,
|
||||
printErr: logLine,
|
||||
postRun: () => {
|
||||
flushLines();
|
||||
postMessage({ message: "end", data: null });
|
||||
self.close();
|
||||
},
|
||||
};
|
||||
|
||||
importScripts("./analyzer.js?1");
|
||||
}
|
||||
|
||||
140
page/src/App.css
140
page/src/App.css
@@ -1,70 +1,70 @@
|
||||
@media (pointer:fine) {
|
||||
::-webkit-scrollbar {
|
||||
width: 20px;
|
||||
}
|
||||
|
||||
::-webkit-scrollbar-track {
|
||||
background-color: transparent;
|
||||
}
|
||||
|
||||
::-webkit-scrollbar-thumb {
|
||||
background-color: rgba(97, 97, 97, 0.7);
|
||||
border-radius: 20px;
|
||||
min-height: 50px;
|
||||
border: 6px solid transparent;
|
||||
background-clip: content-box;
|
||||
transition: all 0.1s linear;
|
||||
}
|
||||
|
||||
::-webkit-scrollbar-thumb:hover {
|
||||
background-color: rgba(97, 97, 97, 0.9);
|
||||
}
|
||||
}
|
||||
|
||||
button {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.terminal-output {
|
||||
line-height: 1.5;
|
||||
font-weight: 600;
|
||||
font-size: 1.05em;
|
||||
font-family: monospace;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.terminal-black {
|
||||
color: #0C0C0C;
|
||||
}
|
||||
|
||||
.terminal-red {
|
||||
color: #FF3131;
|
||||
}
|
||||
|
||||
.terminal-green {
|
||||
color: #86C000;
|
||||
}
|
||||
|
||||
.terminal-yellow {
|
||||
color: #FFB940;
|
||||
}
|
||||
|
||||
.terminal-blue {
|
||||
color: #3A96DD;
|
||||
}
|
||||
|
||||
.terminal-cyan {
|
||||
color: #00ADF7;
|
||||
}
|
||||
|
||||
.terminal-pink {
|
||||
color: #9750DD;
|
||||
}
|
||||
|
||||
.terminal-white {
|
||||
color: #ECECEC;
|
||||
}
|
||||
|
||||
.terminal-dark-gray {
|
||||
color: rgb(81, 81, 81);
|
||||
}
|
||||
@media (pointer: fine) {
|
||||
::-webkit-scrollbar {
|
||||
width: 20px;
|
||||
}
|
||||
|
||||
::-webkit-scrollbar-track {
|
||||
background-color: transparent;
|
||||
}
|
||||
|
||||
::-webkit-scrollbar-thumb {
|
||||
background-color: rgba(97, 97, 97, 0.7);
|
||||
border-radius: 20px;
|
||||
min-height: 50px;
|
||||
border: 6px solid transparent;
|
||||
background-clip: content-box;
|
||||
transition: all 0.1s linear;
|
||||
}
|
||||
|
||||
::-webkit-scrollbar-thumb:hover {
|
||||
background-color: rgba(97, 97, 97, 0.9);
|
||||
}
|
||||
}
|
||||
|
||||
button {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.terminal-output {
|
||||
line-height: 1.5;
|
||||
font-weight: 600;
|
||||
font-size: 1.05em;
|
||||
font-family: monospace;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.terminal-black {
|
||||
color: #0c0c0c;
|
||||
}
|
||||
|
||||
.terminal-red {
|
||||
color: #ff3131;
|
||||
}
|
||||
|
||||
.terminal-green {
|
||||
color: #86c000;
|
||||
}
|
||||
|
||||
.terminal-yellow {
|
||||
color: #ffb940;
|
||||
}
|
||||
|
||||
.terminal-blue {
|
||||
color: #3a96dd;
|
||||
}
|
||||
|
||||
.terminal-cyan {
|
||||
color: #00adf7;
|
||||
}
|
||||
|
||||
.terminal-pink {
|
||||
color: #9750dd;
|
||||
}
|
||||
|
||||
.terminal-white {
|
||||
color: #ececec;
|
||||
}
|
||||
|
||||
.terminal-dark-gray {
|
||||
color: rgb(81, 81, 81);
|
||||
}
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
import { Helmet } from 'react-helmet';
|
||||
import { Helmet } from "react-helmet";
|
||||
|
||||
export interface HeaderProps {
|
||||
title: string;
|
||||
description: string;
|
||||
}
|
||||
|
||||
const image = "https://repository-images.githubusercontent.com/842883987/9e56f43b-4afd-464d-85b9-d7e555751a39";
|
||||
const image =
|
||||
"https://repository-images.githubusercontent.com/842883987/9e56f43b-4afd-464d-85b9-d7e555751a39";
|
||||
|
||||
export function Header(props: HeaderProps) {
|
||||
return (
|
||||
|
||||
@@ -97,7 +97,10 @@ export function Playground() {
|
||||
|
||||
return (
|
||||
<>
|
||||
<Header title="Playground - Sogen" description="Playground to test and run Sogen, the Windows user space emulator, right in your browser." />
|
||||
<Header
|
||||
title="Playground - Sogen"
|
||||
description="Playground to test and run Sogen, the Windows user space emulator, right in your browser."
|
||||
/>
|
||||
<SidebarProvider defaultOpen={false}>
|
||||
<AppSidebar />
|
||||
<SidebarInset className="h-[100dvh]">
|
||||
|
||||
@@ -1,53 +1,51 @@
|
||||
import * as React from "react"
|
||||
|
||||
import {
|
||||
Sidebar,
|
||||
SidebarContent,
|
||||
SidebarGroup,
|
||||
SidebarGroupLabel,
|
||||
SidebarHeader,
|
||||
/*SidebarMenu,
|
||||
SidebarGroupContent,
|
||||
SidebarMenuButton,
|
||||
SidebarMenuItem,*/
|
||||
SidebarRail,
|
||||
} from "@/components/ui/sidebar"
|
||||
|
||||
// This is sample data.
|
||||
const data = {
|
||||
navMain: [
|
||||
{
|
||||
title: "TODO",
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
export function AppSidebar({ ...props }: React.ComponentProps<typeof Sidebar>) {
|
||||
return (
|
||||
<Sidebar {...props}>
|
||||
<SidebarHeader>
|
||||
Filesystem
|
||||
</SidebarHeader>
|
||||
<SidebarContent>
|
||||
{/* We create a SidebarGroup for each parent. */}
|
||||
{data.navMain.map((item) => (
|
||||
<SidebarGroup key={item.title}>
|
||||
<SidebarGroupLabel>{item.title}</SidebarGroupLabel>
|
||||
{/*<SidebarGroupContent>
|
||||
<SidebarMenu>
|
||||
{item.items.map((item) => (
|
||||
<SidebarMenuItem key={item.title}>
|
||||
<SidebarMenuButton asChild isActive={item.isActive}>
|
||||
<a href={item.url}>{item.title}</a>
|
||||
</SidebarMenuButton>
|
||||
</SidebarMenuItem>
|
||||
))}
|
||||
</SidebarMenu>
|
||||
</SidebarGroupContent>*/}
|
||||
</SidebarGroup>
|
||||
))}
|
||||
</SidebarContent>
|
||||
<SidebarRail />
|
||||
</Sidebar>
|
||||
)
|
||||
}
|
||||
import * as React from "react";
|
||||
|
||||
import {
|
||||
Sidebar,
|
||||
SidebarContent,
|
||||
SidebarGroup,
|
||||
SidebarGroupLabel,
|
||||
SidebarHeader,
|
||||
/*SidebarMenu,
|
||||
SidebarGroupContent,
|
||||
SidebarMenuButton,
|
||||
SidebarMenuItem,*/
|
||||
SidebarRail,
|
||||
} from "@/components/ui/sidebar";
|
||||
|
||||
// This is sample data.
|
||||
const data = {
|
||||
navMain: [
|
||||
{
|
||||
title: "TODO",
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
export function AppSidebar({ ...props }: React.ComponentProps<typeof Sidebar>) {
|
||||
return (
|
||||
<Sidebar {...props}>
|
||||
<SidebarHeader>Filesystem</SidebarHeader>
|
||||
<SidebarContent>
|
||||
{/* We create a SidebarGroup for each parent. */}
|
||||
{data.navMain.map((item) => (
|
||||
<SidebarGroup key={item.title}>
|
||||
<SidebarGroupLabel>{item.title}</SidebarGroupLabel>
|
||||
{/*<SidebarGroupContent>
|
||||
<SidebarMenu>
|
||||
{item.items.map((item) => (
|
||||
<SidebarMenuItem key={item.title}>
|
||||
<SidebarMenuButton asChild isActive={item.isActive}>
|
||||
<a href={item.url}>{item.title}</a>
|
||||
</SidebarMenuButton>
|
||||
</SidebarMenuItem>
|
||||
))}
|
||||
</SidebarMenu>
|
||||
</SidebarGroupContent>*/}
|
||||
</SidebarGroup>
|
||||
))}
|
||||
</SidebarContent>
|
||||
<SidebarRail />
|
||||
</Sidebar>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,244 +1,255 @@
|
||||
import React from 'react';
|
||||
import { FixedSizeList as List } from 'react-window';
|
||||
|
||||
interface OutputProps { }
|
||||
|
||||
interface ColorState {
|
||||
color: string;
|
||||
}
|
||||
|
||||
interface OutputState extends ColorState {
|
||||
lines: LogLine[];
|
||||
}
|
||||
|
||||
interface FullOutputState extends OutputState {
|
||||
grouper: OutputGrouper;
|
||||
height: number,
|
||||
width: number,
|
||||
}
|
||||
|
||||
interface LogLine {
|
||||
text: string;
|
||||
classNames: string;
|
||||
};
|
||||
|
||||
function removeSubstringFromStart(str: string, substring: string): string {
|
||||
if (str.startsWith(substring)) {
|
||||
return str.slice(substring.length);
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
function removeSubstringFromEnd(str: string, substring: string): string {
|
||||
if (str.endsWith(substring)) {
|
||||
return str.slice(0, -substring.length);
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
function removeSpanFromStart(str: string, color: string) {
|
||||
const pattern = /^<span class="(terminal-[a-z-]+)">/;
|
||||
const match = str.match(pattern);
|
||||
|
||||
if (match) {
|
||||
const terminalValue = match[1];
|
||||
const cleanedString = str.replace(pattern, '');
|
||||
return [cleanedString, terminalValue];
|
||||
}
|
||||
|
||||
return [str, color];
|
||||
}
|
||||
|
||||
function extractColor(line: string, colorState: ColorState) {
|
||||
while (true) {
|
||||
const newLine = removeSubstringFromStart(line, "</span>");
|
||||
if (newLine == line) {
|
||||
break
|
||||
}
|
||||
|
||||
line = newLine;
|
||||
colorState.color = '';
|
||||
}
|
||||
|
||||
const [nextLine, color] = removeSpanFromStart(line, colorState.color);
|
||||
|
||||
const finalLine = removeSubstringFromEnd(nextLine, "</span>");
|
||||
if (finalLine != nextLine) {
|
||||
colorState.color = '';
|
||||
} else {
|
||||
colorState.color = color;
|
||||
}
|
||||
|
||||
return [finalLine, color];
|
||||
}
|
||||
|
||||
function renderLine(line: string, colorState: ColorState) {
|
||||
const [newLine, color] = extractColor(line, colorState);
|
||||
|
||||
return {
|
||||
text: newLine,
|
||||
classNames: 'whitespace-nowrap block ' + color
|
||||
};
|
||||
}
|
||||
|
||||
function renderLines(lines: string[], color: string): OutputState {
|
||||
var state: ColorState = {
|
||||
color
|
||||
};
|
||||
|
||||
const resultLines = lines.map(line => renderLine(line, state));
|
||||
|
||||
return {
|
||||
lines: resultLines,
|
||||
color: state.color,
|
||||
};
|
||||
}
|
||||
|
||||
function mergeLines(previousState: OutputState, newLines: string[]): OutputState {
|
||||
const result = renderLines(newLines, previousState.color);
|
||||
return { lines: previousState.lines.concat(result.lines), color: result.color };
|
||||
}
|
||||
|
||||
class OutputGrouper {
|
||||
private lines: string[];
|
||||
private flushQueued: boolean;
|
||||
handler: (lines: string[]) => void;
|
||||
|
||||
constructor() {
|
||||
this.lines = [];
|
||||
this.flushQueued = false;
|
||||
this.handler = () => { };
|
||||
}
|
||||
|
||||
clear() {
|
||||
this.lines = [];
|
||||
this.flushQueued = false;
|
||||
}
|
||||
|
||||
flush() {
|
||||
const lines = this.lines;
|
||||
this.lines = [];
|
||||
this.handler(lines);
|
||||
}
|
||||
|
||||
queueFlush() {
|
||||
if (this.flushQueued) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.flushQueued = true;
|
||||
|
||||
requestAnimationFrame(() => {
|
||||
if (!this.flushQueued) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.flushQueued = false;
|
||||
this.flush();
|
||||
});
|
||||
}
|
||||
|
||||
storeLines(lines: string[]) {
|
||||
this.lines = this.lines.concat(lines);
|
||||
this.queueFlush();
|
||||
}
|
||||
}
|
||||
|
||||
export class Output extends React.Component<OutputProps, FullOutputState> {
|
||||
private outputRef: React.RefObject<HTMLDivElement | null>;
|
||||
private listRef: React.RefObject<List | null>;
|
||||
private resizeObserver: ResizeObserver;
|
||||
|
||||
constructor(props: OutputProps) {
|
||||
super(props);
|
||||
|
||||
this.clear = this.clear.bind(this);
|
||||
this.logLine = this.logLine.bind(this);
|
||||
this.logLines = this.logLines.bind(this);
|
||||
this.updateDimensions = this.updateDimensions.bind(this);
|
||||
|
||||
this.outputRef = React.createRef();
|
||||
this.listRef = React.createRef();
|
||||
this.resizeObserver = new ResizeObserver(this.updateDimensions);
|
||||
|
||||
this.state = {
|
||||
lines: [],
|
||||
color: '',
|
||||
grouper: new OutputGrouper(),
|
||||
height: 10,
|
||||
width: 10,
|
||||
};
|
||||
|
||||
this.state.grouper.handler = (lines: string[]) => {
|
||||
this.setState((s) => mergeLines(s, lines));
|
||||
};
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
this.updateDimensions();
|
||||
|
||||
if (this.outputRef.current) {
|
||||
this.resizeObserver.observe(this.outputRef.current);
|
||||
}
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
this.resizeObserver.disconnect();
|
||||
}
|
||||
|
||||
componentDidUpdate(_: OutputProps, prevState: FullOutputState) {
|
||||
if (prevState.lines.length == this.state.lines.length || !this.listRef.current) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.listRef.current.scrollToItem(this.state.lines.length - 1);
|
||||
}
|
||||
|
||||
clear() {
|
||||
this.state.grouper.clear();
|
||||
this.setState({
|
||||
lines: [],
|
||||
color: '',
|
||||
});
|
||||
}
|
||||
|
||||
updateDimensions() {
|
||||
if (!this.outputRef.current) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.setState({
|
||||
width: this.outputRef.current.offsetWidth,
|
||||
height: this.outputRef.current.offsetHeight,
|
||||
});
|
||||
}
|
||||
|
||||
logLines(lines: string[]) {
|
||||
this.state.grouper.storeLines(lines);
|
||||
}
|
||||
|
||||
logLine(line: string) {
|
||||
this.logLines([line]);
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<div className='terminal-output' ref={this.outputRef}>
|
||||
<List ref={this.listRef}
|
||||
width={this.state.width}
|
||||
height={this.state.height}
|
||||
itemCount={this.state.lines.length}
|
||||
itemSize={20}>
|
||||
{({ index, style }) => {
|
||||
const line = this.state.lines[index];
|
||||
return (
|
||||
<span className={line.classNames} style={style}>
|
||||
{line.text}
|
||||
</span>
|
||||
)
|
||||
}}
|
||||
</List>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
import React from "react";
|
||||
import { FixedSizeList as List } from "react-window";
|
||||
|
||||
interface OutputProps {}
|
||||
|
||||
interface ColorState {
|
||||
color: string;
|
||||
}
|
||||
|
||||
interface OutputState extends ColorState {
|
||||
lines: LogLine[];
|
||||
}
|
||||
|
||||
interface FullOutputState extends OutputState {
|
||||
grouper: OutputGrouper;
|
||||
height: number;
|
||||
width: number;
|
||||
}
|
||||
|
||||
interface LogLine {
|
||||
text: string;
|
||||
classNames: string;
|
||||
}
|
||||
|
||||
function removeSubstringFromStart(str: string, substring: string): string {
|
||||
if (str.startsWith(substring)) {
|
||||
return str.slice(substring.length);
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
function removeSubstringFromEnd(str: string, substring: string): string {
|
||||
if (str.endsWith(substring)) {
|
||||
return str.slice(0, -substring.length);
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
function removeSpanFromStart(str: string, color: string) {
|
||||
const pattern = /^<span class="(terminal-[a-z-]+)">/;
|
||||
const match = str.match(pattern);
|
||||
|
||||
if (match) {
|
||||
const terminalValue = match[1];
|
||||
const cleanedString = str.replace(pattern, "");
|
||||
return [cleanedString, terminalValue];
|
||||
}
|
||||
|
||||
return [str, color];
|
||||
}
|
||||
|
||||
function extractColor(line: string, colorState: ColorState) {
|
||||
while (true) {
|
||||
const newLine = removeSubstringFromStart(line, "</span>");
|
||||
if (newLine == line) {
|
||||
break;
|
||||
}
|
||||
|
||||
line = newLine;
|
||||
colorState.color = "";
|
||||
}
|
||||
|
||||
const [nextLine, color] = removeSpanFromStart(line, colorState.color);
|
||||
|
||||
const finalLine = removeSubstringFromEnd(nextLine, "</span>");
|
||||
if (finalLine != nextLine) {
|
||||
colorState.color = "";
|
||||
} else {
|
||||
colorState.color = color;
|
||||
}
|
||||
|
||||
return [finalLine, color];
|
||||
}
|
||||
|
||||
function renderLine(line: string, colorState: ColorState) {
|
||||
const [newLine, color] = extractColor(line, colorState);
|
||||
|
||||
return {
|
||||
text: newLine,
|
||||
classNames: "whitespace-nowrap block " + color,
|
||||
};
|
||||
}
|
||||
|
||||
function renderLines(lines: string[], color: string): OutputState {
|
||||
var state: ColorState = {
|
||||
color,
|
||||
};
|
||||
|
||||
const resultLines = lines.map((line) => renderLine(line, state));
|
||||
|
||||
return {
|
||||
lines: resultLines,
|
||||
color: state.color,
|
||||
};
|
||||
}
|
||||
|
||||
function mergeLines(
|
||||
previousState: OutputState,
|
||||
newLines: string[],
|
||||
): OutputState {
|
||||
const result = renderLines(newLines, previousState.color);
|
||||
return {
|
||||
lines: previousState.lines.concat(result.lines),
|
||||
color: result.color,
|
||||
};
|
||||
}
|
||||
|
||||
class OutputGrouper {
|
||||
private lines: string[];
|
||||
private flushQueued: boolean;
|
||||
handler: (lines: string[]) => void;
|
||||
|
||||
constructor() {
|
||||
this.lines = [];
|
||||
this.flushQueued = false;
|
||||
this.handler = () => {};
|
||||
}
|
||||
|
||||
clear() {
|
||||
this.lines = [];
|
||||
this.flushQueued = false;
|
||||
}
|
||||
|
||||
flush() {
|
||||
const lines = this.lines;
|
||||
this.lines = [];
|
||||
this.handler(lines);
|
||||
}
|
||||
|
||||
queueFlush() {
|
||||
if (this.flushQueued) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.flushQueued = true;
|
||||
|
||||
requestAnimationFrame(() => {
|
||||
if (!this.flushQueued) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.flushQueued = false;
|
||||
this.flush();
|
||||
});
|
||||
}
|
||||
|
||||
storeLines(lines: string[]) {
|
||||
this.lines = this.lines.concat(lines);
|
||||
this.queueFlush();
|
||||
}
|
||||
}
|
||||
|
||||
export class Output extends React.Component<OutputProps, FullOutputState> {
|
||||
private outputRef: React.RefObject<HTMLDivElement | null>;
|
||||
private listRef: React.RefObject<List | null>;
|
||||
private resizeObserver: ResizeObserver;
|
||||
|
||||
constructor(props: OutputProps) {
|
||||
super(props);
|
||||
|
||||
this.clear = this.clear.bind(this);
|
||||
this.logLine = this.logLine.bind(this);
|
||||
this.logLines = this.logLines.bind(this);
|
||||
this.updateDimensions = this.updateDimensions.bind(this);
|
||||
|
||||
this.outputRef = React.createRef();
|
||||
this.listRef = React.createRef();
|
||||
this.resizeObserver = new ResizeObserver(this.updateDimensions);
|
||||
|
||||
this.state = {
|
||||
lines: [],
|
||||
color: "",
|
||||
grouper: new OutputGrouper(),
|
||||
height: 10,
|
||||
width: 10,
|
||||
};
|
||||
|
||||
this.state.grouper.handler = (lines: string[]) => {
|
||||
this.setState((s) => mergeLines(s, lines));
|
||||
};
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
this.updateDimensions();
|
||||
|
||||
if (this.outputRef.current) {
|
||||
this.resizeObserver.observe(this.outputRef.current);
|
||||
}
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
this.resizeObserver.disconnect();
|
||||
}
|
||||
|
||||
componentDidUpdate(_: OutputProps, prevState: FullOutputState) {
|
||||
if (
|
||||
prevState.lines.length == this.state.lines.length ||
|
||||
!this.listRef.current
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.listRef.current.scrollToItem(this.state.lines.length - 1);
|
||||
}
|
||||
|
||||
clear() {
|
||||
this.state.grouper.clear();
|
||||
this.setState({
|
||||
lines: [],
|
||||
color: "",
|
||||
});
|
||||
}
|
||||
|
||||
updateDimensions() {
|
||||
if (!this.outputRef.current) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.setState({
|
||||
width: this.outputRef.current.offsetWidth,
|
||||
height: this.outputRef.current.offsetHeight,
|
||||
});
|
||||
}
|
||||
|
||||
logLines(lines: string[]) {
|
||||
this.state.grouper.storeLines(lines);
|
||||
}
|
||||
|
||||
logLine(line: string) {
|
||||
this.logLines([line]);
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<div className="terminal-output" ref={this.outputRef}>
|
||||
<List
|
||||
ref={this.listRef}
|
||||
width={this.state.width}
|
||||
height={this.state.height}
|
||||
itemCount={this.state.lines.length}
|
||||
itemSize={20}
|
||||
>
|
||||
{({ index, style }) => {
|
||||
const line = this.state.lines[index];
|
||||
return (
|
||||
<span className={line.classNames} style={style}>
|
||||
{line.text}
|
||||
</span>
|
||||
);
|
||||
}}
|
||||
</List>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,72 +1,87 @@
|
||||
import React from "react";
|
||||
import { Checkbox } from "./ui/checkbox";
|
||||
import { Label } from "./ui/label";
|
||||
|
||||
import { Settings } from "@/settings";
|
||||
|
||||
interface SettingsMenuProps {
|
||||
settings: Settings;
|
||||
onChange: (settings: Settings) => void;
|
||||
};
|
||||
|
||||
export class SettingsMenu extends React.Component<SettingsMenuProps, Settings> {
|
||||
|
||||
constructor(props: SettingsMenuProps) {
|
||||
super(props);
|
||||
this.getSettings = this.getSettings.bind(this);
|
||||
this.state = props.settings;
|
||||
}
|
||||
|
||||
getSettings() {
|
||||
return this.state;
|
||||
}
|
||||
|
||||
updateSettings(settings: Settings) {
|
||||
this.setState(() => settings);
|
||||
}
|
||||
|
||||
componentDidUpdate() {
|
||||
this.props.onChange(this.state);
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<div className="grid gap-4">
|
||||
<div className="space-y-2">
|
||||
<h4 className="font-medium leading-none">Settings</h4>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Set the settings for the emulation.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="flex gap-6">
|
||||
<Checkbox id="settings-verbose" checked={this.state.verbose} onCheckedChange={(checked: boolean) => {
|
||||
this.setState({ verbose: checked });
|
||||
}} />
|
||||
<Label htmlFor="settings-verbose">Verbose Logging</Label>
|
||||
</div>
|
||||
|
||||
<div className="flex gap-6">
|
||||
<Checkbox id="settings-concise" checked={this.state.concise} onCheckedChange={(checked: boolean) => {
|
||||
this.setState({ concise: checked });
|
||||
}} />
|
||||
<Label htmlFor="settings-concise">Concise Logging</Label>
|
||||
</div>
|
||||
|
||||
<div className="flex gap-6">
|
||||
<Checkbox id="settings-silent" checked={this.state.silent} onCheckedChange={(checked: boolean) => {
|
||||
this.setState({ silent: checked });
|
||||
}} />
|
||||
<Label htmlFor="settings-silent">Silent Logging</Label>
|
||||
</div>
|
||||
|
||||
<div className="flex gap-6">
|
||||
<Checkbox id="settings-buffer" checked={this.state.bufferStdout} onCheckedChange={(checked: boolean) => {
|
||||
this.setState({ bufferStdout: checked });
|
||||
}} />
|
||||
<Label htmlFor="settings-buffer">Buffer stdout</Label>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
};
|
||||
import React from "react";
|
||||
import { Checkbox } from "./ui/checkbox";
|
||||
import { Label } from "./ui/label";
|
||||
|
||||
import { Settings } from "@/settings";
|
||||
|
||||
interface SettingsMenuProps {
|
||||
settings: Settings;
|
||||
onChange: (settings: Settings) => void;
|
||||
}
|
||||
|
||||
export class SettingsMenu extends React.Component<SettingsMenuProps, Settings> {
|
||||
constructor(props: SettingsMenuProps) {
|
||||
super(props);
|
||||
this.getSettings = this.getSettings.bind(this);
|
||||
this.state = props.settings;
|
||||
}
|
||||
|
||||
getSettings() {
|
||||
return this.state;
|
||||
}
|
||||
|
||||
updateSettings(settings: Settings) {
|
||||
this.setState(() => settings);
|
||||
}
|
||||
|
||||
componentDidUpdate() {
|
||||
this.props.onChange(this.state);
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<div className="grid gap-4">
|
||||
<div className="space-y-2">
|
||||
<h4 className="font-medium leading-none">Settings</h4>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Set the settings for the emulation.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="flex gap-6">
|
||||
<Checkbox
|
||||
id="settings-verbose"
|
||||
checked={this.state.verbose}
|
||||
onCheckedChange={(checked: boolean) => {
|
||||
this.setState({ verbose: checked });
|
||||
}}
|
||||
/>
|
||||
<Label htmlFor="settings-verbose">Verbose Logging</Label>
|
||||
</div>
|
||||
|
||||
<div className="flex gap-6">
|
||||
<Checkbox
|
||||
id="settings-concise"
|
||||
checked={this.state.concise}
|
||||
onCheckedChange={(checked: boolean) => {
|
||||
this.setState({ concise: checked });
|
||||
}}
|
||||
/>
|
||||
<Label htmlFor="settings-concise">Concise Logging</Label>
|
||||
</div>
|
||||
|
||||
<div className="flex gap-6">
|
||||
<Checkbox
|
||||
id="settings-silent"
|
||||
checked={this.state.silent}
|
||||
onCheckedChange={(checked: boolean) => {
|
||||
this.setState({ silent: checked });
|
||||
}}
|
||||
/>
|
||||
<Label htmlFor="settings-silent">Silent Logging</Label>
|
||||
</div>
|
||||
|
||||
<div className="flex gap-6">
|
||||
<Checkbox
|
||||
id="settings-buffer"
|
||||
checked={this.state.bufferStdout}
|
||||
onCheckedChange={(checked: boolean) => {
|
||||
this.setState({ bufferStdout: checked });
|
||||
}}
|
||||
/>
|
||||
<Label htmlFor="settings-buffer">Buffer stdout</Label>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,21 +1,28 @@
|
||||
import { Badge } from '@/components/ui/badge'
|
||||
import { CircleFill } from 'react-bootstrap-icons';
|
||||
|
||||
export interface StatusIndicatorProps {
|
||||
running: boolean;
|
||||
};
|
||||
|
||||
export function StatusIndicator(props: StatusIndicatorProps) {
|
||||
|
||||
const getText = () => {
|
||||
return props.running ? " Running" : " Stopped";
|
||||
};
|
||||
|
||||
const getColor = () => {
|
||||
return props.running ? "bg-lime-600" : "bg-orange-600";
|
||||
}
|
||||
|
||||
return (
|
||||
<Badge variant="outline"><CircleFill className={getColor() + " rounded-full mr-1 n duration-200 ease-in-out"} color='transparent' />{getText()}</Badge>
|
||||
);
|
||||
}
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { CircleFill } from "react-bootstrap-icons";
|
||||
|
||||
export interface StatusIndicatorProps {
|
||||
running: boolean;
|
||||
}
|
||||
|
||||
export function StatusIndicator(props: StatusIndicatorProps) {
|
||||
const getText = () => {
|
||||
return props.running ? " Running" : " Stopped";
|
||||
};
|
||||
|
||||
const getColor = () => {
|
||||
return props.running ? "bg-lime-600" : "bg-orange-600";
|
||||
};
|
||||
|
||||
return (
|
||||
<Badge variant="outline">
|
||||
<CircleFill
|
||||
className={
|
||||
getColor() + " rounded-full mr-1 n duration-200 ease-in-out"
|
||||
}
|
||||
color="transparent"
|
||||
/>
|
||||
{getText()}
|
||||
</Badge>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,73 +1,73 @@
|
||||
import { createContext, useContext, useEffect, useState } from "react"
|
||||
|
||||
type Theme = "dark" | "light" | "system"
|
||||
|
||||
type ThemeProviderProps = {
|
||||
children: React.ReactNode
|
||||
defaultTheme?: Theme
|
||||
storageKey?: string
|
||||
}
|
||||
|
||||
type ThemeProviderState = {
|
||||
theme: Theme
|
||||
setTheme: (theme: Theme) => void
|
||||
}
|
||||
|
||||
const initialState: ThemeProviderState = {
|
||||
theme: "system",
|
||||
setTheme: () => null,
|
||||
}
|
||||
|
||||
const ThemeProviderContext = createContext<ThemeProviderState>(initialState)
|
||||
|
||||
export function ThemeProvider({
|
||||
children,
|
||||
defaultTheme = "system",
|
||||
storageKey = "vite-ui-theme",
|
||||
...props
|
||||
}: ThemeProviderProps) {
|
||||
const [theme, setTheme] = useState<Theme>(
|
||||
() => (localStorage.getItem(storageKey) as Theme) || defaultTheme
|
||||
)
|
||||
|
||||
useEffect(() => {
|
||||
const root = window.document.documentElement
|
||||
|
||||
root.classList.remove("light", "dark")
|
||||
|
||||
if (theme === "system") {
|
||||
const systemTheme = window.matchMedia("(prefers-color-scheme: dark)")
|
||||
.matches
|
||||
? "dark"
|
||||
: "light"
|
||||
|
||||
root.classList.add(systemTheme)
|
||||
return
|
||||
}
|
||||
|
||||
root.classList.add(theme)
|
||||
}, [theme])
|
||||
|
||||
const value = {
|
||||
theme,
|
||||
setTheme: (theme: Theme) => {
|
||||
localStorage.setItem(storageKey, theme)
|
||||
setTheme(theme)
|
||||
},
|
||||
}
|
||||
|
||||
return (
|
||||
<ThemeProviderContext.Provider {...props} value={value}>
|
||||
{children}
|
||||
</ThemeProviderContext.Provider>
|
||||
)
|
||||
}
|
||||
|
||||
export const useTheme = () => {
|
||||
const context = useContext(ThemeProviderContext)
|
||||
|
||||
if (context === undefined)
|
||||
throw new Error("useTheme must be used within a ThemeProvider")
|
||||
|
||||
return context
|
||||
}
|
||||
import { createContext, useContext, useEffect, useState } from "react";
|
||||
|
||||
type Theme = "dark" | "light" | "system";
|
||||
|
||||
type ThemeProviderProps = {
|
||||
children: React.ReactNode;
|
||||
defaultTheme?: Theme;
|
||||
storageKey?: string;
|
||||
};
|
||||
|
||||
type ThemeProviderState = {
|
||||
theme: Theme;
|
||||
setTheme: (theme: Theme) => void;
|
||||
};
|
||||
|
||||
const initialState: ThemeProviderState = {
|
||||
theme: "system",
|
||||
setTheme: () => null,
|
||||
};
|
||||
|
||||
const ThemeProviderContext = createContext<ThemeProviderState>(initialState);
|
||||
|
||||
export function ThemeProvider({
|
||||
children,
|
||||
defaultTheme = "system",
|
||||
storageKey = "vite-ui-theme",
|
||||
...props
|
||||
}: ThemeProviderProps) {
|
||||
const [theme, setTheme] = useState<Theme>(
|
||||
() => (localStorage.getItem(storageKey) as Theme) || defaultTheme,
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
const root = window.document.documentElement;
|
||||
|
||||
root.classList.remove("light", "dark");
|
||||
|
||||
if (theme === "system") {
|
||||
const systemTheme = window.matchMedia("(prefers-color-scheme: dark)")
|
||||
.matches
|
||||
? "dark"
|
||||
: "light";
|
||||
|
||||
root.classList.add(systemTheme);
|
||||
return;
|
||||
}
|
||||
|
||||
root.classList.add(theme);
|
||||
}, [theme]);
|
||||
|
||||
const value = {
|
||||
theme,
|
||||
setTheme: (theme: Theme) => {
|
||||
localStorage.setItem(storageKey, theme);
|
||||
setTheme(theme);
|
||||
},
|
||||
};
|
||||
|
||||
return (
|
||||
<ThemeProviderContext.Provider {...props} value={value}>
|
||||
{children}
|
||||
</ThemeProviderContext.Provider>
|
||||
);
|
||||
}
|
||||
|
||||
export const useTheme = () => {
|
||||
const context = useContext(ThemeProviderContext);
|
||||
|
||||
if (context === undefined)
|
||||
throw new Error("useTheme must be used within a ThemeProvider");
|
||||
|
||||
return context;
|
||||
};
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import * as React from "react"
|
||||
import { Slot } from "@radix-ui/react-slot"
|
||||
import { cva, type VariantProps } from "class-variance-authority"
|
||||
import * as React from "react";
|
||||
import { Slot } from "@radix-ui/react-slot";
|
||||
import { cva, type VariantProps } from "class-variance-authority";
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
const badgeVariants = cva(
|
||||
"inline-flex items-center justify-center rounded-md border px-2 py-0.5 text-xs font-medium w-fit whitespace-nowrap shrink-0 [&>svg]:size-3 gap-1 [&>svg]:pointer-events-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive transition-[color,box-shadow] overflow-hidden",
|
||||
@@ -22,8 +22,8 @@ const badgeVariants = cva(
|
||||
defaultVariants: {
|
||||
variant: "default",
|
||||
},
|
||||
}
|
||||
)
|
||||
},
|
||||
);
|
||||
|
||||
function Badge({
|
||||
className,
|
||||
@@ -32,7 +32,7 @@ function Badge({
|
||||
...props
|
||||
}: React.ComponentProps<"span"> &
|
||||
VariantProps<typeof badgeVariants> & { asChild?: boolean }) {
|
||||
const Comp = asChild ? Slot : "span"
|
||||
const Comp = asChild ? Slot : "span";
|
||||
|
||||
return (
|
||||
<Comp
|
||||
@@ -40,7 +40,7 @@ function Badge({
|
||||
className={cn(badgeVariants({ variant }), className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
export { Badge, badgeVariants }
|
||||
export { Badge, badgeVariants };
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import * as React from "react"
|
||||
import { Slot } from "@radix-ui/react-slot"
|
||||
import { ChevronRight, MoreHorizontal } from "lucide-react"
|
||||
import * as React from "react";
|
||||
import { Slot } from "@radix-ui/react-slot";
|
||||
import { ChevronRight, MoreHorizontal } from "lucide-react";
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
function Breadcrumb({ ...props }: React.ComponentProps<"nav">) {
|
||||
return <nav aria-label="breadcrumb" data-slot="breadcrumb" {...props} />
|
||||
return <nav aria-label="breadcrumb" data-slot="breadcrumb" {...props} />;
|
||||
}
|
||||
|
||||
function BreadcrumbList({ className, ...props }: React.ComponentProps<"ol">) {
|
||||
@@ -14,11 +14,11 @@ function BreadcrumbList({ className, ...props }: React.ComponentProps<"ol">) {
|
||||
data-slot="breadcrumb-list"
|
||||
className={cn(
|
||||
"text-muted-foreground flex flex-wrap items-center gap-1.5 text-sm break-words sm:gap-2.5",
|
||||
className
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function BreadcrumbItem({ className, ...props }: React.ComponentProps<"li">) {
|
||||
@@ -28,7 +28,7 @@ function BreadcrumbItem({ className, ...props }: React.ComponentProps<"li">) {
|
||||
className={cn("inline-flex items-center gap-1.5", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function BreadcrumbLink({
|
||||
@@ -36,9 +36,9 @@ function BreadcrumbLink({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<"a"> & {
|
||||
asChild?: boolean
|
||||
asChild?: boolean;
|
||||
}) {
|
||||
const Comp = asChild ? Slot : "a"
|
||||
const Comp = asChild ? Slot : "a";
|
||||
|
||||
return (
|
||||
<Comp
|
||||
@@ -46,7 +46,7 @@ function BreadcrumbLink({
|
||||
className={cn("hover:text-foreground transition-colors", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function BreadcrumbPage({ className, ...props }: React.ComponentProps<"span">) {
|
||||
@@ -59,7 +59,7 @@ function BreadcrumbPage({ className, ...props }: React.ComponentProps<"span">) {
|
||||
className={cn("text-foreground font-normal", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function BreadcrumbSeparator({
|
||||
@@ -77,7 +77,7 @@ function BreadcrumbSeparator({
|
||||
>
|
||||
{children ?? <ChevronRight />}
|
||||
</li>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function BreadcrumbEllipsis({
|
||||
@@ -95,7 +95,7 @@ function BreadcrumbEllipsis({
|
||||
<MoreHorizontal className="size-4" />
|
||||
<span className="sr-only">More</span>
|
||||
</span>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
export {
|
||||
@@ -106,4 +106,4 @@ export {
|
||||
BreadcrumbPage,
|
||||
BreadcrumbSeparator,
|
||||
BreadcrumbEllipsis,
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import * as React from "react"
|
||||
import { Slot } from "@radix-ui/react-slot"
|
||||
import { cva, type VariantProps } from "class-variance-authority"
|
||||
import * as React from "react";
|
||||
import { Slot } from "@radix-ui/react-slot";
|
||||
import { cva, type VariantProps } from "class-variance-authority";
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
const buttonVariants = cva(
|
||||
"inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-all disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",
|
||||
@@ -32,8 +32,8 @@ const buttonVariants = cva(
|
||||
variant: "default",
|
||||
size: "default",
|
||||
},
|
||||
}
|
||||
)
|
||||
},
|
||||
);
|
||||
|
||||
function Button({
|
||||
className,
|
||||
@@ -43,9 +43,9 @@ function Button({
|
||||
...props
|
||||
}: React.ComponentProps<"button"> &
|
||||
VariantProps<typeof buttonVariants> & {
|
||||
asChild?: boolean
|
||||
asChild?: boolean;
|
||||
}) {
|
||||
const Comp = asChild ? Slot : "button"
|
||||
const Comp = asChild ? Slot : "button";
|
||||
|
||||
return (
|
||||
<Comp
|
||||
@@ -53,7 +53,7 @@ function Button({
|
||||
className={cn(buttonVariants({ variant, size, className }))}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
export { Button, buttonVariants }
|
||||
export { Button, buttonVariants };
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import * as React from "react"
|
||||
import * as React from "react";
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
function Card({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
@@ -8,11 +8,11 @@ function Card({ className, ...props }: React.ComponentProps<"div">) {
|
||||
data-slot="card"
|
||||
className={cn(
|
||||
"bg-card text-card-foreground flex flex-col gap-6 rounded-xl border py-6 shadow-sm",
|
||||
className
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function CardHeader({ className, ...props }: React.ComponentProps<"div">) {
|
||||
@@ -21,11 +21,11 @@ function CardHeader({ className, ...props }: React.ComponentProps<"div">) {
|
||||
data-slot="card-header"
|
||||
className={cn(
|
||||
"@container/card-header grid auto-rows-min grid-rows-[auto_auto] items-start gap-1.5 px-6 has-data-[slot=card-action]:grid-cols-[1fr_auto] [.border-b]:pb-6",
|
||||
className
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function CardTitle({ className, ...props }: React.ComponentProps<"div">) {
|
||||
@@ -35,7 +35,7 @@ function CardTitle({ className, ...props }: React.ComponentProps<"div">) {
|
||||
className={cn("leading-none font-semibold", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function CardDescription({ className, ...props }: React.ComponentProps<"div">) {
|
||||
@@ -45,7 +45,7 @@ function CardDescription({ className, ...props }: React.ComponentProps<"div">) {
|
||||
className={cn("text-muted-foreground text-sm", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function CardAction({ className, ...props }: React.ComponentProps<"div">) {
|
||||
@@ -54,11 +54,11 @@ function CardAction({ className, ...props }: React.ComponentProps<"div">) {
|
||||
data-slot="card-action"
|
||||
className={cn(
|
||||
"col-start-2 row-span-2 row-start-1 self-start justify-self-end",
|
||||
className
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function CardContent({ className, ...props }: React.ComponentProps<"div">) {
|
||||
@@ -68,7 +68,7 @@ function CardContent({ className, ...props }: React.ComponentProps<"div">) {
|
||||
className={cn("px-6", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function CardFooter({ className, ...props }: React.ComponentProps<"div">) {
|
||||
@@ -78,7 +78,7 @@ function CardFooter({ className, ...props }: React.ComponentProps<"div">) {
|
||||
className={cn("flex items-center px-6 [.border-t]:pt-6", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
export {
|
||||
@@ -89,4 +89,4 @@ export {
|
||||
CardAction,
|
||||
CardDescription,
|
||||
CardContent,
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import * as React from "react"
|
||||
import * as CheckboxPrimitive from "@radix-ui/react-checkbox"
|
||||
import { CheckIcon } from "lucide-react"
|
||||
import * as React from "react";
|
||||
import * as CheckboxPrimitive from "@radix-ui/react-checkbox";
|
||||
import { CheckIcon } from "lucide-react";
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
function Checkbox({
|
||||
className,
|
||||
@@ -13,7 +13,7 @@ function Checkbox({
|
||||
data-slot="checkbox"
|
||||
className={cn(
|
||||
"peer border-input dark:bg-input/30 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground dark:data-[state=checked]:bg-primary data-[state=checked]:border-primary focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive size-4 shrink-0 rounded-[4px] border shadow-xs transition-shadow outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50",
|
||||
className
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
@@ -24,7 +24,7 @@ function Checkbox({
|
||||
<CheckIcon className="size-3.5" />
|
||||
</CheckboxPrimitive.Indicator>
|
||||
</CheckboxPrimitive.Root>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
export { Checkbox }
|
||||
export { Checkbox };
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import * as React from "react"
|
||||
import * as React from "react";
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
function Input({ className, type, ...props }: React.ComponentProps<"input">) {
|
||||
return (
|
||||
@@ -11,11 +11,11 @@ function Input({ className, type, ...props }: React.ComponentProps<"input">) {
|
||||
"file:text-foreground placeholder:text-muted-foreground selection:bg-primary selection:text-primary-foreground dark:bg-input/30 border-input flex h-9 w-full min-w-0 rounded-md border bg-transparent px-3 py-1 text-base shadow-xs transition-[color,box-shadow] outline-none file:inline-flex file:h-7 file:border-0 file:bg-transparent file:text-sm file:font-medium disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",
|
||||
"focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px]",
|
||||
"aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",
|
||||
className
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
export { Input }
|
||||
export { Input };
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import * as React from "react"
|
||||
import * as LabelPrimitive from "@radix-ui/react-label"
|
||||
import * as React from "react";
|
||||
import * as LabelPrimitive from "@radix-ui/react-label";
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
function Label({
|
||||
className,
|
||||
@@ -12,11 +12,11 @@ function Label({
|
||||
data-slot="label"
|
||||
className={cn(
|
||||
"flex items-center gap-2 text-sm leading-none font-medium select-none group-data-[disabled=true]:pointer-events-none group-data-[disabled=true]:opacity-50 peer-disabled:cursor-not-allowed peer-disabled:opacity-50",
|
||||
className
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
export { Label }
|
||||
export { Label };
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
import * as React from "react"
|
||||
import * as PopoverPrimitive from "@radix-ui/react-popover"
|
||||
import * as React from "react";
|
||||
import * as PopoverPrimitive from "@radix-ui/react-popover";
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
function Popover({
|
||||
...props
|
||||
}: React.ComponentProps<typeof PopoverPrimitive.Root>) {
|
||||
return <PopoverPrimitive.Root data-slot="popover" {...props} />
|
||||
return <PopoverPrimitive.Root data-slot="popover" {...props} />;
|
||||
}
|
||||
|
||||
function PopoverTrigger({
|
||||
...props
|
||||
}: React.ComponentProps<typeof PopoverPrimitive.Trigger>) {
|
||||
return <PopoverPrimitive.Trigger data-slot="popover-trigger" {...props} />
|
||||
return <PopoverPrimitive.Trigger data-slot="popover-trigger" {...props} />;
|
||||
}
|
||||
|
||||
function PopoverContent({
|
||||
@@ -29,18 +29,18 @@ function PopoverContent({
|
||||
sideOffset={sideOffset}
|
||||
className={cn(
|
||||
"bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 w-72 origin-(--radix-popover-content-transform-origin) rounded-md border p-4 shadow-md outline-hidden",
|
||||
className
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
</PopoverPrimitive.Portal>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function PopoverAnchor({
|
||||
...props
|
||||
}: React.ComponentProps<typeof PopoverPrimitive.Anchor>) {
|
||||
return <PopoverPrimitive.Anchor data-slot="popover-anchor" {...props} />
|
||||
return <PopoverPrimitive.Anchor data-slot="popover-anchor" {...props} />;
|
||||
}
|
||||
|
||||
export { Popover, PopoverTrigger, PopoverContent, PopoverAnchor }
|
||||
export { Popover, PopoverTrigger, PopoverContent, PopoverAnchor };
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import * as React from "react"
|
||||
import * as ScrollAreaPrimitive from "@radix-ui/react-scroll-area"
|
||||
import * as React from "react";
|
||||
import * as ScrollAreaPrimitive from "@radix-ui/react-scroll-area";
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
function ScrollArea({
|
||||
className,
|
||||
@@ -23,7 +23,7 @@ function ScrollArea({
|
||||
<ScrollBar />
|
||||
<ScrollAreaPrimitive.Corner />
|
||||
</ScrollAreaPrimitive.Root>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function ScrollBar({
|
||||
@@ -41,7 +41,7 @@ function ScrollBar({
|
||||
"h-full w-2.5 border-l border-l-transparent",
|
||||
orientation === "horizontal" &&
|
||||
"h-2.5 flex-col border-t border-t-transparent",
|
||||
className
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
@@ -50,7 +50,7 @@ function ScrollBar({
|
||||
className="bg-border relative flex-1 rounded-full"
|
||||
/>
|
||||
</ScrollAreaPrimitive.ScrollAreaScrollbar>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
export { ScrollArea, ScrollBar }
|
||||
export { ScrollArea, ScrollBar };
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
"use client"
|
||||
"use client";
|
||||
|
||||
import * as React from "react"
|
||||
import * as SeparatorPrimitive from "@radix-ui/react-separator"
|
||||
import * as React from "react";
|
||||
import * as SeparatorPrimitive from "@radix-ui/react-separator";
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
function Separator({
|
||||
className,
|
||||
@@ -18,11 +18,11 @@ function Separator({
|
||||
orientation={orientation}
|
||||
className={cn(
|
||||
"bg-border shrink-0 data-[orientation=horizontal]:h-px data-[orientation=horizontal]:w-full data-[orientation=vertical]:h-full data-[orientation=vertical]:w-px",
|
||||
className
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
export { Separator }
|
||||
export { Separator };
|
||||
|
||||
@@ -1,29 +1,29 @@
|
||||
import * as React from "react"
|
||||
import * as SheetPrimitive from "@radix-ui/react-dialog"
|
||||
import { XIcon } from "lucide-react"
|
||||
import * as React from "react";
|
||||
import * as SheetPrimitive from "@radix-ui/react-dialog";
|
||||
import { XIcon } from "lucide-react";
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
function Sheet({ ...props }: React.ComponentProps<typeof SheetPrimitive.Root>) {
|
||||
return <SheetPrimitive.Root data-slot="sheet" {...props} />
|
||||
return <SheetPrimitive.Root data-slot="sheet" {...props} />;
|
||||
}
|
||||
|
||||
function SheetTrigger({
|
||||
...props
|
||||
}: React.ComponentProps<typeof SheetPrimitive.Trigger>) {
|
||||
return <SheetPrimitive.Trigger data-slot="sheet-trigger" {...props} />
|
||||
return <SheetPrimitive.Trigger data-slot="sheet-trigger" {...props} />;
|
||||
}
|
||||
|
||||
function SheetClose({
|
||||
...props
|
||||
}: React.ComponentProps<typeof SheetPrimitive.Close>) {
|
||||
return <SheetPrimitive.Close data-slot="sheet-close" {...props} />
|
||||
return <SheetPrimitive.Close data-slot="sheet-close" {...props} />;
|
||||
}
|
||||
|
||||
function SheetPortal({
|
||||
...props
|
||||
}: React.ComponentProps<typeof SheetPrimitive.Portal>) {
|
||||
return <SheetPrimitive.Portal data-slot="sheet-portal" {...props} />
|
||||
return <SheetPrimitive.Portal data-slot="sheet-portal" {...props} />;
|
||||
}
|
||||
|
||||
function SheetOverlay({
|
||||
@@ -35,11 +35,11 @@ function SheetOverlay({
|
||||
data-slot="sheet-overlay"
|
||||
className={cn(
|
||||
"data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/50",
|
||||
className
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function SheetContent({
|
||||
@@ -48,7 +48,7 @@ function SheetContent({
|
||||
side = "right",
|
||||
...props
|
||||
}: React.ComponentProps<typeof SheetPrimitive.Content> & {
|
||||
side?: "top" | "right" | "bottom" | "left"
|
||||
side?: "top" | "right" | "bottom" | "left";
|
||||
}) {
|
||||
return (
|
||||
<SheetPortal>
|
||||
@@ -65,7 +65,7 @@ function SheetContent({
|
||||
"data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top inset-x-0 top-0 h-auto border-b",
|
||||
side === "bottom" &&
|
||||
"data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom inset-x-0 bottom-0 h-auto border-t",
|
||||
className
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
@@ -76,7 +76,7 @@ function SheetContent({
|
||||
</SheetPrimitive.Close>
|
||||
</SheetPrimitive.Content>
|
||||
</SheetPortal>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function SheetHeader({ className, ...props }: React.ComponentProps<"div">) {
|
||||
@@ -86,7 +86,7 @@ function SheetHeader({ className, ...props }: React.ComponentProps<"div">) {
|
||||
className={cn("flex flex-col gap-1.5 p-4", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function SheetFooter({ className, ...props }: React.ComponentProps<"div">) {
|
||||
@@ -96,7 +96,7 @@ function SheetFooter({ className, ...props }: React.ComponentProps<"div">) {
|
||||
className={cn("mt-auto flex flex-col gap-2 p-4", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function SheetTitle({
|
||||
@@ -109,7 +109,7 @@ function SheetTitle({
|
||||
className={cn("text-foreground font-semibold", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function SheetDescription({
|
||||
@@ -122,7 +122,7 @@ function SheetDescription({
|
||||
className={cn("text-muted-foreground text-sm", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
export {
|
||||
@@ -134,4 +134,4 @@ export {
|
||||
SheetFooter,
|
||||
SheetTitle,
|
||||
SheetDescription,
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,54 +1,54 @@
|
||||
import * as React from "react"
|
||||
import { Slot } from "@radix-ui/react-slot"
|
||||
import { VariantProps, cva } from "class-variance-authority"
|
||||
import { PanelLeftIcon } from "lucide-react"
|
||||
import * as React from "react";
|
||||
import { Slot } from "@radix-ui/react-slot";
|
||||
import { VariantProps, cva } from "class-variance-authority";
|
||||
import { PanelLeftIcon } from "lucide-react";
|
||||
|
||||
import { useIsMobile } from "@/hooks/use-mobile"
|
||||
import { cn } from "@/lib/utils"
|
||||
import { Button } from "@/components/ui/button"
|
||||
import { Input } from "@/components/ui/input"
|
||||
import { Separator } from "@/components/ui/separator"
|
||||
import { useIsMobile } from "@/hooks/use-mobile";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Separator } from "@/components/ui/separator";
|
||||
import {
|
||||
Sheet,
|
||||
SheetContent,
|
||||
SheetDescription,
|
||||
SheetHeader,
|
||||
SheetTitle,
|
||||
} from "@/components/ui/sheet"
|
||||
import { Skeleton } from "@/components/ui/skeleton"
|
||||
} from "@/components/ui/sheet";
|
||||
import { Skeleton } from "@/components/ui/skeleton";
|
||||
import {
|
||||
Tooltip,
|
||||
TooltipContent,
|
||||
TooltipProvider,
|
||||
TooltipTrigger,
|
||||
} from "@/components/ui/tooltip"
|
||||
} from "@/components/ui/tooltip";
|
||||
|
||||
const SIDEBAR_COOKIE_NAME = "sidebar_state"
|
||||
const SIDEBAR_COOKIE_MAX_AGE = 60 * 60 * 24 * 7
|
||||
const SIDEBAR_WIDTH = "16rem"
|
||||
const SIDEBAR_WIDTH_MOBILE = "18rem"
|
||||
const SIDEBAR_WIDTH_ICON = "3rem"
|
||||
const SIDEBAR_KEYBOARD_SHORTCUT = "b"
|
||||
const SIDEBAR_COOKIE_NAME = "sidebar_state";
|
||||
const SIDEBAR_COOKIE_MAX_AGE = 60 * 60 * 24 * 7;
|
||||
const SIDEBAR_WIDTH = "16rem";
|
||||
const SIDEBAR_WIDTH_MOBILE = "18rem";
|
||||
const SIDEBAR_WIDTH_ICON = "3rem";
|
||||
const SIDEBAR_KEYBOARD_SHORTCUT = "b";
|
||||
|
||||
type SidebarContextProps = {
|
||||
state: "expanded" | "collapsed"
|
||||
open: boolean
|
||||
setOpen: (open: boolean) => void
|
||||
openMobile: boolean
|
||||
setOpenMobile: (open: boolean) => void
|
||||
isMobile: boolean
|
||||
toggleSidebar: () => void
|
||||
}
|
||||
state: "expanded" | "collapsed";
|
||||
open: boolean;
|
||||
setOpen: (open: boolean) => void;
|
||||
openMobile: boolean;
|
||||
setOpenMobile: (open: boolean) => void;
|
||||
isMobile: boolean;
|
||||
toggleSidebar: () => void;
|
||||
};
|
||||
|
||||
const SidebarContext = React.createContext<SidebarContextProps | null>(null)
|
||||
const SidebarContext = React.createContext<SidebarContextProps | null>(null);
|
||||
|
||||
function useSidebar() {
|
||||
const context = React.useContext(SidebarContext)
|
||||
const context = React.useContext(SidebarContext);
|
||||
if (!context) {
|
||||
throw new Error("useSidebar must be used within a SidebarProvider.")
|
||||
throw new Error("useSidebar must be used within a SidebarProvider.");
|
||||
}
|
||||
|
||||
return context
|
||||
return context;
|
||||
}
|
||||
|
||||
function SidebarProvider({
|
||||
@@ -60,36 +60,36 @@ function SidebarProvider({
|
||||
children,
|
||||
...props
|
||||
}: React.ComponentProps<"div"> & {
|
||||
defaultOpen?: boolean
|
||||
open?: boolean
|
||||
onOpenChange?: (open: boolean) => void
|
||||
defaultOpen?: boolean;
|
||||
open?: boolean;
|
||||
onOpenChange?: (open: boolean) => void;
|
||||
}) {
|
||||
const isMobile = useIsMobile()
|
||||
const [openMobile, setOpenMobile] = React.useState(false)
|
||||
const isMobile = useIsMobile();
|
||||
const [openMobile, setOpenMobile] = React.useState(false);
|
||||
|
||||
// This is the internal state of the sidebar.
|
||||
// We use openProp and setOpenProp for control from outside the component.
|
||||
const [_open, _setOpen] = React.useState(defaultOpen)
|
||||
const open = openProp ?? _open
|
||||
const [_open, _setOpen] = React.useState(defaultOpen);
|
||||
const open = openProp ?? _open;
|
||||
const setOpen = React.useCallback(
|
||||
(value: boolean | ((value: boolean) => boolean)) => {
|
||||
const openState = typeof value === "function" ? value(open) : value
|
||||
const openState = typeof value === "function" ? value(open) : value;
|
||||
if (setOpenProp) {
|
||||
setOpenProp(openState)
|
||||
setOpenProp(openState);
|
||||
} else {
|
||||
_setOpen(openState)
|
||||
_setOpen(openState);
|
||||
}
|
||||
|
||||
// This sets the cookie to keep the sidebar state.
|
||||
document.cookie = `${SIDEBAR_COOKIE_NAME}=${openState}; path=/; max-age=${SIDEBAR_COOKIE_MAX_AGE}`
|
||||
document.cookie = `${SIDEBAR_COOKIE_NAME}=${openState}; path=/; max-age=${SIDEBAR_COOKIE_MAX_AGE}`;
|
||||
},
|
||||
[setOpenProp, open]
|
||||
)
|
||||
[setOpenProp, open],
|
||||
);
|
||||
|
||||
// Helper to toggle the sidebar.
|
||||
const toggleSidebar = React.useCallback(() => {
|
||||
return isMobile ? setOpenMobile((open) => !open) : setOpen((open) => !open)
|
||||
}, [isMobile, setOpen, setOpenMobile])
|
||||
return isMobile ? setOpenMobile((open) => !open) : setOpen((open) => !open);
|
||||
}, [isMobile, setOpen, setOpenMobile]);
|
||||
|
||||
// Adds a keyboard shortcut to toggle the sidebar.
|
||||
React.useEffect(() => {
|
||||
@@ -98,18 +98,18 @@ function SidebarProvider({
|
||||
event.key === SIDEBAR_KEYBOARD_SHORTCUT &&
|
||||
(event.metaKey || event.ctrlKey)
|
||||
) {
|
||||
event.preventDefault()
|
||||
toggleSidebar()
|
||||
event.preventDefault();
|
||||
toggleSidebar();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
window.addEventListener("keydown", handleKeyDown)
|
||||
return () => window.removeEventListener("keydown", handleKeyDown)
|
||||
}, [toggleSidebar])
|
||||
window.addEventListener("keydown", handleKeyDown);
|
||||
return () => window.removeEventListener("keydown", handleKeyDown);
|
||||
}, [toggleSidebar]);
|
||||
|
||||
// We add a state so that we can do data-state="expanded" or "collapsed".
|
||||
// This makes it easier to style the sidebar with Tailwind classes.
|
||||
const state = open ? "expanded" : "collapsed"
|
||||
const state = open ? "expanded" : "collapsed";
|
||||
|
||||
const contextValue = React.useMemo<SidebarContextProps>(
|
||||
() => ({
|
||||
@@ -121,8 +121,8 @@ function SidebarProvider({
|
||||
setOpenMobile,
|
||||
toggleSidebar,
|
||||
}),
|
||||
[state, open, setOpen, isMobile, openMobile, setOpenMobile, toggleSidebar]
|
||||
)
|
||||
[state, open, setOpen, isMobile, openMobile, setOpenMobile, toggleSidebar],
|
||||
);
|
||||
|
||||
return (
|
||||
<SidebarContext.Provider value={contextValue}>
|
||||
@@ -138,7 +138,7 @@ function SidebarProvider({
|
||||
}
|
||||
className={cn(
|
||||
"group/sidebar-wrapper has-data-[variant=inset]:bg-sidebar flex min-h-svh w-full",
|
||||
className
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
@@ -146,7 +146,7 @@ function SidebarProvider({
|
||||
</div>
|
||||
</TooltipProvider>
|
||||
</SidebarContext.Provider>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function Sidebar({
|
||||
@@ -157,11 +157,11 @@ function Sidebar({
|
||||
children,
|
||||
...props
|
||||
}: React.ComponentProps<"div"> & {
|
||||
side?: "left" | "right"
|
||||
variant?: "sidebar" | "floating" | "inset"
|
||||
collapsible?: "offcanvas" | "icon" | "none"
|
||||
side?: "left" | "right";
|
||||
variant?: "sidebar" | "floating" | "inset";
|
||||
collapsible?: "offcanvas" | "icon" | "none";
|
||||
}) {
|
||||
const { isMobile, state, openMobile, setOpenMobile } = useSidebar()
|
||||
const { isMobile, state, openMobile, setOpenMobile } = useSidebar();
|
||||
|
||||
if (collapsible === "none") {
|
||||
return (
|
||||
@@ -169,13 +169,13 @@ function Sidebar({
|
||||
data-slot="sidebar"
|
||||
className={cn(
|
||||
"bg-sidebar text-sidebar-foreground flex h-full w-(--sidebar-width) flex-col",
|
||||
className
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
</div>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if (isMobile) {
|
||||
@@ -200,7 +200,7 @@ function Sidebar({
|
||||
<div className="flex h-full w-full flex-col">{children}</div>
|
||||
</SheetContent>
|
||||
</Sheet>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
@@ -221,7 +221,7 @@ function Sidebar({
|
||||
"group-data-[side=right]:rotate-180",
|
||||
variant === "floating" || variant === "inset"
|
||||
? "group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)+(--spacing(4)))]"
|
||||
: "group-data-[collapsible=icon]:w-(--sidebar-width-icon)"
|
||||
: "group-data-[collapsible=icon]:w-(--sidebar-width-icon)",
|
||||
)}
|
||||
/>
|
||||
<div
|
||||
@@ -235,7 +235,7 @@ function Sidebar({
|
||||
variant === "floating" || variant === "inset"
|
||||
? "p-2 group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)+(--spacing(4))+2px)]"
|
||||
: "group-data-[collapsible=icon]:w-(--sidebar-width-icon) group-data-[side=left]:border-r group-data-[side=right]:border-l",
|
||||
className
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
@@ -248,7 +248,7 @@ function Sidebar({
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function SidebarTrigger({
|
||||
@@ -256,7 +256,7 @@ function SidebarTrigger({
|
||||
onClick,
|
||||
...props
|
||||
}: React.ComponentProps<typeof Button>) {
|
||||
const { toggleSidebar } = useSidebar()
|
||||
const { toggleSidebar } = useSidebar();
|
||||
|
||||
return (
|
||||
<Button
|
||||
@@ -266,19 +266,19 @@ function SidebarTrigger({
|
||||
size="icon"
|
||||
className={cn("size-7", className)}
|
||||
onClick={(event) => {
|
||||
onClick?.(event)
|
||||
toggleSidebar()
|
||||
onClick?.(event);
|
||||
toggleSidebar();
|
||||
}}
|
||||
{...props}
|
||||
>
|
||||
<PanelLeftIcon />
|
||||
<span className="sr-only">Toggle Sidebar</span>
|
||||
</Button>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function SidebarRail({ className, ...props }: React.ComponentProps<"button">) {
|
||||
const { toggleSidebar } = useSidebar()
|
||||
const { toggleSidebar } = useSidebar();
|
||||
|
||||
return (
|
||||
<button
|
||||
@@ -295,11 +295,11 @@ function SidebarRail({ className, ...props }: React.ComponentProps<"button">) {
|
||||
"hover:group-data-[collapsible=offcanvas]:bg-sidebar group-data-[collapsible=offcanvas]:translate-x-0 group-data-[collapsible=offcanvas]:after:left-full",
|
||||
"[[data-side=left][data-collapsible=offcanvas]_&]:-right-2",
|
||||
"[[data-side=right][data-collapsible=offcanvas]_&]:-left-2",
|
||||
className
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function SidebarInset({ className, ...props }: React.ComponentProps<"main">) {
|
||||
@@ -309,11 +309,11 @@ function SidebarInset({ className, ...props }: React.ComponentProps<"main">) {
|
||||
className={cn(
|
||||
"bg-background relative flex w-full flex-1 flex-col",
|
||||
"md:peer-data-[variant=inset]:m-2 md:peer-data-[variant=inset]:ml-0 md:peer-data-[variant=inset]:rounded-xl md:peer-data-[variant=inset]:shadow-sm md:peer-data-[variant=inset]:peer-data-[state=collapsed]:ml-2",
|
||||
className
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function SidebarInput({
|
||||
@@ -327,7 +327,7 @@ function SidebarInput({
|
||||
className={cn("bg-background h-8 w-full shadow-none", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function SidebarHeader({ className, ...props }: React.ComponentProps<"div">) {
|
||||
@@ -338,7 +338,7 @@ function SidebarHeader({ className, ...props }: React.ComponentProps<"div">) {
|
||||
className={cn("flex flex-col gap-2 p-2", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function SidebarFooter({ className, ...props }: React.ComponentProps<"div">) {
|
||||
@@ -349,7 +349,7 @@ function SidebarFooter({ className, ...props }: React.ComponentProps<"div">) {
|
||||
className={cn("flex flex-col gap-2 p-2", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function SidebarSeparator({
|
||||
@@ -363,7 +363,7 @@ function SidebarSeparator({
|
||||
className={cn("bg-sidebar-border mx-2 w-auto", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function SidebarContent({ className, ...props }: React.ComponentProps<"div">) {
|
||||
@@ -373,11 +373,11 @@ function SidebarContent({ className, ...props }: React.ComponentProps<"div">) {
|
||||
data-sidebar="content"
|
||||
className={cn(
|
||||
"flex min-h-0 flex-1 flex-col gap-2 overflow-auto group-data-[collapsible=icon]:overflow-hidden",
|
||||
className
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function SidebarGroup({ className, ...props }: React.ComponentProps<"div">) {
|
||||
@@ -388,7 +388,7 @@ function SidebarGroup({ className, ...props }: React.ComponentProps<"div">) {
|
||||
className={cn("relative flex w-full min-w-0 flex-col p-2", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function SidebarGroupLabel({
|
||||
@@ -396,7 +396,7 @@ function SidebarGroupLabel({
|
||||
asChild = false,
|
||||
...props
|
||||
}: React.ComponentProps<"div"> & { asChild?: boolean }) {
|
||||
const Comp = asChild ? Slot : "div"
|
||||
const Comp = asChild ? Slot : "div";
|
||||
|
||||
return (
|
||||
<Comp
|
||||
@@ -405,11 +405,11 @@ function SidebarGroupLabel({
|
||||
className={cn(
|
||||
"text-sidebar-foreground/70 ring-sidebar-ring flex h-8 shrink-0 items-center rounded-md px-2 text-xs font-medium outline-hidden transition-[margin,opacity] duration-200 ease-linear focus-visible:ring-2 [&>svg]:size-4 [&>svg]:shrink-0",
|
||||
"group-data-[collapsible=icon]:-mt-8 group-data-[collapsible=icon]:opacity-0",
|
||||
className
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function SidebarGroupAction({
|
||||
@@ -417,7 +417,7 @@ function SidebarGroupAction({
|
||||
asChild = false,
|
||||
...props
|
||||
}: React.ComponentProps<"button"> & { asChild?: boolean }) {
|
||||
const Comp = asChild ? Slot : "button"
|
||||
const Comp = asChild ? Slot : "button";
|
||||
|
||||
return (
|
||||
<Comp
|
||||
@@ -428,11 +428,11 @@ function SidebarGroupAction({
|
||||
// Increases the hit area of the button on mobile.
|
||||
"after:absolute after:-inset-2 md:after:hidden",
|
||||
"group-data-[collapsible=icon]:hidden",
|
||||
className
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function SidebarGroupContent({
|
||||
@@ -446,7 +446,7 @@ function SidebarGroupContent({
|
||||
className={cn("w-full text-sm", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function SidebarMenu({ className, ...props }: React.ComponentProps<"ul">) {
|
||||
@@ -457,7 +457,7 @@ function SidebarMenu({ className, ...props }: React.ComponentProps<"ul">) {
|
||||
className={cn("flex w-full min-w-0 flex-col gap-1", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function SidebarMenuItem({ className, ...props }: React.ComponentProps<"li">) {
|
||||
@@ -468,7 +468,7 @@ function SidebarMenuItem({ className, ...props }: React.ComponentProps<"li">) {
|
||||
className={cn("group/menu-item relative", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
const sidebarMenuButtonVariants = cva(
|
||||
@@ -490,8 +490,8 @@ const sidebarMenuButtonVariants = cva(
|
||||
variant: "default",
|
||||
size: "default",
|
||||
},
|
||||
}
|
||||
)
|
||||
},
|
||||
);
|
||||
|
||||
function SidebarMenuButton({
|
||||
asChild = false,
|
||||
@@ -502,12 +502,12 @@ function SidebarMenuButton({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<"button"> & {
|
||||
asChild?: boolean
|
||||
isActive?: boolean
|
||||
tooltip?: string | React.ComponentProps<typeof TooltipContent>
|
||||
asChild?: boolean;
|
||||
isActive?: boolean;
|
||||
tooltip?: string | React.ComponentProps<typeof TooltipContent>;
|
||||
} & VariantProps<typeof sidebarMenuButtonVariants>) {
|
||||
const Comp = asChild ? Slot : "button"
|
||||
const { isMobile, state } = useSidebar()
|
||||
const Comp = asChild ? Slot : "button";
|
||||
const { isMobile, state } = useSidebar();
|
||||
|
||||
const button = (
|
||||
<Comp
|
||||
@@ -518,16 +518,16 @@ function SidebarMenuButton({
|
||||
className={cn(sidebarMenuButtonVariants({ variant, size }), className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
);
|
||||
|
||||
if (!tooltip) {
|
||||
return button
|
||||
return button;
|
||||
}
|
||||
|
||||
if (typeof tooltip === "string") {
|
||||
tooltip = {
|
||||
children: tooltip,
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return (
|
||||
@@ -540,7 +540,7 @@ function SidebarMenuButton({
|
||||
{...tooltip}
|
||||
/>
|
||||
</Tooltip>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function SidebarMenuAction({
|
||||
@@ -549,10 +549,10 @@ function SidebarMenuAction({
|
||||
showOnHover = false,
|
||||
...props
|
||||
}: React.ComponentProps<"button"> & {
|
||||
asChild?: boolean
|
||||
showOnHover?: boolean
|
||||
asChild?: boolean;
|
||||
showOnHover?: boolean;
|
||||
}) {
|
||||
const Comp = asChild ? Slot : "button"
|
||||
const Comp = asChild ? Slot : "button";
|
||||
|
||||
return (
|
||||
<Comp
|
||||
@@ -568,11 +568,11 @@ function SidebarMenuAction({
|
||||
"group-data-[collapsible=icon]:hidden",
|
||||
showOnHover &&
|
||||
"peer-data-[active=true]/menu-button:text-sidebar-accent-foreground group-focus-within/menu-item:opacity-100 group-hover/menu-item:opacity-100 data-[state=open]:opacity-100 md:opacity-0",
|
||||
className
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function SidebarMenuBadge({
|
||||
@@ -590,11 +590,11 @@ function SidebarMenuBadge({
|
||||
"peer-data-[size=default]/menu-button:top-1.5",
|
||||
"peer-data-[size=lg]/menu-button:top-2.5",
|
||||
"group-data-[collapsible=icon]:hidden",
|
||||
className
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function SidebarMenuSkeleton({
|
||||
@@ -602,12 +602,12 @@ function SidebarMenuSkeleton({
|
||||
showIcon = false,
|
||||
...props
|
||||
}: React.ComponentProps<"div"> & {
|
||||
showIcon?: boolean
|
||||
showIcon?: boolean;
|
||||
}) {
|
||||
// Random width between 50 to 90%.
|
||||
const width = React.useMemo(() => {
|
||||
return `${Math.floor(Math.random() * 40) + 50}%`
|
||||
}, [])
|
||||
return `${Math.floor(Math.random() * 40) + 50}%`;
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div
|
||||
@@ -632,7 +632,7 @@ function SidebarMenuSkeleton({
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function SidebarMenuSub({ className, ...props }: React.ComponentProps<"ul">) {
|
||||
@@ -643,11 +643,11 @@ function SidebarMenuSub({ className, ...props }: React.ComponentProps<"ul">) {
|
||||
className={cn(
|
||||
"border-sidebar-border mx-3.5 flex min-w-0 translate-x-px flex-col gap-1 border-l px-2.5 py-0.5",
|
||||
"group-data-[collapsible=icon]:hidden",
|
||||
className
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function SidebarMenuSubItem({
|
||||
@@ -661,7 +661,7 @@ function SidebarMenuSubItem({
|
||||
className={cn("group/menu-sub-item relative", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function SidebarMenuSubButton({
|
||||
@@ -671,11 +671,11 @@ function SidebarMenuSubButton({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<"a"> & {
|
||||
asChild?: boolean
|
||||
size?: "sm" | "md"
|
||||
isActive?: boolean
|
||||
asChild?: boolean;
|
||||
size?: "sm" | "md";
|
||||
isActive?: boolean;
|
||||
}) {
|
||||
const Comp = asChild ? Slot : "a"
|
||||
const Comp = asChild ? Slot : "a";
|
||||
|
||||
return (
|
||||
<Comp
|
||||
@@ -689,11 +689,11 @@ function SidebarMenuSubButton({
|
||||
size === "sm" && "text-xs",
|
||||
size === "md" && "text-sm",
|
||||
"group-data-[collapsible=icon]:hidden",
|
||||
className
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
export {
|
||||
@@ -721,4 +721,4 @@ export {
|
||||
SidebarSeparator,
|
||||
SidebarTrigger,
|
||||
useSidebar,
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { cn } from "@/lib/utils"
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
function Skeleton({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
@@ -7,7 +7,7 @@ function Skeleton({ className, ...props }: React.ComponentProps<"div">) {
|
||||
className={cn("bg-accent animate-pulse rounded-md", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
export { Skeleton }
|
||||
export { Skeleton };
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import * as React from "react"
|
||||
import * as TabsPrimitive from "@radix-ui/react-tabs"
|
||||
import * as React from "react";
|
||||
import * as TabsPrimitive from "@radix-ui/react-tabs";
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
function Tabs({
|
||||
className,
|
||||
@@ -13,7 +13,7 @@ function Tabs({
|
||||
className={cn("flex flex-col gap-2", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function TabsList({
|
||||
@@ -25,11 +25,11 @@ function TabsList({
|
||||
data-slot="tabs-list"
|
||||
className={cn(
|
||||
"bg-muted text-muted-foreground inline-flex h-9 w-fit items-center justify-center rounded-lg p-[3px]",
|
||||
className
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function TabsTrigger({
|
||||
@@ -41,11 +41,11 @@ function TabsTrigger({
|
||||
data-slot="tabs-trigger"
|
||||
className={cn(
|
||||
"data-[state=active]:bg-background dark:data-[state=active]:text-foreground focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:outline-ring dark:data-[state=active]:border-input dark:data-[state=active]:bg-input/30 text-foreground dark:text-muted-foreground inline-flex h-[calc(100%-1px)] flex-1 items-center justify-center gap-1.5 rounded-md border border-transparent px-2 py-1 text-sm font-medium whitespace-nowrap transition-[color,box-shadow] focus-visible:ring-[3px] focus-visible:outline-1 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:shadow-sm [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
||||
className
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function TabsContent({
|
||||
@@ -58,7 +58,7 @@ function TabsContent({
|
||||
className={cn("flex-1 outline-none", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
export { Tabs, TabsList, TabsTrigger, TabsContent }
|
||||
export { Tabs, TabsList, TabsTrigger, TabsContent };
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
"use client"
|
||||
"use client";
|
||||
|
||||
import * as React from "react"
|
||||
import * as TooltipPrimitive from "@radix-ui/react-tooltip"
|
||||
import * as React from "react";
|
||||
import * as TooltipPrimitive from "@radix-ui/react-tooltip";
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
function TooltipProvider({
|
||||
delayDuration = 0,
|
||||
@@ -15,7 +15,7 @@ function TooltipProvider({
|
||||
delayDuration={delayDuration}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function Tooltip({
|
||||
@@ -25,13 +25,13 @@ function Tooltip({
|
||||
<TooltipProvider>
|
||||
<TooltipPrimitive.Root data-slot="tooltip" {...props} />
|
||||
</TooltipProvider>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function TooltipTrigger({
|
||||
...props
|
||||
}: React.ComponentProps<typeof TooltipPrimitive.Trigger>) {
|
||||
return <TooltipPrimitive.Trigger data-slot="tooltip-trigger" {...props} />
|
||||
return <TooltipPrimitive.Trigger data-slot="tooltip-trigger" {...props} />;
|
||||
}
|
||||
|
||||
function TooltipContent({
|
||||
@@ -47,7 +47,7 @@ function TooltipContent({
|
||||
sideOffset={sideOffset}
|
||||
className={cn(
|
||||
"bg-primary text-primary-foreground animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 w-fit origin-(--radix-tooltip-content-transform-origin) rounded-md px-3 py-1.5 text-xs text-balance",
|
||||
className
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
@@ -55,7 +55,7 @@ function TooltipContent({
|
||||
<TooltipPrimitive.Arrow className="bg-primary fill-primary z-50 size-2.5 translate-y-[calc(-50%_-_2px)] rotate-45 rounded-[2px]" />
|
||||
</TooltipPrimitive.Content>
|
||||
</TooltipPrimitive.Portal>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
export { Tooltip, TooltipTrigger, TooltipContent, TooltipProvider }
|
||||
export { Tooltip, TooltipTrigger, TooltipContent, TooltipProvider };
|
||||
|
||||
@@ -1,71 +1,75 @@
|
||||
import { createDefaultSettings, Settings, translateSettings } from "./settings";
|
||||
import { FileEntry } from "./zip-file";
|
||||
|
||||
type LogHandler = (lines: string[]) => void;
|
||||
|
||||
export interface UserFile {
|
||||
name: string;
|
||||
data: ArrayBuffer;
|
||||
};
|
||||
|
||||
export class Emulator {
|
||||
filesystem: FileEntry[];
|
||||
logHandler: LogHandler;
|
||||
terminatePromise: Promise<number | null>;
|
||||
terminateResolve: (value: number | null) => void;
|
||||
terminateReject: (reason?: any) => void;
|
||||
worker: Worker;
|
||||
|
||||
constructor(filesystem: FileEntry[], logHandler: LogHandler) {
|
||||
this.filesystem = filesystem;
|
||||
this.logHandler = logHandler;
|
||||
this.terminateResolve = () => { };
|
||||
this.terminateReject = () => { };
|
||||
this.terminatePromise = new Promise((resolve, reject) => {
|
||||
this.terminateResolve = resolve;
|
||||
this.terminateReject = reject;
|
||||
});
|
||||
|
||||
this.worker = new Worker(/*new URL('./emulator-worker.js', import.meta.url)*/ "./emulator-worker.js");
|
||||
|
||||
this.worker.onmessage = (event: MessageEvent) => {
|
||||
if (event.data.message == "log") {
|
||||
this.logHandler(event.data.data);
|
||||
}
|
||||
else if (event.data.message == "end") {
|
||||
this.terminateResolve(0);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
start(settings: Settings = createDefaultSettings(), userFile: UserFile | null = null) {
|
||||
var file = "c:/test-sample.exe";
|
||||
if (userFile) {
|
||||
const filename = userFile.name.split("/").pop()?.split("\\").pop();
|
||||
const canonicalName = filename?.toLowerCase()
|
||||
file = "c:/" + canonicalName;
|
||||
this.filesystem.push({
|
||||
name: "root/filesys/c/" + canonicalName,
|
||||
data: userFile.data,
|
||||
});
|
||||
}
|
||||
|
||||
this.worker.postMessage({
|
||||
message: "run",
|
||||
data: {
|
||||
filesystem: this.filesystem,
|
||||
file,
|
||||
options: translateSettings(settings),
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
stop() {
|
||||
this.worker.terminate();
|
||||
this.terminateResolve(null);
|
||||
}
|
||||
|
||||
onTerminate() {
|
||||
return this.terminatePromise;
|
||||
}
|
||||
};
|
||||
import { createDefaultSettings, Settings, translateSettings } from "./settings";
|
||||
import { FileEntry } from "./zip-file";
|
||||
|
||||
type LogHandler = (lines: string[]) => void;
|
||||
|
||||
export interface UserFile {
|
||||
name: string;
|
||||
data: ArrayBuffer;
|
||||
}
|
||||
|
||||
export class Emulator {
|
||||
filesystem: FileEntry[];
|
||||
logHandler: LogHandler;
|
||||
terminatePromise: Promise<number | null>;
|
||||
terminateResolve: (value: number | null) => void;
|
||||
terminateReject: (reason?: any) => void;
|
||||
worker: Worker;
|
||||
|
||||
constructor(filesystem: FileEntry[], logHandler: LogHandler) {
|
||||
this.filesystem = filesystem;
|
||||
this.logHandler = logHandler;
|
||||
this.terminateResolve = () => {};
|
||||
this.terminateReject = () => {};
|
||||
this.terminatePromise = new Promise((resolve, reject) => {
|
||||
this.terminateResolve = resolve;
|
||||
this.terminateReject = reject;
|
||||
});
|
||||
|
||||
this.worker = new Worker(
|
||||
/*new URL('./emulator-worker.js', import.meta.url)*/ "./emulator-worker.js",
|
||||
);
|
||||
|
||||
this.worker.onmessage = (event: MessageEvent) => {
|
||||
if (event.data.message == "log") {
|
||||
this.logHandler(event.data.data);
|
||||
} else if (event.data.message == "end") {
|
||||
this.terminateResolve(0);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
start(
|
||||
settings: Settings = createDefaultSettings(),
|
||||
userFile: UserFile | null = null,
|
||||
) {
|
||||
var file = "c:/test-sample.exe";
|
||||
if (userFile) {
|
||||
const filename = userFile.name.split("/").pop()?.split("\\").pop();
|
||||
const canonicalName = filename?.toLowerCase();
|
||||
file = "c:/" + canonicalName;
|
||||
this.filesystem.push({
|
||||
name: "root/filesys/c/" + canonicalName,
|
||||
data: userFile.data,
|
||||
});
|
||||
}
|
||||
|
||||
this.worker.postMessage({
|
||||
message: "run",
|
||||
data: {
|
||||
filesystem: this.filesystem,
|
||||
file,
|
||||
options: translateSettings(settings),
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
stop() {
|
||||
this.worker.terminate();
|
||||
this.terminateResolve(null);
|
||||
}
|
||||
|
||||
onTerminate() {
|
||||
return this.terminatePromise;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,92 +1,97 @@
|
||||
import {parseZipFile, FileEntry, ProgressHandler} from './zip-file';
|
||||
|
||||
function openDatabase(): Promise<IDBDatabase> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const request = indexedDB.open('cacheDB', 1);
|
||||
|
||||
request.onerror = (event: Event) => {
|
||||
reject(event);
|
||||
};
|
||||
|
||||
request.onsuccess = (event: Event) => {
|
||||
resolve(((event as any).target.result) as IDBDatabase);
|
||||
};
|
||||
|
||||
request.onupgradeneeded = (event: Event) => {
|
||||
const db = ((event as any).target.result) as IDBDatabase;
|
||||
if (!db.objectStoreNames.contains('cacheStore')) {
|
||||
db.createObjectStore('cacheStore', { keyPath: 'id' });
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
async function saveData(id: string, data: any) {
|
||||
const db = await openDatabase();
|
||||
return new Promise((resolve, reject) => {
|
||||
const transaction = db.transaction(['cacheStore'], 'readwrite');
|
||||
const objectStore = transaction.objectStore('cacheStore');
|
||||
const request = objectStore.put({ id: id, data: data });
|
||||
|
||||
request.onsuccess = () => {
|
||||
resolve('Data saved successfully');
|
||||
};
|
||||
|
||||
request.onerror = (event) => {
|
||||
reject('Save error: ' + (event as any).target.errorCode);
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
async function getData(id: string) {
|
||||
const db = await openDatabase();
|
||||
return new Promise((resolve, reject) => {
|
||||
const transaction = db.transaction(['cacheStore'], 'readonly');
|
||||
const objectStore = transaction.objectStore('cacheStore');
|
||||
const request = objectStore.get(id);
|
||||
|
||||
request.onsuccess = (event) => {
|
||||
if ((event as any).target.result) {
|
||||
resolve((event as any).target.result.data);
|
||||
} else {
|
||||
resolve(null);
|
||||
}
|
||||
};
|
||||
|
||||
request.onerror = (event) => {
|
||||
reject('Retrieve error: ' + (event as any).target.errorCode);
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
async function cacheAndUseData(id: string, asyncFunction: () => Promise<FileEntry[]>) {
|
||||
try {
|
||||
let data = (await getData(id)) as FileEntry[];
|
||||
if (!data) {
|
||||
data = await asyncFunction();
|
||||
await saveData(id, data);
|
||||
}
|
||||
return data;
|
||||
} catch (error) {
|
||||
console.error('Error:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
function fetchFilesystemZip() {
|
||||
return fetch("./root.zip?1", {
|
||||
method: "GET",
|
||||
headers: {
|
||||
'Content-Type': 'application/octet-stream',
|
||||
}
|
||||
}).then(r => r.arrayBuffer());
|
||||
}
|
||||
|
||||
async function fetchFilesystem(progressHandler: ProgressHandler) {
|
||||
const filesys = await fetchFilesystemZip();
|
||||
return await parseZipFile(filesys, progressHandler);
|
||||
}
|
||||
|
||||
export function getFilesystem(progressHandler: ProgressHandler) {
|
||||
return cacheAndUseData("emulator-filesystem-2", () => fetchFilesystem(progressHandler));
|
||||
}
|
||||
import { parseZipFile, FileEntry, ProgressHandler } from "./zip-file";
|
||||
|
||||
function openDatabase(): Promise<IDBDatabase> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const request = indexedDB.open("cacheDB", 1);
|
||||
|
||||
request.onerror = (event: Event) => {
|
||||
reject(event);
|
||||
};
|
||||
|
||||
request.onsuccess = (event: Event) => {
|
||||
resolve((event as any).target.result as IDBDatabase);
|
||||
};
|
||||
|
||||
request.onupgradeneeded = (event: Event) => {
|
||||
const db = (event as any).target.result as IDBDatabase;
|
||||
if (!db.objectStoreNames.contains("cacheStore")) {
|
||||
db.createObjectStore("cacheStore", { keyPath: "id" });
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
async function saveData(id: string, data: any) {
|
||||
const db = await openDatabase();
|
||||
return new Promise((resolve, reject) => {
|
||||
const transaction = db.transaction(["cacheStore"], "readwrite");
|
||||
const objectStore = transaction.objectStore("cacheStore");
|
||||
const request = objectStore.put({ id: id, data: data });
|
||||
|
||||
request.onsuccess = () => {
|
||||
resolve("Data saved successfully");
|
||||
};
|
||||
|
||||
request.onerror = (event) => {
|
||||
reject("Save error: " + (event as any).target.errorCode);
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
async function getData(id: string) {
|
||||
const db = await openDatabase();
|
||||
return new Promise((resolve, reject) => {
|
||||
const transaction = db.transaction(["cacheStore"], "readonly");
|
||||
const objectStore = transaction.objectStore("cacheStore");
|
||||
const request = objectStore.get(id);
|
||||
|
||||
request.onsuccess = (event) => {
|
||||
if ((event as any).target.result) {
|
||||
resolve((event as any).target.result.data);
|
||||
} else {
|
||||
resolve(null);
|
||||
}
|
||||
};
|
||||
|
||||
request.onerror = (event) => {
|
||||
reject("Retrieve error: " + (event as any).target.errorCode);
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
async function cacheAndUseData(
|
||||
id: string,
|
||||
asyncFunction: () => Promise<FileEntry[]>,
|
||||
) {
|
||||
try {
|
||||
let data = (await getData(id)) as FileEntry[];
|
||||
if (!data) {
|
||||
data = await asyncFunction();
|
||||
await saveData(id, data);
|
||||
}
|
||||
return data;
|
||||
} catch (error) {
|
||||
console.error("Error:", error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
function fetchFilesystemZip() {
|
||||
return fetch("./root.zip?1", {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/octet-stream",
|
||||
},
|
||||
}).then((r) => r.arrayBuffer());
|
||||
}
|
||||
|
||||
async function fetchFilesystem(progressHandler: ProgressHandler) {
|
||||
const filesys = await fetchFilesystemZip();
|
||||
return await parseZipFile(filesys, progressHandler);
|
||||
}
|
||||
|
||||
export function getFilesystem(progressHandler: ProgressHandler) {
|
||||
return cacheAndUseData("emulator-filesystem-2", () =>
|
||||
fetchFilesystem(progressHandler),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,19 +1,21 @@
|
||||
import * as React from "react"
|
||||
import * as React from "react";
|
||||
|
||||
const MOBILE_BREAKPOINT = 768
|
||||
const MOBILE_BREAKPOINT = 768;
|
||||
|
||||
export function useIsMobile() {
|
||||
const [isMobile, setIsMobile] = React.useState<boolean | undefined>(undefined)
|
||||
const [isMobile, setIsMobile] = React.useState<boolean | undefined>(
|
||||
undefined,
|
||||
);
|
||||
|
||||
React.useEffect(() => {
|
||||
const mql = window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT - 1}px)`)
|
||||
const mql = window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT - 1}px)`);
|
||||
const onChange = () => {
|
||||
setIsMobile(window.innerWidth < MOBILE_BREAKPOINT)
|
||||
}
|
||||
mql.addEventListener("change", onChange)
|
||||
setIsMobile(window.innerWidth < MOBILE_BREAKPOINT)
|
||||
return () => mql.removeEventListener("change", onChange)
|
||||
}, [])
|
||||
setIsMobile(window.innerWidth < MOBILE_BREAKPOINT);
|
||||
};
|
||||
mql.addEventListener("change", onChange);
|
||||
setIsMobile(window.innerWidth < MOBILE_BREAKPOINT);
|
||||
return () => mql.removeEventListener("change", onChange);
|
||||
}, []);
|
||||
|
||||
return !!isMobile
|
||||
return !!isMobile;
|
||||
}
|
||||
|
||||
@@ -76,7 +76,8 @@
|
||||
--sidebar-ring: oklch(0.623 0.214 259.815);
|
||||
}
|
||||
|
||||
:root, .dark {
|
||||
:root,
|
||||
.dark {
|
||||
--background: oklch(0.19 0.004 286.01);
|
||||
--foreground: oklch(0.985 0 0);
|
||||
--card: oklch(0.21 0.006 285.885);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { clsx, type ClassValue } from "clsx"
|
||||
import { twMerge } from "tailwind-merge"
|
||||
import { clsx, type ClassValue } from "clsx";
|
||||
import { twMerge } from "tailwind-merge";
|
||||
|
||||
export function cn(...inputs: ClassValue[]) {
|
||||
return twMerge(clsx(inputs))
|
||||
return twMerge(clsx(inputs));
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { StrictMode } from 'react'
|
||||
import { createRoot } from 'react-dom/client'
|
||||
import './index.css'
|
||||
import App from './App.tsx'
|
||||
import { StrictMode } from "react";
|
||||
import { createRoot } from "react-dom/client";
|
||||
import "./index.css";
|
||||
import App from "./App.tsx";
|
||||
|
||||
createRoot(document.getElementById('root')!).render(
|
||||
createRoot(document.getElementById("root")!).render(
|
||||
<StrictMode>
|
||||
<App />
|
||||
</StrictMode>,
|
||||
)
|
||||
);
|
||||
|
||||
@@ -1,37 +1,37 @@
|
||||
export interface Settings {
|
||||
verbose: boolean;
|
||||
concise: boolean;
|
||||
silent: boolean;
|
||||
bufferStdout: boolean;
|
||||
};
|
||||
|
||||
export function createDefaultSettings(): Settings {
|
||||
return {
|
||||
verbose: false,
|
||||
concise: false,
|
||||
silent: false,
|
||||
bufferStdout: true,
|
||||
};
|
||||
}
|
||||
|
||||
export function translateSettings(settings: Settings): string[] {
|
||||
const switches: string[] = [];
|
||||
|
||||
if (settings.verbose) {
|
||||
switches.push("-v");
|
||||
}
|
||||
|
||||
if (settings.concise) {
|
||||
switches.push("-c");
|
||||
}
|
||||
|
||||
if (settings.silent) {
|
||||
switches.push("-s");
|
||||
}
|
||||
|
||||
if (settings.bufferStdout) {
|
||||
switches.push("-b");
|
||||
}
|
||||
|
||||
return switches;
|
||||
}
|
||||
export interface Settings {
|
||||
verbose: boolean;
|
||||
concise: boolean;
|
||||
silent: boolean;
|
||||
bufferStdout: boolean;
|
||||
}
|
||||
|
||||
export function createDefaultSettings(): Settings {
|
||||
return {
|
||||
verbose: false,
|
||||
concise: false,
|
||||
silent: false,
|
||||
bufferStdout: true,
|
||||
};
|
||||
}
|
||||
|
||||
export function translateSettings(settings: Settings): string[] {
|
||||
const switches: string[] = [];
|
||||
|
||||
if (settings.verbose) {
|
||||
switches.push("-v");
|
||||
}
|
||||
|
||||
if (settings.concise) {
|
||||
switches.push("-c");
|
||||
}
|
||||
|
||||
if (settings.silent) {
|
||||
switches.push("-s");
|
||||
}
|
||||
|
||||
if (settings.bufferStdout) {
|
||||
switches.push("-b");
|
||||
}
|
||||
|
||||
return switches;
|
||||
}
|
||||
|
||||
@@ -1,33 +1,42 @@
|
||||
import JSZip from 'jszip';
|
||||
|
||||
export type ProgressHandler = (processed: number, total: number, filename: string) => void;
|
||||
|
||||
export interface FileEntry {
|
||||
name: string;
|
||||
data: ArrayBuffer
|
||||
};
|
||||
|
||||
export async function parseZipFile(arrayBuffer: ArrayBuffer, progressHandler?: ProgressHandler) {
|
||||
const zip = await JSZip.loadAsync(arrayBuffer);
|
||||
|
||||
const files: Promise<FileEntry>[] = [];
|
||||
const progress = {
|
||||
files: 0,
|
||||
processed: 0,
|
||||
};
|
||||
|
||||
zip.forEach(function (relativePath, zipEntry) {
|
||||
progress.files += 1;
|
||||
files.push(zipEntry.async('arraybuffer').then(data => {
|
||||
progress.processed += 1;
|
||||
|
||||
if (progressHandler) {
|
||||
progressHandler(progress.processed, progress.files, relativePath);
|
||||
}
|
||||
|
||||
return { name: relativePath, data };
|
||||
}));
|
||||
});
|
||||
|
||||
return await Promise.all(files);
|
||||
}
|
||||
import JSZip from "jszip";
|
||||
|
||||
export type ProgressHandler = (
|
||||
processed: number,
|
||||
total: number,
|
||||
filename: string,
|
||||
) => void;
|
||||
|
||||
export interface FileEntry {
|
||||
name: string;
|
||||
data: ArrayBuffer;
|
||||
}
|
||||
|
||||
export async function parseZipFile(
|
||||
arrayBuffer: ArrayBuffer,
|
||||
progressHandler?: ProgressHandler,
|
||||
) {
|
||||
const zip = await JSZip.loadAsync(arrayBuffer);
|
||||
|
||||
const files: Promise<FileEntry>[] = [];
|
||||
const progress = {
|
||||
files: 0,
|
||||
processed: 0,
|
||||
};
|
||||
|
||||
zip.forEach(function (relativePath, zipEntry) {
|
||||
progress.files += 1;
|
||||
files.push(
|
||||
zipEntry.async("arraybuffer").then((data) => {
|
||||
progress.processed += 1;
|
||||
|
||||
if (progressHandler) {
|
||||
progressHandler(progress.processed, progress.files, relativePath);
|
||||
}
|
||||
|
||||
return { name: relativePath, data };
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
return await Promise.all(files);
|
||||
}
|
||||
|
||||
@@ -23,9 +23,7 @@
|
||||
"noUncheckedSideEffectImports": true,
|
||||
"baseUrl": ".",
|
||||
"paths": {
|
||||
"@/*": [
|
||||
"./src/*"
|
||||
]
|
||||
"@/*": ["./src/*"]
|
||||
}
|
||||
},
|
||||
"include": ["src"]
|
||||
|
||||
@@ -11,9 +11,7 @@
|
||||
"compilerOptions": {
|
||||
"baseUrl": ".",
|
||||
"paths": {
|
||||
"@/*": [
|
||||
"./src/*"
|
||||
]
|
||||
"@/*": ["./src/*"]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import path from "path"
|
||||
import tailwindcss from "@tailwindcss/vite"
|
||||
import { defineConfig } from 'vite'
|
||||
import react from '@vitejs/plugin-react'
|
||||
import path from "path";
|
||||
import tailwindcss from "@tailwindcss/vite";
|
||||
import { defineConfig } from "vite";
|
||||
import react from "@vitejs/plugin-react";
|
||||
|
||||
// https://vite.dev/config/
|
||||
export default defineConfig({
|
||||
@@ -11,4 +11,4 @@ export default defineConfig({
|
||||
"@": path.resolve(__dirname, "./src"),
|
||||
},
|
||||
},
|
||||
})
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user