chore: format code

This commit is contained in:
fantasticit 2022-03-12 10:31:03 +08:00
parent b13dd26d9a
commit f629eedbb0
36 changed files with 387 additions and 425 deletions

4
.prettierignore Normal file
View File

@ -0,0 +1,4 @@
node_modules
.next
dist
lib

12
.prettierrc Normal file
View File

@ -0,0 +1,12 @@
{
"singleQuote": true,
"quoteProps": "consistent",
"bracketSpacing": true,
"jsxBracketSameLine": false,
"arrowParens": "always",
"trailingComma": "es5",
"tabWidth": 2,
"semi": true,
"printWidth": 100,
"endOfLine": "lf"
}

View File

@ -89,40 +89,40 @@ pnpm run dev
```yaml ```yaml
# 开发环境配置 # 开发环境配置
server: server:
prefix: "/api" prefix: '/api'
port: 5001 port: 5001
collaborationPort: 5003 collaborationPort: 5003
client: client:
assetPrefix: "/" assetPrefix: '/'
apiUrl: "http://localhost:5001/api" apiUrl: 'http://localhost:5001/api'
collaborationUrl: "ws://localhost:5003" collaborationUrl: 'ws://localhost:5003'
# 数据库配置 # 数据库配置
db: db:
mysql: mysql:
host: "127.0.0.1" host: '127.0.0.1'
username: "root" username: 'root'
password: "root" password: 'root'
database: "think" database: 'think'
port: 3306 port: 3306
charset: "utf8mb4" charset: 'utf8mb4'
timezone: "+08:00" timezone: '+08:00'
synchronize: true synchronize: true
# oss 文件存储服务 # oss 文件存储服务
oss: oss:
aliyun: aliyun:
accessKeyId: "" accessKeyId: ''
accessKeySecret: "" accessKeySecret: ''
bucket: "" bucket: ''
https: true https: true
region: "" region: ''
# jwt 配置 # jwt 配置
jwt: jwt:
secretkey: "zA_Think+KNOWLEDGE+WIKI+DOCUMENTS@2022" secretkey: 'zA_Think+KNOWLEDGE+WIKI+DOCUMENTS@2022'
expiresIn: "6h" expiresIn: '6h'
``` ```
### 项目部署 ### 项目部署

View File

@ -19,7 +19,12 @@
"start:client": "pnpm run --dir packages/client start", "start:client": "pnpm run --dir packages/client start",
"pm2": "concurrently \"pnpm:pm2:*\"", "pm2": "concurrently \"pnpm:pm2:*\"",
"pm2:server": "pnpm run --dir packages/server pm2", "pm2:server": "pnpm run --dir packages/server pm2",
"pm2:client": "pnpm run --dir packages/client pm2" "pm2:client": "pnpm run --dir packages/client pm2",
"lint": "eslint . -c ./.eslintrc.js --fix --quiet 'packages/**/*.{ts,tsx,js,jsx}'",
"format": "npm run format:md && npm run format:json && npm run format:source",
"format:md": "prettier --parser markdown --write './**/*.md'",
"format:json": "prettier --parser json --write './**/*.json'",
"format:source": "prettier --write './**/*.{js,ts}'"
}, },
"dependencies": { "dependencies": {
"concurrently": "^7.0.0", "concurrently": "^7.0.0",
@ -31,6 +36,7 @@
"node": ">=16.5.0" "node": ">=16.5.0"
}, },
"devDependencies": { "devDependencies": {
"prettier": "^2.3.2",
"typescript": "^4.5.5" "typescript": "^4.5.5"
} }
} }

View File

@ -1,6 +1,6 @@
const semi = require("@douyinfe/semi-next").default({}); const semi = require('@douyinfe/semi-next').default({});
const TsconfigPathsPlugin = require("tsconfig-paths-webpack-plugin"); const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
const { getConfig } = require("@think/config"); const { getConfig } = require('@think/config');
const config = getConfig().client; const config = getConfig().client;
/** @type {import('next').NextConfig} */ /** @type {import('next').NextConfig} */

View File

