@wangtaizong/components 1.0.6 → 1.0.8

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,8 @@
1
+ # Changesets
2
+
3
+ Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
4
+ with multi-package repos, or single-package repos to help you version and publish your code. You can
5
+ find the full documentation for it [in our repository](https://github.com/changesets/changesets)
6
+
7
+ We have a quick list of common questions to get you started engaging with this project in
8
+ [our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)
@@ -0,0 +1,11 @@
1
+ {
2
+ "$schema": "https://unpkg.com/@changesets/config@3.1.1/schema.json",
3
+ "changelog": "@changesets/cli/changelog",
4
+ "commit": false,
5
+ "fixed": [],
6
+ "linked": [],
7
+ "access": "restricted",
8
+ "baseBranch": "main",
9
+ "updateInternalDependencies": "patch",
10
+ "ignore": []
11
+ }
package/.dumirc.ts ADDED
@@ -0,0 +1,28 @@
1
+ import { defineConfig } from 'dumi';
2
+ import path from 'path';
3
+
4
+ export default defineConfig({
5
+ outputPath: 'docs-dist',
6
+ autoAlias: false,
7
+ alias: {
8
+ '@chr/components': path.join(__dirname, 'packages/components/src'),
9
+ '@chr/utils': path.join(__dirname, 'packages/utils/src'),
10
+ '@chr/hooks': path.join(__dirname, 'packages/hooks/src'),
11
+ },
12
+ themeConfig: {
13
+ name: 'chr',
14
+ nav: [
15
+ { title: '介绍', link: '/guide/install' },
16
+ { title: '组件', link: '/components' },
17
+ { title: '方法', link: '/utils' },
18
+ { title: '更新日志', link: '/changelogs' },
19
+ ],
20
+ },
21
+ resolve: {
22
+ atomDirs: [
23
+ { type: 'component', dir: 'packages/components/src' },
24
+ { type: 'utils', dir: 'packages/utils/src' },
25
+ { type: 'hooks', dir: 'packages/hooks/src' },
26
+ ],
27
+ },
28
+ });
package/.editorconfig ADDED
@@ -0,0 +1,13 @@
1
+ # http://editorconfig.org
2
+ root = true
3
+
4
+ [*]
5
+ indent_style = space
6
+ indent_size = 2
7
+ end_of_line = lf
8
+ charset = utf-8
9
+ trim_trailing_whitespace = true
10
+ insert_final_newline = true
11
+
12
+ [*.md]
13
+ trim_trailing_whitespace = false
package/.eslintrc.js ADDED
@@ -0,0 +1,3 @@
1
+ module.exports = {
2
+ extends: require.resolve('@umijs/lint/dist/config/eslint'),
3
+ };
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env sh
2
+ . "$(dirname -- "$0")/_/husky.sh"
3
+
4
+ npx commitlint --edit "${1}"
5
+ npx --no-install commitlint --edit .git/COMMIT_EDITMSG
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env sh
2
+ . "$(dirname -- "$0")/_/husky.sh"
3
+
4
+ npx lint-staged
5
+ if [ -z "$(git diff --cached --name-only .changeset/)" ]; then
6
+ echo "错误:必须创建 Changeset 文件!"
7
+ exit 1
8
+ fi
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env sh
2
+ . "$(dirname -- "$0")/_/husky.sh"
3
+
4
+ pnpm cs:status | grep "No changesets present"
5
+ if [ $? -eq 0 ]; then
6
+ echo "错误:存在未处理的 Changeset 文件!"
7
+ exit 1
8
+ fi
@@ -0,0 +1,2 @@
1
+ /dist
2
+ *.yaml
package/.prettierrc.js ADDED
@@ -0,0 +1,19 @@
1
+ module.exports = {
2
+ pluginSearchDirs: false,
3
+ plugins: [
4
+ require.resolve('prettier-plugin-organize-imports'),
5
+ require.resolve('prettier-plugin-packagejson'),
6
+ ],
7
+ printWidth: 80,
8
+ proseWrap: 'never',
9
+ singleQuote: true,
10
+ trailingComma: 'all',
11
+ overrides: [
12
+ {
13
+ files: '*.md',
14
+ options: {
15
+ proseWrap: 'preserve',
16
+ },
17
+ },
18
+ ],
19
+ };
package/.stylelintrc ADDED
@@ -0,0 +1,3 @@
1
+ {
2
+ "extends": "@umijs/lint/dist/config/stylelint"
3
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "cSpell.words": ["Cascader", "dumirc", "Formily", "kincy", "rollup", "umijs"]
3
+ }
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) kincy
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,52 +0,0 @@
1
- # EverUI
2
-
3
- 前端业务组件库项目
4
-
5
- 框架:react + vite + storybook
6
-
7
- [story文档 ](https://storybook.js.org/docs/react/addons/addons-api#addonssetconfigconfig)
8
-
9
- ### 开发
10
- ```
11
- yarn storybook
12
- ```
13
-
14
- ### 打包
15
- ```
16
- yarn build
17
- ```
18
-
19
- ### 发布npm
20
- ```
21
- npm publish
22
- ```
23
- [npm线上地址](https://www.npmjs.com/package/@youdao-ead-fe/yodao-ui)
24
-
25
-
26
- ### 使用组件库
27
- ```
28
- npm install @youdao-ead-fe/yodao-ui
29
-
30
- // 在输入文件如_app.js中引入style
31
- import '@youdao-ead-fe/yodao-ui/style'
32
-
33
- // 在目标页面中
34
- import {MutipleSelector} from @youdao-ead-fe/yodao-ui
35
- ```
36
-
37
-
38
-
39
- ### 发布到github
40
- 使用[@storybook/storybook-deployer文档](https://github.com/storybook-eol/storybook-deployer)发布到github
41
-
42
- ```
43
- yarn build-storybook
44
-
45
- // 在storybook-static 文件夹中添加.nojekyll文件
46
-
47
- yarn deploy-storybook -- --existing-output-dir=storybook-static
48
- ```
49
-
50
- [线上地址](https://MingwieJin.github.io/EverUI/)
51
-
52
-
@@ -0,0 +1,21 @@
1
+ // commitlint.config.js
2
+ module.exports = {
3
+ extends: ['@commitlint/config-conventional'],
4
+ rules: {
5
+ 'type-enum': [
6
+ 2,
7
+ 'always',
8
+ [
9
+ 'feat',
10
+ 'fix',
11
+ 'docs',
12
+ 'style',
13
+ 'refactor',
14
+ 'perf',
15
+ 'test',
16
+ 'chore',
17
+ 'revert',
18
+ ],
19
+ ],
20
+ },
21
+ };
@@ -0,0 +1,9 @@
1
+ ---
2
+ title: 更新日志
3
+ toc: content
4
+ order: 1
5
+ ---
6
+
7
+ # 更新日志
8
+
9
+ - 2026/03/17 `@chr/ui@1.0` v1.0.0 正式发布。
@@ -0,0 +1 @@
1
+ 1
@@ -0,0 +1,39 @@
1
+ ---
2
+ title: 安装
3
+ toc: content
4
+ group:
5
+ title: 快速上手
6
+ order: 1
7
+ ---
8
+
9
+ # 安装
10
+
11
+ `@chr/ui@1.0` 是基于 `antd@6.3.3` 开发的。
12
+
13
+ ## 前置依赖
14
+
15
+ 请先检查项目中是否已安装以下依赖:
16
+
17
+ ```
18
+ "react": ">=16.9.0",
19
+ "react-dom": ">=16.9.0",
20
+ "antd": ">=6.3.3"
21
+ ```
22
+
23
+ ## 镜像仓库
24
+
25
+ `@chr/ui@1.0` 应当发布到公司的npm私服中。
26
+
27
+ ```bash
28
+ npm config set registry http://npm.xxx.com
29
+ # or
30
+ yarn config set registry http://npm.xxx.com
31
+ ```
32
+
33
+ ## 安装
34
+
35
+ ```bash
36
+ npm install @chr/ui
37
+ # or
38
+ yarn add @chr/ui
39
+ ```
package/docs/index.md ADDED
@@ -0,0 +1,21 @@
1
+ ---
2
+ hero:
3
+ title: MyAntd
4
+ description: 一个基于Antd二次封装的组件库
5
+ actions:
6
+ - text: 快速上手
7
+ link: /guide/install
8
+ - text: gitlab
9
+ link: https://gitlab.com
10
+ features:
11
+ - title: 快速开发
12
+ emoji: 🚀
13
+ description: 让开发更快速、简单
14
+ - title: 'Ant Design'
15
+ emoji: 💎
16
+ description: 在 Ant Design基础上进行的封装,无缝对接 antd 项目
17
+ - title: TypeScript
18
+ emoji: 🌈
19
+ description: 使用TypeScript开发,提供完整的类型定义文件
20
+ ---
21
+
@@ -0,0 +1 @@
1
+ 1
package/lerna.json ADDED
@@ -0,0 +1,8 @@
1
+ {
2
+ "$schema": "node_modules/lerna/schemas/lerna-schema.json",
3
+ "version": "independent",
4
+ "npmClient": "pnpm",
5
+ "packages": [
6
+ "packages/*"
7
+ ]
8
+ }
package/package.json CHANGED
@@ -1,78 +1,75 @@
1
1
  {
2
2
  "name": "@wangtaizong/components",
3
- "version": "1.0.6",
4
- "type": "module",
5
- "license": "MIT",
6
- "publishConfig": {
7
- "access": "public",
8
- "registry": "https://registry.npmjs.org/"
9
- },
3
+ "version": "1.0.8",
4
+ "private": false,
10
5
  "scripts": {
11
- "dev": "vite",
12
- "build": "vite build && tsc --project tsconfig.build.json",
13
- "lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
14
- "preview": "vite preview",
15
- "storybook": "storybook dev -p 8080",
16
- "preview-storybook": "npx http-server storybook-static",
17
- "build-storybook": "storybook build",
18
- "deploy-storybook": "storybook-to-ghpages"
6
+ "build": "lerna run build",
7
+ "clean": "lerna clean --yes",
8
+ "clean:dist": "lerna exec -- rm -rf dist es lib",
9
+ "commit": "git add . && git cz",
10
+ "cs:add": "pnpm changeset add",
11
+ "cs:preEnter": "pnpm changeset pre enter beta",
12
+ "cs:preExit": "pnpm changeset pre exit",
13
+ "cs:publish": "pnpm changeset publish",
14
+ "cs:status": "pnpm changeset status",
15
+ "cs:version": "pnpm changeset version",
16
+ "dev": "dumi dev",
17
+ "docs:build": "dumi build",
18
+ "docs:preview": "dumi preview",
19
+ "lint": "npm run lint:es && npm run lint:css",
20
+ "lint:css": "stylelint \"{src,test}/**/*.{css,less}\"",
21
+ "lint:es": "eslint \"{src,test}/**/*.{js,jsx,ts,tsx}\"",
22
+ "lp": "lerna publish from-git",
23
+ "lv": "lerna version",
24
+ "start": "npm run dev"
19
25
  },
20
- "dependencies": {
21
- "@codesandbox/sandpack-react": "^2.13.8",
22
- "@codesandbox/sandpack-themes": "^2.0.21",
23
- "@minoru/react-dnd-treeview": "^3.4.4",
24
- "@monaco-editor/react": "4.6.0",
25
- "path": "^0.12.7",
26
- "react": "^18.2.0",
27
- "react-dom": "^18.2.0",
28
- "react-dnd": "^16.0.1"
26
+ "commitlint": {
27
+ "extends": [
28
+ "@commitlint/config-conventional"
29
+ ]
29
30
  },
30
- "devDependencies": {
31
- "@storybook/addon-essentials": "^7.4.0",
32
- "@storybook/addon-interactions": "^7.4.0",
33
- "@storybook/addon-links": "^7.4.0",
34
- "@storybook/addon-onboarding": "1.0.8",
35
- "@storybook/blocks": "^7.4.0",
36
- "@storybook/manager-api": "^7.4.0",
37
- "@storybook/react": "^7.4.0",
38
- "@storybook/react-vite": "^7.4.0",
39
- "@storybook/storybook-deployer": "^2.8.16",
40
- "@storybook/testing-library": "0.2.2",
41
- "@storybook/theming": "^7.4.0",
42
- "@types/less": "^3.0.4",
43
- "@types/node": "^20.8.3",
44
- "@types/react": "^18.2.15",
45
- "@types/react-dom": "^18.2.7",
46
- "@typescript-eslint/eslint-plugin": "^6.0.0",
47
- "@typescript-eslint/parser": "^6.0.0",
48
- "@vitejs/plugin-react": "^4.0.3",
49
- "classnames": "^2.3.2",
50
- "eslint": "^8.45.0",
51
- "eslint-plugin-react-hooks": "^4.6.0",
52
- "eslint-plugin-react-refresh": "^0.4.3",
53
- "eslint-plugin-storybook": "^0.6.15",
54
- "less": "^4.2.0",
55
- "react-selectable-fast": "^3.4.0",
56
- "storybook": "^7.4.0",
57
- "typescript": "^5.0.2",
58
- "vite": "^4.4.5"
31
+ "lint-staged": {
32
+ "*.{md,json}": [
33
+ "prettier --write --no-error-on-unmatched-pattern"
34
+ ],
35
+ "*.{css,less}": [
36
+ "stylelint --fix",
37
+ "prettier --write"
38
+ ],
39
+ "*.{js,jsx}": [
40
+ "eslint --fix",
41
+ "prettier --write"
42
+ ],
43
+ "*.{ts,tsx}": [
44
+ "eslint --fix",
45
+ "prettier --parser=typescript --write"
46
+ ]
59
47
  },
60
- "files": [
61
- "dist"
62
- ],
63
- "main": "./dist/index.umd.js",
64
- "module": "./dist/index.es.js",
65
- "typings": "./dist/index.d.ts",
66
- "exports": {
67
- ".": {
68
- "import": "./dist/index.es.js",
69
- "require": "./dist/index.umd.js"
70
- },
71
- "./style": "./dist/style.css"
48
+ "config": {
49
+ "commitizen": {
50
+ "path": "./node_modules/cz-conventional-changelog"
51
+ }
72
52
  },
73
- "resolutions": {
74
- "string-width": "^4",
75
- "jackspeak": "^2",
76
- "strip-ansi": "^6"
53
+ "devDependencies": {
54
+ "@changesets/cli": "^2.29.2",
55
+ "@commitlint/cli": "^17.1.2",
56
+ "@commitlint/config-conventional": "^17.1.0",
57
+ "@types/react": "^18.0.0",
58
+ "@types/react-dom": "^18.0.0",
59
+ "@umijs/lint": "^4.0.0",
60
+ "commitizen": "^4.3.1",
61
+ "cz-conventional-changelog": "^3.3.0",
62
+ "dumi": "^2.4.18",
63
+ "eslint": "^8.23.0",
64
+ "father": "^4.1.0",
65
+ "husky": "^8.0.1",
66
+ "lerna": "^8.2.1",
67
+ "lint-staged": "^13.0.3",
68
+ "prettier": "^2.7.1",
69
+ "prettier-plugin-organize-imports": "^3.0.0",
70
+ "prettier-plugin-packagejson": "^2.2.18",
71
+ "react": "^18.0.0",
72
+ "react-dom": "^18.0.0",
73
+ "stylelint": "^14.9.1"
77
74
  }
78
75
  }
File without changes
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "@chr/components",
3
+ "version": "1.0.0",
4
+ "description": "基础组件",
5
+ "keywords": [],
6
+ "license": "MIT",
7
+ "sideEffects": false,
8
+ "main": "lib/index.js",
9
+ "unpkg": "dist/index.min.js",
10
+ "module": "es/index.js",
11
+ "typings": "es/index.d.ts",
12
+ "files": [
13
+ "es",
14
+ "lib",
15
+ "dist"
16
+ ],
17
+ "scripts": {
18
+ "build": "rollup -c"
19
+ },
20
+ "dependencies": {
21
+ "@ant-design/icons": "^6.0.0"
22
+ },
23
+ "devDependencies": {
24
+ "@babel/preset-env": "^7.26.9",
25
+ "@babel/preset-react": "^7.26.3",
26
+ "@rollup/plugin-babel": "^6.0.4",
27
+ "@rollup/plugin-commonjs": "^28.0.3",
28
+ "@rollup/plugin-node-resolve": "^16.0.1",
29
+ "@rollup/plugin-typescript": "^12.1.2",
30
+ "rollup": "^4.38.0",
31
+ "rollup-plugin-dts": "^6.2.1",
32
+ "rollup-plugin-peer-deps-external": "^2.2.4",
33
+ "rollup-plugin-postcss": "^4.0.2",
34
+ "rollup-plugin-terser": "^7.0.2",
35
+ "typescript": "^5.8.2"
36
+ },
37
+ "peerDependencies": {
38
+ "antd": "catalog:",
39
+ "react": "catalog:",
40
+ "react-dom": "catalog:",
41
+ "@ant-design/icons": "catalog:"
42
+ },
43
+ "packageManager": "pnpm@10.7.0",
44
+ "publishConfig": {
45
+ "access": "public",
46
+ "registry": "https://registry.npmjs.org/"
47
+ }
48
+ }
@@ -0,0 +1,108 @@
1
+ import babel from '@rollup/plugin-babel';
2
+ import commonjs from '@rollup/plugin-commonjs';
3
+ import { nodeResolve } from '@rollup/plugin-node-resolve';
4
+ import typescript from '@rollup/plugin-typescript';
5
+ import { defineConfig } from 'rollup';
6
+ import peerDepsExternal from 'rollup-plugin-peer-deps-external';
7
+ import postcss from 'rollup-plugin-postcss';
8
+ import { terser } from 'rollup-plugin-terser';
9
+
10
+ const DIR_MAP = {
11
+ ESM: 'es',
12
+ CJS: 'lib',
13
+ UMD: 'dist',
14
+ };
15
+
16
+ // 处理 Ant Design 样式按需加载
17
+ const antdStyles = () => ({
18
+ name: 'antd-styles',
19
+ transform(code, id) {
20
+ if (/node_modules\/antd/.test(id) && id.endsWith('.js')) {
21
+ return code.replace(/import\s+['"].*\.less['"]/, '');
22
+ }
23
+ return null;
24
+ },
25
+ });
26
+
27
+ const baseConfig = (tsConfig) => ({
28
+ external: ['react', 'react-dom', 'antd', 'tslib'],
29
+ input: 'src/index.ts',
30
+ plugins: [
31
+ peerDepsExternal(),
32
+ nodeResolve({
33
+ modulesOnly: true,
34
+ extensions: ['.ts', '.tsx', '.js', '.jsx'],
35
+ preferBuiltins: true,
36
+ }),
37
+ commonjs(),
38
+ typescript(tsConfig),
39
+ babel({
40
+ babelHelpers: 'bundled',
41
+ extensions: ['.ts', '.tsx'],
42
+ presets: [
43
+ '@babel/preset-react',
44
+ ['@babel/preset-env', { modules: false }],
45
+ ],
46
+ }),
47
+ postcss({
48
+ extract: true, // 分离 CSS 文件
49
+ modules: false,
50
+ use: ['less'],
51
+ minimize: true,
52
+ }),
53
+ antdStyles(),
54
+ ],
55
+ });
56
+
57
+ const esmConfig = {
58
+ ...baseConfig({
59
+ declaration: true,
60
+ declarationDir: DIR_MAP.ESM,
61
+ }),
62
+ output: {
63
+ dir: DIR_MAP.ESM,
64
+ format: 'esm',
65
+ preserveModules: true,
66
+ preserveModulesRoot: 'src',
67
+ },
68
+ };
69
+
70
+ const cjsConfig = {
71
+ ...baseConfig({
72
+ declaration: true,
73
+ declarationDir: DIR_MAP.CJS,
74
+ }),
75
+ output: {
76
+ dir: DIR_MAP.CJS,
77
+ format: 'cjs',
78
+ exports: 'named',
79
+ preserveModules: true,
80
+ preserveModulesRoot: 'src',
81
+ },
82
+ };
83
+
84
+ const umdConfig = {
85
+ ...baseConfig(),
86
+ output: [
87
+ {
88
+ file: DIR_MAP.UMD + '/index.js',
89
+ format: 'umd',
90
+ name: 'KcComponents',
91
+ globals: {
92
+ react: 'React',
93
+ 'react-dom': 'ReactDOM',
94
+ antd: 'antd',
95
+ },
96
+ sourcemap: true,
97
+ },
98
+ {
99
+ file: DIR_MAP.UMD + '/index.min.js',
100
+ format: 'umd',
101
+ name: 'KcComponents',
102
+ plugins: [terser()],
103
+ sourcemap: true,
104
+ },
105
+ ],
106
+ };
107
+
108
+ export default defineConfig([esmConfig, cjsConfig, umdConfig]);
@@ -0,0 +1,13 @@
1
+ # CHRButton
2
+
3
+ This is an example component.
4
+
5
+ ```jsx
6
+ import { CHRButton } from '@chr/components';
7
+
8
+ export default () => (
9
+ <CHRButton color="default" variant="solid">
10
+ Solid
11
+ </CHRButton>
12
+ );
13
+ ```
@@ -0,0 +1,34 @@
1
+ import { Button } from 'antd';
2
+ import React, { type FC, ReactNode } from 'react';
3
+
4
+ interface CHRButtonProps {
5
+ children?: ReactNode;
6
+ title?: string;
7
+ defaultText?: string;
8
+ onClick?: React.MouseEventHandler<HTMLElement>;
9
+ }
10
+
11
+ const CHRButton: FC<CHRButtonProps> = ({
12
+ children,
13
+ title,
14
+ defaultText = '按钮',
15
+ onClick,
16
+ ...restProps
17
+ }) => {
18
+ const handleClick: React.MouseEventHandler<HTMLElement> = (e) => {
19
+ console.log('CHRButton 内部点击处理');
20
+ onClick?.(e);
21
+ };
22
+
23
+ // 决定显示内容
24
+ let content: ReactNode;
25
+ content = children !== undefined ? children : title || defaultText;
26
+
27
+ return (
28
+ <Button {...restProps} onClick={handleClick}>
29
+ {content}
30
+ </Button>
31
+ );
32
+ };
33
+
34
+ export default CHRButton;