This commit is contained in:
2025-03-18 16:14:40 +08:00
parent 25def8c245
commit aa1cee7c9f
50 changed files with 916 additions and 502 deletions

View File

@@ -1,5 +1,5 @@
{
"name": "resources",
"name": "@kevisual/resources",
"version": "0.0.1",
"description": "",
"main": "index.js",
@@ -42,5 +42,9 @@
},
"devDependencies": {
"@kevisual/types": "^0.0.6"
},
"exports": {
".": "./src/index.tsx",
"./*": "./src/*"
}
}

View File

@@ -1,4 +1,4 @@
import { bootstrap } from './pages/Bootstrap';
import { render } from './pages/Bootstrap';
bootstrap('#ai-root');
render('#ai-root');

View File

@@ -1,4 +1,4 @@
import { toastLogin } from '@/pages/message/ToastLogin';
import { toastLogin } from '@kevisual/resources/pages/message/ToastLogin';
import { QueryClient } from '@kevisual/query';
export const query = new QueryClient();

View File

@@ -1,5 +1,5 @@
import { useEffect } from 'react';
import { theme } from '@kevisual/center-components/theme';
import { useEffect, useMemo } from 'react';
import { theme } from '@kevisual/center-components/theme/index.tsx';
import { ThemeProvider } from '@mui/material/styles';
import { Left } from './layout/Left';
import { Main } from './main/index';
@@ -74,7 +74,17 @@ export const InitProvider = ({ children }: { children: React.ReactNode }) => {
<div style={{ display: 'flex', flexDirection: 'column', justifyContent: 'center', alignItems: 'center', height: '100vh', color: 'red' }}>
<h2></h2>
<p></p>
<button onClick={handleRetry} style={{ marginTop: '20px', padding: '10px 20px', backgroundColor: '#f44336', color: '#fff', border: 'none', borderRadius: '4px', cursor: 'pointer' }}>
<button
onClick={handleRetry}
style={{
marginTop: '20px',
padding: '10px 20px',
backgroundColor: '#f44336',
color: '#fff',
border: 'none',
borderRadius: '4px',
cursor: 'pointer',
}}>
</button>
</div>
@@ -82,15 +92,37 @@ export const InitProvider = ({ children }: { children: React.ReactNode }) => {
}
return <>{children}</>;
};
export const App = () => {
type AppProvider = {
key: string;
use: boolean;
};
export type AppProps = {
providers?: AppProvider[];
noProvider?: boolean;
/**
* 是否是单个应用
* 默认是单个应用模块。
*/
isSingleApp?: boolean;
};
export const App = ({ providers, noProvider, isSingleApp = true }: AppProps) => {
const children = useMemo(() => {
return (
<InitProvider>
<Left>
<Main />
</Left>
</InitProvider>
);
}, []);
if (noProvider) {
return <>{children}</>;
}
return (
<ThemeProvider theme={theme}>
<AntdConfigProvider>
<InitProvider>
<Left>
<Main />
</Left>
</InitProvider>
{children}
<ToastContainer />
</AntdConfigProvider>
</ThemeProvider>

View File

@@ -1,5 +1,5 @@
import { createRoot } from 'react-dom/client';
import { App } from './App';
import { App, AppProps } from './App';
import React from 'react';
export class ReactRenderer {
@@ -40,13 +40,27 @@ export class ReactRenderer {
}
export default ReactRenderer;
export const bootstrap = (el: HTMLElement | string) => {
export const randomId = () => {
return Math.random().toString(36).substring(2, 15);
};
export const render = (el: HTMLElement | string, props?: AppProps) => {
// createRoot(document.getElementById('ai-root')!).render(<App />);
const root = typeof el === 'string' ? document.querySelector(el) : el;
if (root) {
if (!root) {
console.error('root not found');
return;
}
const hasResourceApp = window.context?.resourcesApp;
if (hasResourceApp) {
const render = hasResourceApp as ReactRenderer;
render.updateProps({
props: { t: randomId(), ...props },
});
root.innerHTML = '';
root.appendChild(render.element);
} else {
const renderer = new ReactRenderer(App, {
props: {},
props: { ...props },
className: 'resources-root w-full h-full',
});
if (window.context) {
@@ -59,3 +73,17 @@ export const bootstrap = (el: HTMLElement | string) => {
root.appendChild(renderer.element);
}
};
export const unmount = (el: HTMLElement | string) => {
const root = typeof el === 'string' ? document.querySelector(el) : el;
if (!root) {
console.error('root not found');
return;
}
const hasResourceApp = window.context?.resourcesApp;
if (hasResourceApp) {
const render = hasResourceApp as ReactRenderer;
render.destroy();
window.context.resourcesApp = null;
}
};

View File

@@ -1,5 +1,5 @@
import { useResourceStore } from '@/pages/store/resource';
import { useResourceFileStore } from '@/pages/store/resource-file';
import { useResourceStore } from '@kevisual/resources/pages/store/resource';
import { useResourceFileStore } from '@kevisual/resources/pages/store/resource-file';
import { Box, Divider, Drawer, Tab, Tabs } from '@mui/material';
import { useMemo, useState } from 'react';
import { QuickValues, QuickTabs } from './QuickTabs';

View File

@@ -1,4 +1,4 @@
import { useResourceFileStore } from '@/pages/store/resource-file';
import { useResourceFileStore } from '@kevisual/resources/pages/store/resource-file';
import { Box, Typography } from '@mui/material';
import prettyBytes from 'pretty-bytes';
import dayjs from 'dayjs';

View File

@@ -1,4 +1,4 @@
import { useResourceFileStore } from '@/pages/store/resource-file';
import { useResourceFileStore } from '@kevisual/resources/pages/store/resource-file';
import { FormControlLabel, Box, TextField, Button, IconButton, ButtonGroup, Tooltip, Select, MenuItem, Typography, FormGroup } from '@mui/material';
import { Info, Plus, Save, Share, Shuffle, Trash } from 'lucide-react';
import { useState, useEffect, useMemo } from 'react';

View File

@@ -1,5 +1,5 @@
import { useResourceFileStore } from '@/pages/store/resource-file';
import { useSettingsStore } from '@/pages/store/settings';
import { useResourceFileStore } from '@kevisual/resources/pages/store/resource-file';
import { useSettingsStore } from '@kevisual/resources/pages/store/settings';
import { Button, Tooltip, useTheme } from '@mui/material';
import { useShallow } from 'zustand/shallow';
import { Accordion, AccordionSummary, AccordionDetails } from '@mui/material';

View File

@@ -1,4 +1,4 @@
import { useResourceFileStore } from '@/pages/store/resource-file';
import { useResourceFileStore } from '@kevisual/resources/pages/store/resource-file';
import { useShallow } from 'zustand/shallow';
import { QuickPreview } from './QuickPreview';
import { useMemo } from 'react';

View File

@@ -1,9 +1,9 @@
import { useResourceStore } from '@/pages/store/resource';
import { useResourceStore } from '@kevisual/resources/pages/store/resource';
import { Card, CardContent, Typography } from '@mui/material';
import { getIcon } from '../FileIcon';
import { amber } from '@mui/material/colors';
import clsx from 'clsx';
import { useResourceFileStore } from '@/pages/store/resource-file';
import { useResourceFileStore } from '@kevisual/resources/pages/store/resource-file';
export const FileCard = () => {
const { list, prefix, onOpenPrefix } = useResourceStore();
const { setPrefix, setOpenDrawer } = useResourceFileStore();

View File

@@ -1,11 +1,11 @@
import { useResourceStore } from '@/pages/store/resource';
import { useResourceStore } from '@kevisual/resources/pages/store/resource';
import { Button, Paper, Table, TableBody, TableCell, TableContainer, TableHead, TableRow } from '@mui/material';
import prettyBytes from 'pretty-bytes';
import dayjs from 'dayjs';
import { getIcon } from '../FileIcon';
import { Download, Trash } from 'lucide-react';
import clsx from 'clsx';
import { useResourceFileStore } from '@/pages/store/resource-file';
import { useResourceFileStore } from '@kevisual/resources/pages/store/resource-file';
export const FileTable = () => {
const { list, prefix, download, onOpenPrefix, deleteFile } = useResourceStore();

View File

@@ -1,4 +1,4 @@
import { useResourceStore } from '@/pages/store/resource';
import { useResourceStore } from '@kevisual/resources/pages/store/resource';
import { Breadcrumbs, Typography } from '@mui/material';
import clsx from 'clsx';
import { useMemo } from 'react';

View File

@@ -1,3 +1,3 @@
import { bootstrap } from './Bootstrap';
import { render } from './Bootstrap';
bootstrap('#ai-root');
render('#ai-root');

View File

@@ -1,4 +1,4 @@
import { useSettingsStore, Settings as SettingsType } from '@/pages/store/settings';
import { useSettingsStore, Settings as SettingsType } from '@kevisual/resources/pages/store/settings';
import { Box, Typography, TextField, useTheme, Button } from '@mui/material';
import { useEffect, useState } from 'react';
import { Settings as SettingsIcon } from 'lucide-react';

View File

@@ -1,6 +1,6 @@
import { create } from 'zustand';
import { Resource } from './resource';
import { query } from '@/modules/query';
import { query } from '@kevisual/resources/modules/query';
import { toast } from 'react-toastify';
interface ResourceFileStore {

View File

@@ -1,5 +1,5 @@
import { create } from 'zustand';
import { query } from '@/modules/query';
import { query } from '@kevisual/resources/modules/query';
import { sortBy } from 'lodash-es';
import { toast } from 'react-toastify';
import { useSettingsStore } from './settings';

View File

@@ -1,5 +1,5 @@
import { create } from 'zustand';
import { query } from '@/modules/query';
import { query } from '@kevisual/resources/modules/query';
import { toast } from 'react-toastify';
export type Settings = {

View File

@@ -1,5 +1,5 @@
import { create } from 'zustand';
import { query } from '@/modules/query';
import { query } from '@kevisual/resources/modules/query';
type Statistic = {
list: any[];

View File

@@ -2,7 +2,7 @@ import NProgress from 'nprogress';
import 'nprogress/nprogress.css';
import { toast } from 'react-toastify';
import { nanoid } from 'nanoid';
import { toastLogin } from '@/pages/message/ToastLogin';
import { toastLogin } from '@kevisual/resources/pages/message/ToastLogin';
type ConvertOpts = {
appKey?: string;

View File

@@ -2,7 +2,7 @@ import NProgress from 'nprogress';
import 'nprogress/nprogress.css';
import { toast } from 'react-toastify';
import { nanoid } from 'nanoid';
import { toastLogin } from '@/pages/message/ToastLogin';
import { toastLogin } from '@kevisual/resources/pages/message/ToastLogin';
type ConvertOpts = {
appKey?: string;

View File

@@ -22,7 +22,7 @@
"node_modules/@kevisual/types",
],
"paths": {
"@/*": [
"@kevisual/resources/*": [
"src/*"
]
},

View File

@@ -42,7 +42,7 @@ export default defineConfig({
},
resolve: {
alias: {
'@': path.resolve(__dirname, './src'),
'@kevisual/resources': path.resolve(__dirname, './src'),
// 'react/jsx-dev-runtime': 'https://cdn.jsdelivr.net/npm/react/jsx-dev-runtime/+esm',
// 'react/jsx-runtime': 'https://cdn.jsdelivr.net/npm/react/jsx-runtime/+esm',
// 'react/jsx-runtime': path.resolve(__dirname, './node_modules/react/jsx-runtime'),