@wangtaizong/components 1.0.6 → 1.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/.changeset/README.md +8 -0
  2. package/.changeset/config.json +11 -0
  3. package/.dumirc.ts +28 -0
  4. package/.editorconfig +13 -0
  5. package/.eslintrc.js +3 -0
  6. package/.husky/commit-msg +5 -0
  7. package/.husky/pre-commit +8 -0
  8. package/.husky/pre-push +8 -0
  9. package/.prettierignore +2 -0
  10. package/.prettierrc.js +19 -0
  11. package/.stylelintrc +3 -0
  12. package/.vscode/settings.json +3 -0
  13. package/LICENSE +21 -0
  14. package/README.md +0 -52
  15. package/commitlint.config.js +21 -0
  16. package/docs/changelogs/index.md +9 -0
  17. package/docs/components/index.md +1 -0
  18. package/docs/guide/install.md +39 -0
  19. package/docs/index.md +21 -0
  20. package/docs/utils/index.md +1 -0
  21. package/lerna.json +8 -0
  22. package/package.json +66 -69
  23. package/packages/components/CHANGELOG.md +0 -0
  24. package/packages/components/package.json +48 -0
  25. package/packages/components/rollup.config.mjs +108 -0
  26. package/packages/components/src/Button/index.md +13 -0
  27. package/packages/components/src/Button/index.tsx +34 -0
  28. package/packages/components/src/Icon/index.md +81 -0
  29. package/packages/components/src/Icon/index.tsx +34 -0
  30. package/packages/components/src/Upload/index.md +209 -0
  31. package/packages/components/src/Upload/index.tsx +218 -0
  32. package/packages/components/src/antd/index.md +12 -0
  33. package/packages/components/src/antd/index.tsx +2 -0
  34. package/packages/components/src/index.md +23 -0
  35. package/packages/components/src/index.ts +5 -0
  36. package/packages/components/tsconfig.json +32 -0
  37. package/packages/utils/README.md +11 -0
  38. package/packages/utils/package.json +35 -0
  39. package/packages/utils/rollup.config.mjs +63 -0
  40. package/packages/utils/src/CHRRequest/index.md +59 -0
  41. package/packages/utils/src/CHRRequest/index.ts +94 -0
  42. package/packages/utils/src/index.ts +17 -0
  43. package/packages/utils/tsconfig.json +28 -0
  44. package/pnpm-workspace.yaml +8 -0
  45. package/public/favicon.ico +0 -0
  46. package/public/logo.webp +0 -0
  47. package/tsconfig.json +14 -0
  48. package/dist/Add.d.ts +0 -2
  49. package/dist/base-80a1f760-22b3368a.js +0 -23
  50. package/dist/components/editor/MonacoEditor.d.ts +0 -2
  51. package/dist/components/editor/WEditor.d.ts +0 -13
  52. package/dist/components/editor/sandpack-file-explorer/CreateNewNode.d.ts +0 -3
  53. package/dist/components/editor/sandpack-file-explorer/Example.d.ts +0 -4
  54. package/dist/components/editor/sandpack-file-explorer/FileTreeExplorer.d.ts +0 -1
  55. package/dist/components/editor/sandpack-file-explorer/SandpackFilesProvider.d.ts +0 -24
  56. package/dist/components/editor/sandpack-file-explorer/SingleInputForm.d.ts +0 -8
  57. package/dist/components/editor/sandpack-file-explorer/index.d.ts +0 -6
  58. package/dist/components/editor/sandpack-file-explorer/types.d.ts +0 -18
  59. package/dist/components/editor/sandpack-file-explorer/utils/arrayToObject.d.ts +0 -1
  60. package/dist/components/editor/sandpack-file-explorer/utils/buildPath.d.ts +0 -2
  61. package/dist/components/editor/sandpack-file-explorer/utils/deepMerge.d.ts +0 -2
  62. package/dist/components/editor/sandpack-file-explorer/utils/deleteKeys.d.ts +0 -4
  63. package/dist/components/editor/sandpack-file-explorer/utils/directoryFileMap.d.ts +0 -3
  64. package/dist/components/editor/sandpack-file-explorer/utils/fiindParentPath.d.ts +0 -1
  65. package/dist/components/editor/sandpack-file-explorer/utils/flattenObject.d.ts +0 -2
  66. package/dist/components/editor/sandpack-file-explorer/utils/getEntryFile.d.ts +0 -2
  67. package/dist/components/editor/sandpack-file-explorer/utils/getRemovedKeys.d.ts +0 -5
  68. package/dist/components/editor/sandpack-file-explorer/utils/index.d.ts +0 -12
  69. package/dist/components/editor/sandpack-file-explorer/utils/mergeHierarchicalArray.d.ts +0 -2
  70. package/dist/components/editor/sandpack-file-explorer/utils/removeHiddenEntries.d.ts +0 -3
  71. package/dist/components/editor/sandpack-file-explorer/utils/toHierarchicalArray.d.ts +0 -3
  72. package/dist/components/editor/utils/map.d.ts +0 -4
  73. package/dist/consoleHook-59e792cb-0fba2dba.js +0 -168
  74. package/dist/index-3417dbcd.js +0 -316
  75. package/dist/index-585bceb7-39d610b1.js +0 -8813
  76. package/dist/index-6426660e.js +0 -32172
  77. package/dist/index-a63bd288.js +0 -1104
  78. package/dist/index.d.ts +0 -2
  79. package/dist/index.es.js +0 -5
  80. package/dist/index.umd.js +0 -779
