Skip to content

Commit

Permalink
chore: format code.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Dec 30, 2021
1 parent 965264a commit 1d6281c
Show file tree
Hide file tree
Showing 21 changed files with 175 additions and 144 deletions.
2 changes: 1 addition & 1 deletion .kktrc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ export default (conf: Configuration, env: 'production' | 'development', options:
conf.output = { ...conf.output, publicPath: './' };
}
return conf;
}
};
4 changes: 1 addition & 3 deletions renovate.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
{
"extends": [
"config:base"
]
"extends": ["config:base"]
}
15 changes: 12 additions & 3 deletions src/components/Loading.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
export default function Loading() {
return (
<div style={{ color: '#fff', minHeight: 100, display: 'flex', textAlign: 'center', justifyContent: 'center', alignItems: 'center' }}>
<div
style={{
color: '#fff',
minHeight: 100,
display: 'flex',
textAlign: 'center',
justifyContent: 'center',
alignItems: 'center',
}}
>
<span>Loading...</span>
</div>
)
}
);
}
5 changes: 2 additions & 3 deletions src/components/Search.module.less
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

.input {
max-width: 420px;
}
Expand All @@ -14,9 +13,9 @@
}
a {
color: #669eb9;
transition: color .3s;
transition: color 0.3s;
&:hover {
color: #78bfe0;
}
}
}
}
36 changes: 21 additions & 15 deletions src/components/Search.tsx
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
import { useState, Fragment} from 'react';
import { useState, Fragment } from 'react';
import Input from '@uiw/react-input';
import Button from '@uiw/react-button';
import { useDispatch } from 'react-redux';
import { Link, useNavigate }from 'react-router-dom';
import { Link, useNavigate } from 'react-router-dom';
import { Dispatch } from '../models';
import styles from './Search.module.less';

export default function Search() {
const dispatch = useDispatch<Dispatch>();
const [value, setValue] = useState<string>();
const navigate = useNavigate();
const [links] = useState<{to: string, label: string}[]>([
const [links] = useState<{ to: string; label: string }[]>([
{
to: '/pkg/uiw',
label: 'uiw'
label: 'uiw',
},
{
to: '/pkg/vue',
label: 'vue'
label: 'vue',
},
{
to: '/pkg/react',
label: 'react'
label: 'react',
},
{
to: '/pkg/react@17',
label: 'react@17'
label: 'react@17',
},
{
to: '/pkg/[email protected]',
label: '[email protected]'
label: '[email protected]',
},
]);
return (
Expand All @@ -42,12 +42,18 @@ export default function Search() {
setValue(e.target.value);
}}
addonAfter={
<Button onClick={() => {
if (value) {
dispatch.global.update({ showSearch: false });
navigate(`/pkg/${value}`);
}
}} icon="arrow-right" size="small" basic type="light" />
<Button
onClick={() => {
if (value) {
dispatch.global.update({ showSearch: false });
navigate(`/pkg/${value}`);
}
}}
icon="arrow-right"
size="small"
basic
type="light"
/>
}
placeholder="package or package@version"
/>
Expand All @@ -64,7 +70,7 @@ export default function Search() {
>
{item.label}
</Link>
)
);
})}
</div>
</Fragment>
Expand Down
6 changes: 3 additions & 3 deletions src/hook/usePath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ export function usePath() {
}, [filename, other]);

useEffect(() => {
setPkgName(`${org ? `${org}/${name}`: name}`);
setPkgName(`${org ? `${org}/${name}` : name}`);
}, [org, name]);