@ -1,171 +1,171 @@
export const EXPRESSIONES = [ export const EXPRESSIONES = [
"😀", '😀',
"😃", '😃',
"😄", '😄',
"😁", '😁',
"😆", '😆',
"😅", '😅',
"😂", '😂',
"🤣", '🤣',
"🥲", '🥲',
"😊", '😊',
"😇", '😇',
"🙂", '🙂',
"🙃", '🙃',
"😉", '😉',
"😌", '😌',
"😍", '😍',
"🥰", '🥰',
"😘", '😘',
"😗", '😗',
"😙", '😙',
"😚", '😚',
"😋", '😋',
"😛", '😛',
"😝", '😝',
"😜", '😜',
"🤪", '🤪',
"🤨", '🤨',
"🧐", '🧐',
"🤓", '🤓',
"😎", '😎',
"🥸", '🥸',
"🤩", '🤩',
"🥳", '🥳',
"😏", '😏',
"😒", '😒',
"😞", '😞',
"😔", '😔',
"😟", '😟',
"😕", '😕',
"🙁", '🙁',
"😣", '😣',
"😖", '😖',
"😫", '😫',
"😩", '😩',
"🥺", '🥺',
"😢", '😢',
"😭", '😭',
"😤", '😤',
"😠", '😠',
"😡", '😡',
"🤬", '🤬',
"🤯", '🤯',
"😳", '😳',
"🥵", '🥵',
"🥶", '🥶',
"😱", '😱',
"😨", '😨',
"😰", '😰',
"😥", '😥',
"😓", '😓',
"🤗", '🤗',
"🤔", '🤔',
"🤭", '🤭',
"🤫", '🤫',
"🤥", '🤥',
"😶", '😶',
"😐", '😐',
"😑", '😑',
"😬", '😬',
"🙄", '🙄',
"😯", '😯',
"😦", '😦',
"😧", '😧',
"😮", '😮',
"😲", '😲',
"🥱", '🥱',
"😴", '😴',
"🤤", '🤤',
"😪", '😪',
"😵", '😵',
"🤐", '🤐',
"🥴", '🥴',
"🤢", '🤢',
"🤮", '🤮',
"🤧", '🤧',
"😷", '😷',
"🤒", '🤒',
"🤕", '🤕',
"🤑", '🤑',
"🤠", '🤠',
"😈", '😈',
"👿", '👿',
"👹", '👹',
"👺", '👺',
"🤡", '🤡',
"💩", '💩',
"👻", '👻',
"💀", '💀',
"☠️", '☠️',
"👽", '👽',
"👾", '👾',
"🤖", '🤖',
"🎃", '🎃',
"😺", '😺',
"😸", '😸',
"😹", '😹',
"😻", '😻',
"😼", '😼',
"😽", '😽',
"🙀", '🙀',
"😿", '😿',
"😾", '😾',
]; ];
export const GESTURES = [ export const GESTURES = [
"👋", '👋',
"🤚", '🤚',
"🖐", '🖐',
"✋", '✋',
"🖖", '🖖',
"👌", '👌',
"🤌", '🤌',
"🤏", '🤏',
"✌️", '✌️',
"🤞", '🤞',
"🤟", '🤟',
"🤘", '🤘',
"🤙", '🤙',
"👈", '👈',
"👉", '👉',
"👆", '👆',
"🖕", '🖕',
"👇", '👇',
"☝️", '☝️',
"👍", '👍',
"👎", '👎',
"✊", '✊',
"👊", '👊',
"🤛", '🤛',
"🤜", '🤜',
"👏", '👏',
"🙌", '🙌',
"👐", '👐',
"🤲", '🤲',
"🤝", '🤝',
"🙏", '🙏',
"✍️", '✍️',
"💅", '💅',
"🤳", '🤳',
"💪", '💪',
"🦾", '🦾',
"🦵", '🦵',
"🦿", '🦿',
"🦶", '🦶',
"👣", '👣',
"👂", '👂',
"🦻", '🦻',
"👃", '👃',
"🫀", '🫀',
"🫁", '🫁',
"🧠", '🧠',
"🦷", '🦷',
"🦴", '🦴',
"👀", '👀',
"👁", '👁',
"👅", '👅',
"👄", '👄',
"💋", '💋',
"🩸", '🩸',
]; ];

View File