@@ -0,0 +1,63 @@
1
+ import commonjs from '@rollup/plugin-commonjs';
2
+ import { nodeResolve } from '@rollup/plugin-node-resolve';
3
+ import typescript from '@rollup/plugin-typescript';
4
+ import { defineConfig } from 'rollup';
5
+ import { terser } from 'rollup-plugin-terser';
6
+
7
+ const DIR_MAP = {
8
+ ESM: 'es',
9
+ CJS: 'lib',
10
+ UMD: 'dist',
11
+ };
12
+
13
+ const baseConfig = (tsConfig) => ({
14
+ input: 'src/index.ts',
15
+ plugins: [
16
+ nodeResolve({ extensions: ['.ts'] }),
17
+ commonjs(),
18
+ typescript(tsConfig),
19
+ ],
20
+ });
21
+
22
+ const esmConfig = defineConfig({
23
+ ...baseConfig({
24
+ declaration: true,
25
+ declarationDir: DIR_MAP.ESM,
26
+ }),
27
+ output: {
28
+ dir: DIR_MAP.ESM,
29
+ format: 'esm',
30
+ preserveModules: true,
31
+ },
32
+ });
33
+
34
+ const cjsConfig = defineConfig({
35
+ ...baseConfig({
36
+ declaration: true,
37
+ declarationDir: DIR_MAP.CJS,
38
+ }),
39
+ output: {
40
+ dir: DIR_MAP.CJS,
41
+ format: 'cjs',
42
+ exports: 'named',
43
+ },
44
+ });
45
+
46
+ const umdConfig = defineConfig({
47
+ ...baseConfig(),
48
+ output: [
49
+ {
50
+ file: DIR_MAP.UMD + '/index.js',
51
+ format: 'umd',
52
+ name: 'KcUtils',
53
+ },
54
+ {
55
+ file: DIR_MAP.UMD + '/index.min.js',
56
+ format: 'umd',
57
+ name: 'KcUtils',
58
+ plugins: [terser()],
59
+ },
60
+ ],
61
+ });
62
+
63
+ export default defineConfig([esmConfig, cjsConfig, umdConfig]);
@@ -0,0 +1,59 @@
1
+ # CHRRequest
2
+
3
+ ## 代码演示
4
+
5
+ ### 基本用法
6
+
7
+ ```jsx
8
+ import { alovaGet, useRequest } from '@chr/utils';
9
+ import { CHRButton } from '@chr/components';
10
+
11
+ export default function PostExample() {
12
+ const { loading, data, error, send } = useRequest(
13
+ () =>
14
+ alovaGet('/api/dd', {
15
+ meta: {
16
+ ignoreAuth: true,
17
+ },
18
+ }),
19
+ {
20
+ immediate: false,
21
+ initialData: {},
22
+ },
23
+ );
24
+
25
+ if (!data.id) {
26
+ return (
27
+ <div>
28
+ <CHRButton onClick={() => send()}>请求</CHRButton>
29
+ {loading && <div>加载中...</div>}
30
+ {error && <div>加载失败:{error.message}</div>}
31
+ </div>
32
+ );
33
+ }
34
+
35
+ // 有数据时展示详情
36
+ return (
37
+ <div>
38
+ <CHRButton onClick={() => send()}>请求</CHRButton>
39
+ <h2>文章详情</h2>
40
+ <p>
41
+ <strong>ID:</strong>
42
+ {data.id}
43
+ </p>
44
+ <p>
45
+ <strong>用户ID:</strong>
46
+ {data.userId}
47
+ </p>
48
+ <p>
49
+ <strong>标题:</strong>
50
+ {data.title}
51
+ </p>
52
+ <p>
53
+ <strong>内容:</strong>
54
+ </p>
55
+ <p>{data.body}</p>
56
+ </div>
57
+ );
58
+ }
59
+ ```
@@ -0,0 +1,94 @@
1
+ import { createAlova, RequestBody } from 'alova';
2
+ import { useRequest } from 'alova/client';
3
+ import adapterFetch from 'alova/fetch';
4
+ import ReactHook from 'alova/react';
5
+ const getToken = () => localStorage.getItem('token');
6
+
7
+ export interface AlovaClientOptions {
8
+ baseURL: string;
9
+ timeout?: number;
10
+ cacheFor?: any;
11
+ beforeRequest?: (method: any) => void;
12
+ responded?: any;
13
+ }
14
+
15
+ class AlovaClient {
16
+ private instance: ReturnType<typeof createAlova>;
17
+
18
+ constructor(options: AlovaClientOptions) {
19
+ const {
20
+ baseURL,
21
+ timeout = 10000,
22
+ cacheFor = { GET: 2000 },
23
+ beforeRequest,
24
+ responded,
25
+ } = options;
26
+ this.instance = createAlova({
27
+ baseURL,
28
+ statesHook: ReactHook,
29
+ requestAdapter: adapterFetch(),
30
+ timeout,
31
+ cacheFor,
32
+ beforeRequest: (method) => {
33
+ method.config.headers = method.config.headers || {};
34
+ method.config.headers['Content-Type'] =
35
+ 'application/json;charset=utf-8';
36
+
37
+ if (beforeRequest) {
38
+ beforeRequest(method);
39
+ return;
40
+ }
41
+
42
+ if (method.meta?.ignoreAuth) return;
43
+ const token = getToken();
44
+ if (token) {
45
+ method.config.headers['Authorization'] = `Bearer ${token}`;
46
+ }
47
+ },
48
+ responded: responded || {
49
+ onSuccess: async (response) => {
50
+ const json = await response.json();
51
+ if (response.status !== 200) {
52
+ // antd.message.error(json.msg || '请求失败');
53
+ return Promise.reject(json.message || '请求失败');
54
+ }
55
+ return Promise.resolve(json);
56
+ },
57
+ onError: async (error) => {
58
+ // antd.message.error(error.message);
59
+ return Promise.reject(error);
60
+ },
61
+ },
62
+ }) as any;
63
+ }
64
+
65
+ get<T = any>(url: string, config?: RequestInit) {
66
+ return this.instance.Get<T>(url, config);
67
+ }
68
+
69
+ post<T = any>(url: string, data?: RequestBody, config?: RequestInit) {
70
+ return this.instance.Post<T>(url, data, config);
71
+ }
72
+
73
+ put<T = any>(url: string, data?: RequestBody, config?: RequestInit) {
74
+ return this.instance.Put<T>(url, data, config);
75
+ }
76
+
77
+ delete<T = any>(url: string, data?: RequestBody, config?: RequestInit) {
78
+ return this.instance.Delete<T>(url, data, config);
79
+ }
80
+
81
+ getInstance() {
82
+ return this.instance;
83
+ }
84
+ }
85
+
86
+ const defaultBaseURL = 'http://localhost:3000';
87
+ const defaultClient = new AlovaClient({ baseURL: defaultBaseURL });
88
+
89
+ export const alovaGet = defaultClient.get.bind(defaultClient);
90
+ export const alovaPost = defaultClient.post.bind(defaultClient);
91
+ export const alovaPut = defaultClient.put.bind(defaultClient);
92
+ export const alovaDelete = defaultClient.delete.bind(defaultClient);
93
+ export { AlovaClient, useRequest };
94
+ export default defaultClient;
@@ -0,0 +1,17 @@
1
+ import CHRRequest, {
2
+ AlovaClient,
3
+ alovaDelete,
4
+ alovaGet,
5
+ alovaPost,
6
+ alovaPut,
7
+ useRequest,
8
+ } from './CHRRequest';
9
+ export {
10
+ AlovaClient,
11
+ alovaDelete,
12
+ alovaGet,
13
+ alovaPost,
14
+ alovaPut,
15
+ CHRRequest,
16
+ useRequest,
17
+ };
@@ -0,0 +1,28 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES5",
4
+ "module": "ESNext",
5
+ "moduleResolution": "node",
6
+ "baseUrl": ".",
7
+
8
+ "jsx": "react-jsx",
9
+ "jsxImportSource": "react",
10
+
11
+ "skipLibCheck": true,
12
+ "types": ["react", "react-dom"],
13
+
14
+ "strict": true,
15
+ "noImplicitAny": false,
16
+ "forceConsistentCasingInFileNames": true,
17
+
18
+ "esModuleInterop": true,
19
+ "allowSyntheticDefaultImports": true,
20
+
21
+ "sourceMap": true,
22
+ "inlineSources": true
23
+ },
24
+
25
+ /* 文件范围控制 */
26
+ "include": ["src/**/*.ts", "src/**/*.tsx", "types/**/*.d.ts"],
27
+ "exclude": ["node_modules", "dist", "**/__tests__/*"]
28
+ }
@@ -0,0 +1,8 @@
1
+ packages:
2
+ - 'packages/*'
3
+
4
+ catalog:
5
+ react: ^18.3.1
6
+ react-dom: ^18.3.1
7
+ antd: ^6.3.3
8
+ alova: 3.5.1
Binary file
Binary file
package/tsconfig.json ADDED
@@ -0,0 +1,14 @@
1
+ {
2
+ "compilerOptions": {
3
+ "sourceMap": true,
4
+ "strict": true,
5
+ "noImplicitAny": true,
6
+ "baseUrl": ".",
7
+ "paths": {
8
+ "@kc-components/*": ["packages/*/src"]
9
+ },
10
+ "esModuleInterop": true,
11
+ "experimentalDecorators": true
12
+ },
13
+ "include": [".dumirc.ts", "packages/**/*.{ts,tsx}"]
14
+ }
package/dist/Add.d.ts DELETED
@@ -1,2 +0,0 @@
1
- declare const Add: () => import("react/jsx-runtime").JSX.Element;
2
- export default Add;
@@ -1,23 +0,0 @@
1
- import { e as n } from "./index-6426660e.js";
2
- var p = (
3
- /** @class */
4
- function() {
5
- function o(t, i, e) {
6
- e === void 0 && (e = {}), this.status = "idle", this.options = e, this.sandboxSetup = i, this.iframeSelector = t;
7
- }
8
- return o.prototype.updateOptions = function(t) {
9
- n(this.options, t) || (this.options = t, this.updateSandbox());
10
- }, o.prototype.updateSandbox = function(t, i) {
11
- throw t === void 0 && (t = this.sandboxSetup), Error("Method not implemented");
12
- }, o.prototype.destroy = function() {
13
- throw Error("Method not implemented");
14
- }, o.prototype.dispatch = function(t) {
15
- throw Error("Method not implemented");
16
- }, o.prototype.listen = function(t) {
17
- throw Error("Method not implemented");
18
- }, o;
19
- }()
20
- );
21
- export {
22
- p as S
23
- };
@@ -1,2 +0,0 @@
1
- declare const MonacoEditor: (props: any) => import("react/jsx-runtime").JSX.Element;
2
- export default MonacoEditor;
@@ -1,13 +0,0 @@
1
- import { HTMLAttributes, ReactNode } from "react";
2
- import { SandpackPredefinedTemplate } from "@codesandbox/sandpack-react";
3
- interface MyEditorProps extends HTMLAttributes<HTMLDivElement> {
4
- type?: SandpackPredefinedTemplate;
5
- showConsole?: boolean;
6
- files?: {
7
- [key: string]: string;
8
- };
9
- children: ReactNode;
10
- [key: string]: any;
11
- }
12
- declare const WEditor: ({ type, children, showConsole, files, className, style, editorRef, ...restProps }: MyEditorProps) => import("react/jsx-runtime").JSX.Element;
13
- export default WEditor;
@@ -1,3 +0,0 @@
1
- export declare const CreateNewNode: ({ dir }: {
2
- dir?: boolean;
3
- }) => import("react/jsx-runtime").JSX.Element;
@@ -1,4 +0,0 @@
1
- export type ExampleProps = {
2
- text?: String;
3
- };
4
- export declare function Example(props: ExampleProps): import("react/jsx-runtime").JSX.Element;
@@ -1 +0,0 @@
1
- export declare const FileTreeExplorer: () => import("react/jsx-runtime").JSX.Element;
@@ -1,24 +0,0 @@
1
- import { SandpackFiles } from '@codesandbox/sandpack-react';
2
- import { DropOptions } from '@minoru/react-dnd-treeview';
3
- import type { FC, PropsWithChildren } from 'react';
4
- import React from 'react';
5
- import type { Item } from './types';
6
- export declare const useSandpackFiles: () => {
7
- addFile: (pathOrFiles: Record<string, string> | SandpackFiles, code?: string | undefined) => Promise<void>;
8
- buildPath: (item: Item, arr: Item[]) => string;
9
- deleteFile: (file: string | string[]) => Promise<void>;
10
- moveFiles: (fileMap: Record<string, string>) => void;
11
- onFileMoved: ({ node, newTree, }: {
12
- newTree: Item[];
13
- node: DropOptions<{
14
- path: string;
15
- }>;
16
- }) => Promise<void>;
17
- openDirs: string[];
18
- setOpenDirs: React.Dispatch<React.SetStateAction<string[]>>;
19
- setTreeData: React.Dispatch<React.SetStateAction<any[]>>;
20
- treeData: any[];
21
- };
22
- export declare const SandpackFilesProvider: FC<PropsWithChildren & {
23
- onMoveFile?: (fileMap: Record<string, string>) => void;
24
- }>;
@@ -1,8 +0,0 @@
1
- import { SandpackBundlerFiles } from './types';
2
- export declare const SingleInputForm: ({ onSubmit, onBlur, isDirectory, files, currentPath, }: {
3
- currentPath?: string;
4
- files: SandpackBundlerFiles;
5
- isDirectory?: boolean;
6
- onBlur: () => void;
7
- onSubmit: (value: string) => void;
8
- }) => import("react/jsx-runtime").JSX.Element;
@@ -1,6 +0,0 @@
1
- export { useSandpackFiles, SandpackFilesProvider, } from "./SandpackFilesProvider";
2
- export declare const SandpackFileTree: () => import("react/jsx-runtime").JSX.Element;
3
- type Props = {
4
- onMoveFile?: ((fileMap: Record<string, string>) => void) | undefined;
5
- };
6
- export declare const SandpackFileExplorer: (props: Props) => import("react/jsx-runtime").JSX.Element;
@@ -1,18 +0,0 @@
1
- export interface SandpackBundlerFile {
2
- active?: boolean;
3
- code: string;
4
- hidden?: boolean;
5
- readOnly?: boolean;
6
- }
7
- export type SandpackBundlerFiles = Record<string, SandpackBundlerFile>;
8
- export type Item = {
9
- children?: Item[];
10
- data: {
11
- path: string;
12
- };
13
- droppable: boolean;
14
- id: string;
15
- parent: string;
16
- text: string;
17
- };
18
- export type HierarchicalData = Record<number, Item>;
@@ -1 +0,0 @@
1
- export declare function arrayToObject(arr: any[]): any;
@@ -1,2 +0,0 @@
1
- import type { Item } from '../types';
2
- export declare const buildPath: (item: Partial<Item>, arr: Item[]) => string;
@@ -1,2 +0,0 @@
1
- import type { SandpackBundlerFiles } from '../types';
2
- export declare function deepMerge(files: SandpackBundlerFiles, obj1: any, obj2: any, path: string): any;
@@ -1,4 +0,0 @@
1
- import type { SandpackBundlerFiles } from '../types';
2
- export declare const deleteKeys: (obj: Record<string, string> | SandpackBundlerFiles, keysToDelete: string[]) => {
3
- [k: string]: any;
4
- };
@@ -1,3 +0,0 @@
1
- import { SandpackFiles } from '@codesandbox/sandpack-react';
2
- import type { SandpackBundlerFiles } from '../types';
3
- export declare const directoryFileMap: (files: SandpackBundlerFiles | Record<string, string> | SandpackFiles, overrides?: Record<string, string> | string | SandpackFiles) => {};
@@ -1 +0,0 @@
1
- export declare function findParentPath(obj: Record<string, any>, parentId: string): string;
@@ -1,2 +0,0 @@
1
- import { SandpackBundlerFile } from '../types';
2
- export declare function flattenObject(obj: Record<string, SandpackBundlerFile>): void;
@@ -1,2 +0,0 @@
1
- import type { SandpackBundlerFiles } from '../types';
2
- export declare const getEntryFile: (files: SandpackBundlerFiles) => string;
@@ -1,5 +0,0 @@
1
- export declare function getRemovedKeys(original: {
2
- [key: string]: any;
3
- }, updated: {
4
- [key: string]: any;
5
- }): string[];
@@ -1,12 +0,0 @@
1
- export * from './arrayToObject';
2
- export * from './deepMerge';
3
- export * from './deleteKeys';
4
- export * from './directoryFileMap';
5
- export * from './toHierarchicalArray';
6
- export * from './buildPath';
7
- export * from './fiindParentPath';
8
- export * from './flattenObject';
9
- export * from './getEntryFile';
10
- export * from './getRemovedKeys';
11
- export * from './mergeHierarchicalArray';
12
- export * from './removeHiddenEntries';
@@ -1,2 +0,0 @@
1
- import type { Item, SandpackBundlerFiles } from '../types';
2
- export declare function mergeHierarchicalArray(sandpackFiles: SandpackBundlerFiles, arr: Item[]): SandpackBundlerFiles;
@@ -1,3 +0,0 @@
1
- export declare function removeHiddenEntries(obj: {
2
- [key: string]: any;
3
- }): void;
@@ -1,3 +0,0 @@
1
- export declare const toHierarchicalArray: (obj: {
2
- [key: string]: any;
3
- }, parentId?: string, arr?: any[]) => any[];
@@ -1,4 +0,0 @@
1
- declare const fileTypeMap: {
2
- [key: string]: string;
3
- };
4
- export default fileTypeMap;