return { org, name, filename, other, filePath, pkgName }
}
return { org, name, filename, other, filePath, pkgName };
}
6 changes: 1 addition & 5 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,7 @@ function App() {

ReactDOM.render(
<Provider store={store}>
<GitHubCorners
size={54}
target="_parent"
href="https://github.com/uiwjs/npm-unpkg"
/>
<GitHubCorners size={54} target="_parent" href="https://github.com/uiwjs/npm-unpkg" />
<App />
</Provider>,
document.getElementById('root'),
Expand Down
74 changes: 38 additions & 36 deletions src/models/global.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createModel } from '@rematch/core';
import { RootModel } from './';
import { getDirectoryTrees, getFileContent } from '../servers/unpkg';
import {dataFilesSort} from '../utils/utils';
import { dataFilesSort } from '../utils/utils';

export interface Files {
path: string;
Expand All @@ -14,33 +14,35 @@ export interface Files {
}

export interface PackageJSON {
name: string;
version: string;
description: string;
author: string;
homepage?: string;
repository?: {
type?: string;
url?: string;
} | string;
license: string;
main: string;
module: string;
files: string[];
publishConfig?: {
[key: string]: any;
}
keywords: string[];
peerDependencies?: {
[key: string]: string;
}
dependencies?: {
[key: string]: string;
}
devDependencies?: {
[key: string]: string;
}
gitHead?: string;
name: string;
version: string;
description: string;
author: string;
homepage?: string;
repository?:
| {
type?: string;
url?: string;
}
| string;
license: string;
main: string;
module: string;
files: string[];
publishConfig?: {
[key: string]: any;
};
keywords: string[];
peerDependencies?: {
[key: string]: string;
};
dependencies?: {
[key: string]: string;
};
devDependencies?: {
[key: string]: string;
};
gitHead?: string;
}

export interface GlobalState {
Expand All @@ -59,7 +61,7 @@ export type Params = {
name?: string;
filename?: string;
'*'?: string;
}
};

export const global = createModel<RootModel>()({
state: {
Expand All @@ -78,8 +80,8 @@ export const global = createModel<RootModel>()({
...payload,
}),
},
effects: (dispatch) => {
const { global } = dispatch
effects: (dispatch) => {
const { global } = dispatch;
return {
async setPkgname(params: Params) {
const { name, org } = params || {};
Expand All @@ -106,7 +108,7 @@ export const global = createModel<RootModel>()({
async getPackageJSON(_, state) {
const data: PackageJSON = await getFileContent(`${state.global.pkgname}/package.json`);
if (data && typeof data === 'object') {
global.update({ package: {...data }, notFindPkg: false });
global.update({ package: { ...data }, notFindPkg: false });
} else {
global.update({
package: undefined,
Expand All @@ -118,15 +120,15 @@ export const global = createModel<RootModel>()({
if (!filepath) {
dispatch.global.update({ content: '', extname: '' });
return;
};
const type = filepath.replace(/.+\./,'');
}
const type = filepath.replace(/.+\./, '');
const data: PackageJSON = await getFileContent(`${state.global.pkgname}/${filepath}`);
if (typeof data === 'string' || !data) {
dispatch.global.update({ content: data, extname: type });
} else if (data && /\.(json|map)$/.test(filepath)) {
dispatch.global.update({ content: JSON.stringify(data, null, 2), extname: type });
}
},
}
}
};
},
});
6 changes: 3 additions & 3 deletions src/models/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ export const store = init<RootModel, FullModel>({
plugins: [loadingPlugin()],
});

export type Store = typeof store
export type Dispatch = RematchDispatch<RootModel>
export type RootState = RematchRootState<RootModel, FullModel>
export type Store = typeof store;
export type Dispatch = RematchDispatch<RootModel>;
export type RootState = RematchRootState<RootModel, FullModel>;
2 changes: 1 addition & 1 deletion src/pages/Home/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export default function Home() {
<Search />
</div>
);
}
}
2 changes: 1 addition & 1 deletion src/pages/Preview/Content.module.less
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@
background-color: #333;
color: #fff;
}
}
}
38 changes: 21 additions & 17 deletions src/pages/Preview/Content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const langs: Record<string, any> = {
typescript: () => javascript({ typescript: true }),
ts: () => javascript({ typescript: true }),
tsx: () => javascript({ jsx: true, typescript: true }),
}
};

export default function DirectoryTrees() {
const { loading, content, extname } = useSelector(({ global, loading }: RootState) => ({
Expand All @@ -51,18 +51,29 @@ export default function DirectoryTrees() {
const contentView = useMemo(() => {
let ext = extname;
switch (extname) {
case 'tsx': ext = 'typescript'; break;
case 'ts': ext = 'typescript'; break;
case 'map': ext = 'json'; break;
case 'markdown': ext = 'md'; break;
default: break;
case 'tsx':
ext = 'typescript';
break;
case 'ts':
ext = 'typescript';
break;
case 'map':
ext = 'json';
break;
case 'markdown':
ext = 'md';
break;
default:
break;
}
if (!content) return <Fragment />
if (extname && (/(md|markdown)$/.test(extname))) {
if (!content) return <Fragment />;
if (extname && /(md|markdown)$/.test(extname)) {
return (
<Fragment>
<div>
<a className={styles.viewRaw} href={filePath} target="__blank">View Raw</a>
<a className={styles.viewRaw} href={filePath} target="__blank">
View Raw
</a>
<MarkdownPreview rehypePlugins={[rehypeVideo]} style={{ padding: 25 }} source={content || ''} />
</div>
</Fragment>
Expand All @@ -73,14 +84,7 @@ export default function DirectoryTrees() {
if (langs[extname]) {
extensions.push(langs[extname]());
}
return (
<CodeMirror
extensions={[...extensions]}
editable={false}
height="100%"
value={content}
/>
);
return <CodeMirror extensions={[...extensions]} editable={false} height="100%" value={content} />;
}
if (extname) {
return <MarkdownPreview className={styles.code} source={`\`\`\`${ext}\n${content}\n\`\`\``} />;
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Preview/DirectoryTrees.module.less
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
line-height: 16px;
align-self: center;
margin-right: -6px !important;
}
}
Loading

0 comments on commit 1d6281c

Please sign in to comment.