@ -1,5 +1,5 @@
import { HocuspocusProvider } from "@hocuspocus/provider"; import { HocuspocusProvider } from '@hocuspocus/provider';
import { IUser } from "@think/domains"; import { IUser } from '@think/domains';
const PROVIDER_POOL_READER = new Map(); const PROVIDER_POOL_READER = new Map();
const PROVIDER_POOL_EDITOR = new Map(); const PROVIDER_POOL_EDITOR = new Map();
@ -7,22 +7,21 @@ const PROVIDER_POOL_EDITOR = new Map();
export const getProvider = ({ export const getProvider = ({
targetId, targetId,
token, token,
cacheType = "READER", cacheType = 'READER',
user, user,
docType = "document", docType = 'document',
events = {}, events = {},
}: { }: {
targetId: string; targetId: string;
token: string; token: string;
cacheType: "READER" | "EDITOR"; cacheType: 'READER' | 'EDITOR';
user: IUser; user: IUser;
docType: "document" | "template"; docType: 'document' | 'template';
events?: { events?: {
onAwarenessUpdate?: (states: any) => void; onAwarenessUpdate?: (states: any) => void;
}; };
}) => { }) => {
const pool = const pool = cacheType === 'READER' ? PROVIDER_POOL_READER : PROVIDER_POOL_EDITOR;
cacheType === "READER" ? PROVIDER_POOL_READER : PROVIDER_POOL_EDITOR;
if (!pool.has(targetId)) { if (!pool.has(targetId)) {
const provider = new HocuspocusProvider({ const provider = new HocuspocusProvider({
@ -43,12 +42,8 @@ export const getProvider = ({
return pool.get(targetId); return pool.get(targetId);
}; };
export const destoryProvider = ( export const destoryProvider = (provider, cacheType: 'READER' | 'EDITOR' = 'READER') => {
provider, const pool = cacheType === 'READER' ? PROVIDER_POOL_READER : PROVIDER_POOL_EDITOR;
cacheType: "READER" | "EDITOR" = "READER"
) => {
const pool =
cacheType === "READER" ? PROVIDER_POOL_READER : PROVIDER_POOL_EDITOR;
pool.delete(provider.configuration.name); pool.delete(provider.configuration.name);
provider.document.destroy(); provider.document.destroy();

View File

@ -1,9 +1,7 @@
export const isListActive = (editor) => { export const isListActive = (editor) => {
return ( return (
editor.isActive("bulletList") || editor.isActive('bulletList') || editor.isActive('orderedList') || editor.isActive('taskList')
editor.isActive("orderedList") ||
editor.isActive("taskList")
); );
}; };
export const isTitleActive = (editor) => editor.isActive("title"); export const isTitleActive = (editor) => editor.isActive('title');

View File

@ -1,5 +1,5 @@
export function download(url, name) { export function download(url, name) {
const link = document.createElement("a"); const link = document.createElement('a');
link.download = name; link.download = name;
link.href = url; link.href = url;
document.body.appendChild(link); document.body.appendChild(link);

View File

@ -1,19 +1,17 @@
import { Node } from "prosemirror-model"; import { Node } from 'prosemirror-model';
export function isBulletListNode(node: Node): boolean { export function isBulletListNode(node: Node): boolean {
return node.type.name === "bulletList"; return node.type.name === 'bulletList';
} }
export function isOrderedListNode(node: Node): boolean { export function isOrderedListNode(node: Node): boolean {
return node.type.name === "orderedList"; return node.type.name === 'orderedList';
} }
export function isTodoListNode(node: Node): boolean { export function isTodoListNode(node: Node): boolean {
return node.type.name === "taskList"; return node.type.name === 'taskList';
} }
export function isListNode(node: Node): boolean { export function isListNode(node: Node): boolean {
return ( return isBulletListNode(node) || isOrderedListNode(node) || isTodoListNode(node);
isBulletListNode(node) || isOrderedListNode(node) || isTodoListNode(node)
);
} }

View File

@ -1,10 +1,7 @@
import { NodeType, Schema } from "prosemirror-model"; import { NodeType, Schema } from 'prosemirror-model';
export function getNodeType( export function getNodeType(nameOrType: string | NodeType, schema: Schema): NodeType {
nameOrType: string | NodeType, if (typeof nameOrType === 'string') {
schema: Schema
): NodeType {
if (typeof nameOrType === "string") {
if (!schema.nodes[nameOrType]) { if (!schema.nodes[nameOrType]) {
throw Error( throw Error(
`There is no node type named '${nameOrType}'. Maybe you forgot to add the extension?` `There is no node type named '${nameOrType}'. Maybe you forgot to add the extension?`

View File

@ -1,14 +1,11 @@
import type { IComment } from "@think/domains"; import type { IComment } from '@think/domains';
import { useState } from "react"; import { useState } from 'react';
import useSWR from "swr"; import useSWR from 'swr';
import { HttpClient } from "services/HttpClient"; import { HttpClient } from 'services/HttpClient';
export type CreateCommentDto = Pick< export type CreateCommentDto = Pick<IComment, 'parentCommentId' | 'html' | 'replyUserId'>;
IComment,
"parentCommentId" | "html" | "replyUserId"
>;
export type UpdateCommentDto = Pick<IComment, "id" | "html">; export type UpdateCommentDto = Pick<IComment, 'id' | 'html'>;
/** /**
* *
@ -20,9 +17,7 @@ export const useComments = (documentId) => {
const { data, error, mutate } = useSWR<{ const { data, error, mutate } = useSWR<{
data: Array<IComment>; data: Array<IComment>;
total: number; total: number;
}>(`/comment/document/${documentId}?page=${page}`, (url) => }>(`/comment/document/${documentId}?page=${page}`, (url) => HttpClient.get(url));
HttpClient.get(url)
);
const loading = !data && !error; const loading = !data && !error;
const addComment = async (data: CreateCommentDto) => { const addComment = async (data: CreateCommentDto) => {

View File

@ -1,9 +1,9 @@
import type { IUser, IDocument } from "@think/domains"; import type { IUser, IDocument } from '@think/domains';
import useSWR from "swr"; import useSWR from 'swr';
import { useState, useCallback, useEffect } from "react"; import { useState, useCallback, useEffect } from 'react';
import { useAsyncLoading } from "hooks/useAsyncLoading"; import { useAsyncLoading } from 'hooks/useAsyncLoading';
import { HttpClient } from "services/HttpClient"; import { HttpClient } from 'services/HttpClient';
import { getPublicDocumentDetail } from "services/document"; import { getPublicDocumentDetail } from 'services/document';
interface IAuthority { interface IAuthority {
id: string; id: string;
@ -13,20 +13,18 @@ interface IAuthority {
editable: boolean; editable: boolean;
} }
type ICreateDocument = Partial<Pick<IDocument, "wikiId" | "parentDocumentId">>; type ICreateDocument = Partial<Pick<IDocument, 'wikiId' | 'parentDocumentId'>>;
type IDocumentWithAuth = { document: IDocument; authority: IAuthority }; type IDocumentWithAuth = { document: IDocument; authority: IAuthority };
type IUpdateDocument = Partial<Pick<IDocument, "title" | "content">>; type IUpdateDocument = Partial<Pick<IDocument, 'title' | 'content'>>;
/** /**
* *
* @returns * @returns
*/ */
export const useCreateDocument = () => { export const useCreateDocument = () => {
const [create, loading] = useAsyncLoading( const [create, loading] = useAsyncLoading((data: ICreateDocument): Promise<IDocument> => {
(data: ICreateDocument): Promise<IDocument> => { return HttpClient.post('/document/create', data);
return HttpClient.post("/document/create", data); });
}
);
return { create, loading }; return { create, loading };
}; };
@ -36,7 +34,7 @@ export const useCreateDocument = () => {
* @returns * @returns
*/ */
export const updateDocumentViews = (id: string) => { export const updateDocumentViews = (id: string) => {
return HttpClient.get("/document/views/" + id); return HttpClient.get('/document/views/' + id);
}; };
/** /**
@ -46,7 +44,7 @@ export const updateDocumentViews = (id: string) => {
*/ */
export const useDeleteDocument = (id) => { export const useDeleteDocument = (id) => {
const [deleteDocument, loading] = useAsyncLoading((): Promise<IDocument> => { const [deleteDocument, loading] = useAsyncLoading((): Promise<IDocument> => {
return HttpClient.delete("/document/delete/" + id); return HttpClient.delete('/document/delete/' + id);
}); });
return { deleteDocument, loading }; return { deleteDocument, loading };
}; };
@ -64,15 +62,13 @@ export const useDocumentDetail = (documentId, options = null) => {
); );
const loading = !data && !error; const loading = !data && !error;
const update = async (data: IUpdateDocument) => { const update = async (data: IUpdateDocument) => {
const res = await HttpClient.post("/document/update/" + documentId, data); const res = await HttpClient.post('/document/update/' + documentId, data);
mutate(); mutate();
return res; return res;
}; };
const toggleStatus = async ( const toggleStatus = async (data: Partial<Pick<IDocument, 'sharePassword'>>) => {
data: Partial<Pick<IDocument, "sharePassword">> const ret = await HttpClient.post('/document/share/' + documentId, data);
) => {
const ret = await HttpClient.post("/document/share/" + documentId, data);
mutate(); mutate();
return ret; return ret;
}; };
@ -85,9 +81,8 @@ export const useDocumentDetail = (documentId, options = null) => {
* @returns * @returns
*/ */
export const useRecentDocuments = () => { export const useRecentDocuments = () => {
const { data, error, mutate } = useSWR<IDocument[]>( const { data, error, mutate } = useSWR<IDocument[]>('/document/recent', (url) =>
"/document/recent", HttpClient.get(url)
(url) => HttpClient.get(url)
); );
const loading = !data && !error; const loading = !data && !error;
return { data, error, loading, refresh: mutate }; return { data, error, loading, refresh: mutate };
@ -99,18 +94,16 @@ export const useRecentDocuments = () => {
* @returns * @returns
*/ */
export const useDocumentStar = (documentId) => { export const useDocumentStar = (documentId) => {
const { data, error, mutate } = useSWR<boolean>( const { data, error, mutate } = useSWR<boolean>(`/collector/check/${documentId}`, () =>
`/collector/check/${documentId}`, HttpClient.post(`/collector/check`, {
() => type: 'document',
HttpClient.post(`/collector/check`, { targetId: documentId,
type: "document", })
targetId: documentId,
})
); );
const toggleStar = async () => { const toggleStar = async () => {
await HttpClient.post("/collector/toggle/", { await HttpClient.post('/collector/toggle/', {
type: "document", type: 'document',
targetId: documentId, targetId: documentId,
}); });
mutate(); mutate();
@ -124,9 +117,8 @@ export const useDocumentStar = (documentId) => {
* @returns * @returns
*/ */
export const useStaredDocuments = () => { export const useStaredDocuments = () => {
const { data, error, mutate } = useSWR<IDocument[]>( const { data, error, mutate } = useSWR<IDocument[]>('/collector/documents', (url) =>
"/collector/documents", HttpClient.post(url)
(url) => HttpClient.post(url)
); );
const loading = !data && !error; const loading = !data && !error;
@ -141,13 +133,11 @@ export const useStaredDocuments = () => {
export const usePublicDocument = (documentId: string) => { export const usePublicDocument = (documentId: string) => {
const [fetch] = useAsyncLoading(getPublicDocumentDetail); const [fetch] = useAsyncLoading(getPublicDocumentDetail);
const [document, setDocument] = useState<IDocument | null>(null); const [document, setDocument] = useState<IDocument | null>(null);
const [error, setError] = useState<(Error & { statusCode?: number }) | null>( const [error, setError] = useState<(Error & { statusCode?: number }) | null>(null);
null
);
const loading = !document && !error; const loading = !document && !error;
const queryData = useCallback( const queryData = useCallback(
(sharePassword = "") => { (sharePassword = '') => {
fetch(documentId, { sharePassword }) fetch(documentId, { sharePassword })
.then((doc) => { .then((doc) => {
setDocument(doc); setDocument(doc);
@ -221,16 +211,10 @@ export const useCollaborationDocument = (documentId) => {
* @param isShare 访 * @param isShare 访
* @returns * @returns
*/ */
export const useChildrenDocument = ({ export const useChildrenDocument = ({ wikiId, documentId, isShare = false }) => {
wikiId,
documentId,
isShare = false,
}) => {
const { data, error, mutate } = useSWR<Array<IDocument>>( const { data, error, mutate } = useSWR<Array<IDocument>>(
isShare ? "/document/public/children" : `/document/children`, isShare ? '/document/public/children' : `/document/children`,
wikiId || documentId wikiId || documentId ? (url) => HttpClient.post(url, { wikiId, documentId, isShare }) : null,
? (url) => HttpClient.post(url, { wikiId, documentId, isShare })
: null,
{ shouldRetryOnError: false } { shouldRetryOnError: false }
); );
const loading = !data && !error; const loading = !data && !error;

View File

@ -1,7 +1,7 @@
import type { IMessage } from "@think/domains"; import type { IMessage } from '@think/domains';
import { useState } from "react"; import { useState } from 'react';
import useSWR from "swr"; import useSWR from 'swr';
import { HttpClient } from "services/HttpClient"; import { HttpClient } from 'services/HttpClient';
/** /**
* *

View File

@ -1,7 +1,7 @@
import type { ITemplate } from "@think/domains"; import type { ITemplate } from '@think/domains';
import { useState } from "react"; import { useState } from 'react';
import useSWR from "swr"; import useSWR from 'swr';
import { HttpClient } from "services/HttpClient"; import { HttpClient } from 'services/HttpClient';
export const usePublicTemplates = () => { export const usePublicTemplates = () => {
const [page, setPage] = useState(1); const [page, setPage] = useState(1);

View File

@ -1,35 +1,31 @@
import { useEffect } from "react"; import { useEffect } from 'react';
import useSWR from "swr"; import useSWR from 'swr';
import { setStorage, getStorage } from "helpers/storage"; import { setStorage, getStorage } from 'helpers/storage';
export enum Width { export enum Width {
"standardWidth" = "standardWidth", 'standardWidth' = 'standardWidth',
"fullWidth" = "fullWidth", 'fullWidth' = 'fullWidth',
} }
const WIDTH_KEY = "document-style-width"; const WIDTH_KEY = 'document-style-width';
const FONT_SIZE_KEY = "document-style-font-size"; const FONT_SIZE_KEY = 'document-style-font-size';
const DEFAULT_WIDTH = Width.standardWidth; const DEFAULT_WIDTH = Width.standardWidth;
const DEFAULT_FONT_SIZE = 16; const DEFAULT_FONT_SIZE = 16;
export const useDocumentStyle = () => { export const useDocumentStyle = () => {
const { data, mutate } = useSWR( const { data, mutate } = useSWR(`/fe/mock/${WIDTH_KEY}/${FONT_SIZE_KEY}`, () => {
`/fe/mock/${WIDTH_KEY}/${FONT_SIZE_KEY}`, if (typeof window !== 'undefined') {
() => {
if (typeof window !== "undefined") {
return {
width: getStorage(WIDTH_KEY) || DEFAULT_WIDTH,
fontSize:
parseInt(getStorage(FONT_SIZE_KEY), 10) || DEFAULT_FONT_SIZE,
};
}
return { return {
width: DEFAULT_WIDTH, width: getStorage(WIDTH_KEY) || DEFAULT_WIDTH,
fontSize: DEFAULT_FONT_SIZE, fontSize: parseInt(getStorage(FONT_SIZE_KEY), 10) || DEFAULT_FONT_SIZE,
}; };
} }
);
return {
width: DEFAULT_WIDTH,
fontSize: DEFAULT_FONT_SIZE,
};
});
const setWidth = (width: Width) => { const setWidth = (width: Width) => {
setStorage(WIDTH_KEY, width); setStorage(WIDTH_KEY, width);

View File

@ -1,9 +1,9 @@
import { useEffect, useRef } from "react"; import { useEffect, useRef } from 'react';
import useSWR from "swr"; import useSWR from 'swr';
import { useWindowSize } from "hooks/useWindowSize"; import { useWindowSize } from 'hooks/useWindowSize';
import { setStorage, getStorage } from "helpers/storage"; import { setStorage, getStorage } from 'helpers/storage';
const key = "dragable-menu-width"; const key = 'dragable-menu-width';
export const MIN_WIDTH = 240; export const MIN_WIDTH = 240;
export const MAX_WIDTH = 600; export const MAX_WIDTH = 600;
@ -22,7 +22,7 @@ export const useDragableWidth = () => {
}; };
const toggleCollapsed = (collapsed = null) => { const toggleCollapsed = (collapsed = null) => {
const isBool = typeof collapsed === "boolean"; const isBool = typeof collapsed === 'boolean';
const nextCollapsed = isBool ? collapsed : !isCollapsed; const nextCollapsed = isBool ? collapsed : !isCollapsed;
let nextWidth = nextCollapsed ? COLLAPSED_WIDTH : MIN_WIDTH; let nextWidth = nextCollapsed ? COLLAPSED_WIDTH : MIN_WIDTH;
setStorage(key, nextWidth); setStorage(key, nextWidth);

View File

@ -1,5 +1,5 @@
import { IDocument } from "@think/domains"; import { IDocument } from '@think/domains';
import { HttpClient } from "./HttpClient"; import { HttpClient } from './HttpClient';
/** /**
* *
@ -7,7 +7,7 @@ import { HttpClient } from "./HttpClient";
* @returns * @returns
*/ */
export const updateDocumentViews = (id: string) => { export const updateDocumentViews = (id: string) => {
return HttpClient.get("/document/views/" + id); return HttpClient.get('/document/views/' + id);
}; };
/** /**
@ -18,9 +18,9 @@ export const updateDocumentViews = (id: string) => {
*/ */
export const getPublicDocumentDetail = ( export const getPublicDocumentDetail = (
id: string, id: string,
data: Partial<Pick<IDocument, "sharePassword">> data: Partial<Pick<IDocument, 'sharePassword'>>
): Promise<IDocument> => { ): Promise<IDocument> => {
return HttpClient.post("/document/public/detail/" + id, data); return HttpClient.post('/document/public/detail/' + id, data);
}; };
/** /**
@ -29,5 +29,5 @@ export const getPublicDocumentDetail = (
* @returns * @returns
*/ */
export const searchDocument = (keyword: string): Promise<IDocument[]> => { export const searchDocument = (keyword: string): Promise<IDocument[]> => {
return HttpClient.get("/document/search", { params: { keyword } }); return HttpClient.get('/document/search', { params: { keyword } });
}; };

View File

@ -1,18 +1,16 @@
import { HttpClient } from "./HttpClient"; import { HttpClient } from './HttpClient';
export const uploadFile = async (file: Blob): Promise<string> => { export const uploadFile = async (file: Blob): Promise<string> => {
if (process.env.ENABLE_ALIYUN_OSS) { if (process.env.ENABLE_ALIYUN_OSS) {
return Promise.reject( return Promise.reject(new Error('阿里云OSS配置不完善请自行实现上传文件'));
new Error("阿里云OSS配置不完善请自行实现上传文件")
);
} }
const formData = new FormData(); const formData = new FormData();
formData.append("file", file); formData.append('file', file);
return HttpClient.post("/file/upload", formData, { return HttpClient.post('/file/upload', formData, {
headers: { headers: {
"Content-Type": "multipart/form-data", 'Content-Type': 'multipart/form-data',
}, },
}); });
}; };

View File

@ -1,6 +1,6 @@
import type { IUser } from "@think/domains"; import type { IUser } from '@think/domains';
import { HttpClient } from "./HttpClient"; import { HttpClient } from './HttpClient';
export const register = (data: Partial<IUser>): Promise<IUser> => { export const register = (data: Partial<IUser>): Promise<IUser> => {
return HttpClient.post("/user/register", data); return HttpClient.post('/user/register', data);
}; };

View File

@ -14,11 +14,7 @@
"scripts": { "scripts": {
"build": "tsc --declaration" "build": "tsc --declaration"
}, },
"files": [ "files": ["lib", "src", "yaml"],
"lib",
"src",
"yaml"
],
"dependencies": { "dependencies": {
"js-yaml": "^4.1.0" "js-yaml": "^4.1.0"
} }

View File

@ -14,10 +14,7 @@
"scripts": { "scripts": {
"build": "tsc --declaration" "build": "tsc --declaration"
}, },
"files": [ "files": ["lib", "src"],
"lib",
"src"
],
"devDependencies": { "devDependencies": {
"typescript": "^4.5.5" "typescript": "^4.5.5"
} }

View File

@ -1,17 +1,17 @@
export const DEFAULT_WIKI_AVATAR = export const DEFAULT_WIKI_AVATAR =
"https://wipi.oss-cn-shanghai.aliyuncs.com/2022-02-01/default0-96.png"; 'https://wipi.oss-cn-shanghai.aliyuncs.com/2022-02-01/default0-96.png';
export const WIKI_AVATARS = [ export const WIKI_AVATARS = [
DEFAULT_WIKI_AVATAR, DEFAULT_WIKI_AVATAR,
"https://wipi.oss-cn-shanghai.aliyuncs.com/2022-02-01/default2-96.png", 'https://wipi.oss-cn-shanghai.aliyuncs.com/2022-02-01/default2-96.png',
"https://wipi.oss-cn-shanghai.aliyuncs.com/2022-02-01/default7-96.png", 'https://wipi.oss-cn-shanghai.aliyuncs.com/2022-02-01/default7-96.png',
"https://wipi.oss-cn-shanghai.aliyuncs.com/2022-02-01/default8-96.png", 'https://wipi.oss-cn-shanghai.aliyuncs.com/2022-02-01/default8-96.png',
"https://wipi.oss-cn-shanghai.aliyuncs.com/2022-02-01/default14-96.png", 'https://wipi.oss-cn-shanghai.aliyuncs.com/2022-02-01/default14-96.png',
"https://wipi.oss-cn-shanghai.aliyuncs.com/2022-02-01/default21-96.png", 'https://wipi.oss-cn-shanghai.aliyuncs.com/2022-02-01/default21-96.png',
"https://wipi.oss-cn-shanghai.aliyuncs.com/2022-02-01/default23-96.png", 'https://wipi.oss-cn-shanghai.aliyuncs.com/2022-02-01/default23-96.png',
"https://wipi.oss-cn-shanghai.aliyuncs.com/2022-02-01/default1-96%20(1).png", 'https://wipi.oss-cn-shanghai.aliyuncs.com/2022-02-01/default1-96%20(1).png',
"https://wipi.oss-cn-shanghai.aliyuncs.com/2022-02-01/default4-96.png", 'https://wipi.oss-cn-shanghai.aliyuncs.com/2022-02-01/default4-96.png',
"https://wipi.oss-cn-shanghai.aliyuncs.com/2022-02-01/default12-96.png", 'https://wipi.oss-cn-shanghai.aliyuncs.com/2022-02-01/default12-96.png',
"https://wipi.oss-cn-shanghai.aliyuncs.com/2022-02-01/default17-96.png", 'https://wipi.oss-cn-shanghai.aliyuncs.com/2022-02-01/default17-96.png',
"https://wipi.oss-cn-shanghai.aliyuncs.com/2022-02-01/default18-96.png", 'https://wipi.oss-cn-shanghai.aliyuncs.com/2022-02-01/default18-96.png',
]; ];

View File

@ -14,10 +14,7 @@
"scripts": { "scripts": {
"build": "tsc --declaration" "build": "tsc --declaration"
}, },
"files": [ "files": ["lib", "src"],
"lib",
"src"
],
"devDependencies": { "devDependencies": {
"typescript": "^4.5.5" "typescript": "^4.5.5"
} }

View File

@ -1,2 +1,2 @@
export * from "./models"; export * from './models';
export * from "./util"; export * from './util';

View File

@ -1,4 +1,4 @@
export enum CollectType { export enum CollectType {
document = "document", document = 'document',
wiki = "wiki", wiki = 'wiki',
} }

View File

@ -1,16 +1,16 @@
import { IUser } from "./user"; import { IUser } from './user';
import { IDocument } from "./document"; import { IDocument } from './document';
/** /**
* *
*/ */
export interface IComment { export interface IComment {
id: string; id: string;
parentCommentId?: IComment["id"]; parentCommentId?: IComment['id'];
documentId: IDocument["id"]; documentId: IDocument['id'];
createUserId: IUser["id"]; createUserId: IUser['id'];
createUser: IUser; createUser: IUser;
replyUserId?: IUser["id"]; replyUserId?: IUser['id'];
replyUser?: IUser; replyUser?: IUser;
html: string; html: string;
userAgent: string; userAgent: string;

View File

@ -1,12 +1,12 @@
import { IUser } from "./user"; import { IUser } from './user';
import { IWiki } from "./wiki"; import { IWiki } from './wiki';
/** /**
* *
*/ */
export enum DocumentStatus { export enum DocumentStatus {
private = "private", private = 'private',
public = "public", public = 'public',
} }
/** /**
@ -14,11 +14,11 @@ export enum DocumentStatus {
*/ */
export interface IDocument { export interface IDocument {
id: string; id: string;
wikiId: IWiki["id"]; wikiId: IWiki['id'];
isWikiHome: boolean; isWikiHome: boolean;
createUserId: IUser["id"]; createUserId: IUser['id'];
createUser: IUser; createUser: IUser;
parentDocumentId?: IDocument["id"]; parentDocumentId?: IDocument['id'];
title: string; title: string;
content: string; content: string;
status: DocumentStatus; status: DocumentStatus;
@ -34,8 +34,8 @@ export interface IDocument {
*/ */
export interface IAuthority { export interface IAuthority {
id: string; id: string;
documentId: IDocument["id"]; documentId: IDocument['id'];
userId: IUser["id"]; userId: IUser['id'];
readable: boolean; readable: boolean;
editable: boolean; editable: boolean;
} }

View File

@ -1,8 +1,8 @@
export * from "./user"; export * from './user';
export * from "./wiki"; export * from './wiki';
export * from "./document"; export * from './document';
export * from "./message"; export * from './message';
export * from "./template"; export * from './template';
export * from "./comment"; export * from './comment';
export * from "./collector"; export * from './collector';
export * from "./pagination"; export * from './pagination';

View File

@ -1,11 +1,11 @@
import { IUser } from "./user"; import { IUser } from './user';
/** /**
* *
*/ */
export interface IMessage { export interface IMessage {
id: string; id: string;
userId: IUser["id"]; userId: IUser['id'];
title: string; title: string;
message: string; message: string;
url: string; url: string;

View File

@ -1,11 +1,11 @@
import { IUser } from "./user"; import { IUser } from './user';
/** /**
* *
*/ */
export interface ITemplate { export interface ITemplate {
id: string; id: string;
createUserId: IUser["id"]; createUserId: IUser['id'];
createUser: IUser; createUser: IUser;
title: string; title: string;
content: string; content: string;

View File

@ -2,17 +2,17 @@
* *
*/ */
export enum UserRole { export enum UserRole {
normal = "normal", normal = 'normal',
admin = "admin", admin = 'admin',
superadmin = "superadmin", superadmin = 'superadmin',
} }
/** /**
* *
*/ */
export enum UserStatus { export enum UserStatus {
normal = "normal", normal = 'normal',
locked = "locked", locked = 'locked',
} }
/** /**

View File

@ -1,28 +1,28 @@
import { IUser } from "./user"; import { IUser } from './user';
/** /**
* *
*/ */
export enum WikiStatus { export enum WikiStatus {
private = "private", private = 'private',
public = "public", public = 'public',
} }
/** /**
* *
*/ */
export enum WikiUserStatus { export enum WikiUserStatus {
applying = "applying", applying = 'applying',
inviting = "inviting", inviting = 'inviting',
normal = "normal", normal = 'normal',
} }
/** /**
* *
*/ */
export enum WikiUserRole { export enum WikiUserRole {
normal = "normal", normal = 'normal',
admin = "admin", admin = 'admin',
} }
/** /**
@ -33,7 +33,7 @@ export interface IWiki {
name: string; name: string;
avatar: string; avatar: string;
description: string; description: string;
createUserId: IUser["id"]; createUserId: IUser['id'];
createUser: IUser; createUser: IUser;
status: WikiStatus; status: WikiStatus;
createdAt: Date; createdAt: Date;

View File

@ -1,10 +1,4 @@
import { import { WikiStatus, WikiUserRole, DocumentStatus, IWiki, IDocument } from './models';
WikiStatus,
WikiUserRole,
DocumentStatus,
IWiki,
IDocument,
} from "./models";
/** /**
* *
@ -12,11 +6,11 @@ import {
export const WIKI_STATUS_LIST = [ export const WIKI_STATUS_LIST = [
{ {
value: WikiStatus.private, value: WikiStatus.private,
label: "私有", label: '私有',
}, },
{ {
value: WikiStatus.public, value: WikiStatus.public,
label: "公开", label: '公开',
}, },
]; ];
@ -25,12 +19,12 @@ export const WIKI_STATUS_LIST = [
*/ */
export const WIKI_USER_ROLES = [ export const WIKI_USER_ROLES = [
{ {
value: "admin", value: 'admin',
label: "管理员", label: '管理员',
}, },
{ {
value: "normal", value: 'normal',
label: "成员", label: '成员',
}, },
]; ];
@ -40,11 +34,11 @@ export const WIKI_USER_ROLES = [
export const DOCUMENT_STATUS = [ export const DOCUMENT_STATUS = [
{ {
value: DocumentStatus.private, value: DocumentStatus.private,
label: "私有", label: '私有',
}, },
{ {
value: DocumentStatus.public, value: DocumentStatus.public,
label: "公开", label: '公开',
}, },
]; ];
@ -62,8 +56,7 @@ export const getWikiStatusText = (wiki: IWiki): string => {
* @param currentStatus wiki status * @param currentStatus wiki status
* @returns * @returns
*/ */
export const isPublicWiki = (currentStatus: IWiki["status"]) => export const isPublicWiki = (currentStatus: IWiki['status']) => currentStatus === WikiStatus.public;
currentStatus === WikiStatus.public;
/** /**
* *
@ -79,5 +72,5 @@ export const getWikiUserRoleText = (role: WikiUserRole) => {
* @param currentStatus document status * @param currentStatus document status
* @returns * @returns
*/ */
export const isPublicDocument = (currentStatus: IDocument["status"]) => export const isPublicDocument = (currentStatus: IDocument['status']) =>
currentStatus === DocumentStatus.public; currentStatus === DocumentStatus.public;

View File

@ -76,19 +76,13 @@
"typescript": "^4.3.5" "typescript": "^4.3.5"
}, },
"jest": { "jest": {
"moduleFileExtensions": [ "moduleFileExtensions": ["js", "json", "ts"],
"js",
"json",
"ts"
],
"rootDir": "src", "rootDir": "src",
"testRegex": ".*\\.spec\\.ts$", "testRegex": ".*\\.spec\\.ts$",
"transform": { "transform": {
"^.+\\.(t|j)s$": "ts-jest" "^.+\\.(t|j)s$": "ts-jest"
}, },
"collectCoverageFrom": [ "collectCoverageFrom": ["**/*.(t|j)s"],
"**/*.(t|j)s"
],
"coverageDirectory": "../coverage", "coverageDirectory": "../coverage",
"testEnvironment": "node" "testEnvironment": "node"
} }

View File

@ -7,6 +7,7 @@ importers:
concurrently: ^7.0.0 concurrently: ^7.0.0
cross-env: ^7.0.3 cross-env: ^7.0.3
fs-extra: ^10.0.0 fs-extra: ^10.0.0
prettier: ^2.3.2
rimraf: ^3.0.2 rimraf: ^3.0.2
typescript: ^4.5.5 typescript: ^4.5.5
dependencies: dependencies:
@ -15,6 +16,7 @@ importers:
fs-extra: 10.0.0 fs-extra: 10.0.0
rimraf: 3.0.2 rimraf: 3.0.2
devDependencies: devDependencies:
prettier: 2.5.1
typescript: 4.5.5 typescript: 4.5.5
packages/client: packages/client: