diff --git a/mana/packages/mana-ui/.eslintrc.js b/mana/packages/mana-ui/.eslintrc.js deleted file mode 100644 index ffd7daa9..00000000 --- a/mana/packages/mana-ui/.eslintrc.js +++ /dev/null @@ -1,3 +0,0 @@ -module.exports = { - extends: require.resolve('../../.eslintrc.js'), -}; diff --git a/mana/packages/mana-ui/.fatherrc.ts b/mana/packages/mana-ui/.fatherrc.ts deleted file mode 100644 index 6e08d731..00000000 --- a/mana/packages/mana-ui/.fatherrc.ts +++ /dev/null @@ -1,26 +0,0 @@ -export default { - platform: 'browser', - esm: { - output: 'es', - }, - cjs: { - output: 'lib', - }, - extraBabelPlugins: [ - ['@babel/plugin-proposal-decorators', { legacy: true }], - ['@babel/plugin-transform-flow-strip-types'], - ['@babel/plugin-transform-class-properties', { loose: true }], - ['@babel/plugin-transform-private-methods', { loose: true }], - ['@babel/plugin-transform-private-property-in-object', { loose: true }], - 'babel-plugin-parameter-decorator', - ], - extraBabelPresets: [ - [ - '@babel/preset-react', - { - runtime: 'automatic', - }, - ], - ['@babel/preset-typescript', { onlyRemoveTypeImports: true }], - ], -}; diff --git a/mana/packages/mana-ui/CHANGELOG.md b/mana/packages/mana-ui/CHANGELOG.md deleted file mode 100644 index c3d12fa0..00000000 --- a/mana/packages/mana-ui/CHANGELOG.md +++ /dev/null @@ -1,296 +0,0 @@ -# @difizen/mana-ui - -## 0.1.32 - -### Patch Changes - -- [#88](https://github.com/difizen/mana/pull/88) [`efec026`](https://github.com/difizen/mana/commit/efec02698841de45108da24897040b528d2c3ec2) Thanks [@sunshinesmilelk](https://github.com/sunshinesmilelk)! - feat: add onWillStart hook for ApplicationComponent - -- Updated dependencies [[`efec026`](https://github.com/difizen/mana/commit/efec02698841de45108da24897040b528d2c3ec2)]: - - @difizen/mana-core@0.1.32 - - @difizen/mana-app@0.1.32 - - @difizen/mana-common@0.1.32 - - @difizen/mana-observable@0.1.32 - - @difizen/mana-react@0.1.32 - - @difizen/mana-syringe@0.1.32 - -## 0.1.31 - -### Patch Changes - -- [#79](https://github.com/difizen/mana/pull/79) [`0365365`](https://github.com/difizen/mana/commit/03653659a7400430493903e33f44dc2f048576df) Thanks [@lulusir](https://github.com/lulusir)! - fix: localStorage is not defined. - -- Updated dependencies [[`0365365`](https://github.com/difizen/mana/commit/03653659a7400430493903e33f44dc2f048576df)]: - - @difizen/mana-observable@0.1.31 - - @difizen/mana-syringe@0.1.31 - - @difizen/mana-common@0.1.31 - - @difizen/mana-react@0.1.31 - - @difizen/mana-core@0.1.31 - - @difizen/mana-app@0.1.31 - -## 0.1.30 - -### Patch Changes - -- [#76](https://github.com/difizen/mana/pull/76) [`14ea61a`](https://github.com/difizen/mana/commit/14ea61ac7ecc717b3091687b9ea4ac0aaf1e6ecf) Thanks [@BroKun](https://github.com/BroKun)! - Use a consistent version. - -- [#78](https://github.com/difizen/mana/pull/78) [`92f3efc`](https://github.com/difizen/mana/commit/92f3efcc9852ff7230d9e029e25fdacd9d529d55) Thanks [@sunshinesmilelk](https://github.com/sunshinesmilelk)! - fix text color for some components - -- Updated dependencies [[`14ea61a`](https://github.com/difizen/mana/commit/14ea61ac7ecc717b3091687b9ea4ac0aaf1e6ecf), [`92f3efc`](https://github.com/difizen/mana/commit/92f3efcc9852ff7230d9e029e25fdacd9d529d55)]: - - @difizen/mana-observable@0.1.30 - - @difizen/mana-syringe@0.1.30 - - @difizen/mana-common@0.1.30 - - @difizen/mana-react@0.1.30 - - @difizen/mana-core@0.1.30 - - @difizen/mana-app@0.1.30 - -## 0.1.28 - -### Patch Changes - -- [#71](https://github.com/difizen/mana/pull/71) [`24b70a0`](https://github.com/difizen/mana/commit/24b70a036be7f4d85548db720ea5859b5a3e5b41) Thanks [@BroKun](https://github.com/BroKun)! - [syringe] Developing multi-instance data structures becomes easier with auto factory. - -- Updated dependencies [[`24b70a0`](https://github.com/difizen/mana/commit/24b70a036be7f4d85548db720ea5859b5a3e5b41)]: - - @difizen/mana-observable@0.1.28 - - @difizen/mana-syringe@0.1.28 - - @difizen/mana-common@0.1.28 - - @difizen/mana-react@0.1.28 - - @difizen/mana-core@0.1.28 - - @difizen/mana-app@0.1.28 - -## 0.1.27 - -### Patch Changes - -- [#62](https://github.com/difizen/mana/pull/62) [`812915f`](https://github.com/difizen/mana/commit/812915f4681c44982cefa5800d6f11ec27a81a20) Thanks [@sunshinesmilelk](https://github.com/sunshinesmilelk)! - fix(umi-plugin): update mana runtime plugin dir name - -- Updated dependencies [[`812915f`](https://github.com/difizen/mana/commit/812915f4681c44982cefa5800d6f11ec27a81a20)]: - - @difizen/mana-app@0.1.27 - - @difizen/mana-common@0.1.27 - - @difizen/mana-core@0.1.27 - - @difizen/mana-observable@0.1.27 - - @difizen/mana-react@0.1.27 - - @difizen/mana-syringe@0.1.27 - -## 0.1.26 - -### Patch Changes - -- [#60](https://github.com/difizen/mana/pull/60) [`a23732f`](https://github.com/difizen/mana/commit/a23732f365a76f719ac59f2c87de3920f70b1dd7) Thanks [@zhanba](https://github.com/zhanba)! - fix: support query parse in uri - -- Updated dependencies [[`a23732f`](https://github.com/difizen/mana/commit/a23732f365a76f719ac59f2c87de3920f70b1dd7)]: - - @difizen/mana-common@0.1.26 - - @difizen/mana-app@0.1.26 - - @difizen/mana-core@0.1.26 - - @difizen/mana-observable@0.1.26 - - @difizen/mana-react@0.1.26 - - @difizen/mana-syringe@0.1.26 - -## 0.1.25 - -### Patch Changes - -- [#58](https://github.com/difizen/mana/pull/58) [`df976cb`](https://github.com/difizen/mana/commit/df976cba6bcf49b979dc001ffe68b4e0953522ff) Thanks [@BroKun](https://github.com/BroKun)! - Theme support empty prefix - -- Updated dependencies [[`df976cb`](https://github.com/difizen/mana/commit/df976cba6bcf49b979dc001ffe68b4e0953522ff)]: - - @difizen/mana-observable@0.1.25 - - @difizen/mana-syringe@0.1.25 - - @difizen/mana-common@0.1.25 - - @difizen/mana-react@0.1.25 - - @difizen/mana-core@0.1.25 - - @difizen/mana-app@0.1.25 - -## 0.1.24 - -### Patch Changes - -- [#56](https://github.com/difizen/mana/pull/56) [`02f92a6`](https://github.com/difizen/mana/commit/02f92a6da23fc653e52c0192c3547ed956a44a22) Thanks [@BroKun](https://github.com/BroKun)! - Support custom css variable prefix - -- Updated dependencies [[`02f92a6`](https://github.com/difizen/mana/commit/02f92a6da23fc653e52c0192c3547ed956a44a22)]: - - @difizen/mana-observable@0.1.24 - - @difizen/mana-syringe@0.1.24 - - @difizen/mana-common@0.1.24 - - @difizen/mana-react@0.1.24 - - @difizen/mana-core@0.1.24 - - @difizen/mana-app@0.1.24 - -## 0.1.23 - -### Patch Changes - -- [#53](https://github.com/difizen/mana/pull/53) [`c76098a`](https://github.com/difizen/mana/commit/c76098abd7eeae0ea7885d00402a47e15197e2a0) Thanks [@BroKun](https://github.com/BroKun)! - Fix slot view initialization in some cases. - -- [#53](https://github.com/difizen/mana/pull/53) [`c24e597`](https://github.com/difizen/mana/commit/c24e5974abd064d3af1d27f321745daa48183a74) Thanks [@BroKun](https://github.com/BroKun)! - Export color protocol. - -- [#53](https://github.com/difizen/mana/pull/53) [`8174a13`](https://github.com/difizen/mana/commit/8174a1355b9aca974d7ba68fc6087aef923b757c) Thanks [@BroKun](https://github.com/BroKun)! - Always serialize when storing. - -- [#53](https://github.com/difizen/mana/pull/53) [`06bdadd`](https://github.com/difizen/mana/commit/06bdadd00e143151c0b25f63354dab3579d5ee1f) Thanks [@BroKun](https://github.com/BroKun)! - Use modal service api without full modal item - -- Updated dependencies [[`c76098a`](https://github.com/difizen/mana/commit/c76098abd7eeae0ea7885d00402a47e15197e2a0), [`c24e597`](https://github.com/difizen/mana/commit/c24e5974abd064d3af1d27f321745daa48183a74), [`8174a13`](https://github.com/difizen/mana/commit/8174a1355b9aca974d7ba68fc6087aef923b757c), [`06bdadd`](https://github.com/difizen/mana/commit/06bdadd00e143151c0b25f63354dab3579d5ee1f)]: - - @difizen/mana-observable@0.1.23 - - @difizen/mana-syringe@0.1.23 - - @difizen/mana-common@0.1.23 - - @difizen/mana-react@0.1.23 - - @difizen/mana-core@0.1.23 - - @difizen/mana-app@0.1.23 - -## 0.1.22 - -### Patch Changes - -- ec0b517: Fix core module compatibility -- Updated dependencies [ec0b517] - - @difizen/mana-observable@0.1.22 - - @difizen/mana-syringe@0.1.22 - - @difizen/mana-common@0.1.22 - - @difizen/mana-react@0.1.22 - - @difizen/mana-core@0.1.22 - - @difizen/mana-app@0.1.22 - -## 0.1.21 - -### Patch Changes - -- 007af7f: Dark mode support for menu. -- 32133c3: Add notification feature. -- Updated dependencies [007af7f] -- Updated dependencies [32133c3] - - @difizen/mana-observable@0.1.21 - - @difizen/mana-syringe@0.1.21 - - @difizen/mana-common@0.1.21 - - @difizen/mana-react@0.1.21 - - @difizen/mana-core@0.1.21 - - @difizen/mana-app@0.1.21 - -## 0.1.20 - -### Patch Changes - -- 690a2aa: Added umi plug-in, now you can use mana in umi project more easily. -- Updated dependencies [690a2aa] - - @difizen/mana-observable@0.1.20 - - @difizen/mana-syringe@0.1.20 - - @difizen/mana-common@0.1.20 - - @difizen/mana-react@0.1.20 - - @difizen/mana-core@0.1.20 - - @difizen/mana-app@0.1.20 - -## 0.1.19 - -### Patch Changes - -- 43f310a: Remove global style css -- Updated dependencies [43f310a] - - @difizen/mana-observable@0.1.19 - - @difizen/mana-syringe@0.1.19 - - @difizen/mana-common@0.1.19 - - @difizen/mana-react@0.1.19 - - @difizen/mana-core@0.1.19 - - @difizen/mana-app@0.1.19 - -## 0.1.18 - -### Patch Changes - -- 02ef50f: basic styles no longer affect global styles. -- Updated dependencies [02ef50f] - - @difizen/mana-observable@0.1.18 - - @difizen/mana-syringe@0.1.18 - - @difizen/mana-common@0.1.18 - - @difizen/mana-react@0.1.18 - - @difizen/mana-core@0.1.18 - - @difizen/mana-app@0.1.18 - -## 0.1.17 - -### Patch Changes - -- 1acf757: feat: add onInitialized hooks for ApplicationComponent -- Updated dependencies [1acf757] - - @difizen/mana-core@0.1.17 - - @difizen/mana-app@0.1.17 - - @difizen/mana-common@0.1.17 - - @difizen/mana-observable@0.1.17 - - @difizen/mana-react@0.1.17 - - @difizen/mana-syringe@0.1.17 - -## 0.1.16 - -### Patch Changes - -- 84f7cd8: No longer import font-awesome styles through less file. -- Updated dependencies [84f7cd8] - - @difizen/mana-observable@0.1.16 - - @difizen/mana-syringe@0.1.16 - - @difizen/mana-common@0.1.16 - - @difizen/mana-react@0.1.16 - - @difizen/mana-core@0.1.16 - - @difizen/mana-app@0.1.16 - -## 0.1.15 - -### Patch Changes - -- 95eb30c: chore: add father config -- Updated dependencies [95eb30c] - - @difizen/mana-app@0.1.15 - - @difizen/mana-common@0.1.15 - - @difizen/mana-core@0.1.15 - - @difizen/mana-observable@0.1.15 - - @difizen/mana-react@0.1.15 - - @difizen/mana-syringe@0.1.15 - -## 0.1.14 - -### Patch Changes - -- 1b880fe: fix: attributes in ContributionOptionConfig -- Updated dependencies [1b880fe] - - @difizen/mana-syringe@0.1.14 - - @difizen/mana-app@0.1.14 - - @difizen/mana-common@0.1.14 - - @difizen/mana-core@0.1.14 - - @difizen/mana-observable@0.1.14 - - @difizen/mana-react@0.1.14 - -## 0.1.13 - -### Patch Changes - -- 76745bd: feat: add ContributionOptionConfig -- Updated dependencies [76745bd] - - @difizen/mana-syringe@0.1.13 - - @difizen/mana-app@0.1.13 - - @difizen/mana-common@0.1.13 - - @difizen/mana-core@0.1.13 - - @difizen/mana-observable@0.1.13 - - @difizen/mana-react@0.1.13 - -## 0.1.12 - -### Patch Changes - -- 8eee617: chore: update the peerDependencies about react -- Updated dependencies [8eee617] - - @difizen/mana-observable@0.1.12 - - @difizen/mana-react@0.1.12 - - @difizen/mana-app@0.1.12 - - @difizen/mana-common@0.1.12 - - @difizen/mana-core@0.1.12 - - @difizen/mana-syringe@0.1.12 - -## 0.1.11 - -### Patch Changes - -- 6fb1d96: mana-observable: Allows defining properties that should not be observed. -- 67e2969: Add mana-ui package -- Updated dependencies [6fb1d96] -- Updated dependencies [67e2969] -- Updated dependencies [c1cf9c7] - - @difizen/mana-observable@0.1.11 - - @difizen/mana-syringe@0.1.11 - - @difizen/mana-common@0.1.11 - - @difizen/mana-react@0.1.11 - - @difizen/mana-core@0.1.11 - - @difizen/mana-app@0.1.11 diff --git a/mana/packages/mana-ui/README.md b/mana/packages/mana-ui/README.md deleted file mode 100644 index 7c7f33f0..00000000 --- a/mana/packages/mana-ui/README.md +++ /dev/null @@ -1 +0,0 @@ -# mana-ui diff --git a/mana/packages/mana-ui/babel.config.json b/mana/packages/mana-ui/babel.config.json deleted file mode 100644 index efd12242..00000000 --- a/mana/packages/mana-ui/babel.config.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "presets": [ - "@babel/preset-env", - [ - "@babel/preset-react", - { - "runtime": "automatic" - } - ], - "@babel/preset-typescript" - ], - "plugins": [ - ["@babel/plugin-proposal-decorators", { "legacy": true }], - ["@babel/plugin-transform-flow-strip-types", { "allowDeclareFields": true }], - ["@babel/plugin-transform-private-methods", { "loose": true }], - ["@babel/plugin-transform-private-property-in-object", { "loose": true }], - ["@babel/plugin-transform-class-properties", { "loose": true }], - "babel-plugin-parameter-decorator" - ] -} diff --git a/mana/packages/mana-ui/jest.config.js b/mana/packages/mana-ui/jest.config.js deleted file mode 100644 index a129a34b..00000000 --- a/mana/packages/mana-ui/jest.config.js +++ /dev/null @@ -1,3 +0,0 @@ -const configs = require('../../jest.config'); - -module.exports = configs; diff --git a/mana/packages/mana-ui/package.json b/mana/packages/mana-ui/package.json deleted file mode 100644 index 41ac3492..00000000 --- a/mana/packages/mana-ui/package.json +++ /dev/null @@ -1,63 +0,0 @@ -{ - "name": "@difizen/mana-ui", - "version": "0.1.32", - "keywords": [ - "mana", - "difizen", - "mana-ui" - ], - "exports": { - ".": { - "import": { - "typings": "./es/index.d.ts", - "default": "./es/index.js" - }, - "require": { - "typings": "./lib/index.d.ts", - "default": "./lib/index.js" - } - }, - "./package.json": "./package.json" - }, - "main": "lib/index.js", - "module": "es/index.js", - "typings": "lib/index.d.ts", - "files": [ - "lib", - "es", - "src" - ], - "scripts": { - "setup": "father build", - "build": "father build", - "test": ": Note: lint task is delegated to test:* scripts", - "test:vitest": "vitest run", - "test:jest": "jest", - "coverage": ": Note: lint task is delegated to coverage:* scripts", - "coverage:vitest": "vitest run --coverage", - "coverage:jest": "jest --coverage", - "lint": ": Note: lint task is delegated to lint:* scripts", - "lint:eslint": "eslint src", - "lint:tsc": "tsc --noEmit" - }, - "dependencies": { - "@difizen/mana-common": "^0.1.32", - "@difizen/mana-syringe": "^0.1.32", - "@difizen/mana-core": "^0.1.32", - "@difizen/mana-observable": "^0.1.32", - "@difizen/mana-react": "^0.1.32", - "@difizen/mana-app": "^0.1.32", - "classnames": "^2.3.2" - }, - "devDependencies": { - "@types/lodash.debounce": "4.0.3", - "@types/react-virtualized": "^9.18.3" - }, - "peerDependencies": { - "react": ">=16.8.6", - "antd": "^4.0.0 || ^5.0.0" - }, - "publishConfig": { - "access": "public" - } -} diff --git a/mana/packages/mana-ui/src/enhancers/antd-table/index.ts b/mana/packages/mana-ui/src/enhancers/antd-table/index.ts deleted file mode 100644 index 246bba7f..00000000 --- a/mana/packages/mana-ui/src/enhancers/antd-table/index.ts +++ /dev/null @@ -1,270 +0,0 @@ -import { DisposableCollection } from '@difizen/mana-common'; -import { prop, watch } from '@difizen/mana-observable'; -import { inject, transient } from '@difizen/mana-syringe'; -import type { FormInstance, TableProps } from 'antd'; - -import type { Data, Pagination, TableParams, TableResult } from './types'; -import { TableOptions, TableService } from './types'; - -@transient() -export class AntdTableService> { - @prop() - pagination: Pagination = { - current: 1, - pageSize: 10, - total: 0, - }; - - @prop() - data: Data = { - list: [], - total: 0, - }; - - @prop() - loading = false; - - @prop() - error?: Error; - - @prop() - params: TableParams = undefined!; - - protected defaultParams: TableParams = undefined!; - - protected options?: TableOptions>; - - protected form: FormInstance> = undefined!; - - protected service: TableService>; - - protected toDispose = new DisposableCollection(); - - constructor( - @inject(TableOptions) - options: TableOptions>, - @inject(TableService) - service: TableService>, - ) { - this.options = options; - this.service = service; - this.pagination = { - current: options?.defaultCurrent || 1, - pageSize: options?.defaultPageSize || 10, - total: 0, - }; - - if (this.options.defaultParams) { - this.defaultParams = this.options.defaultParams; - } - - if (this.options.refreshDeps) { - this.options.refreshDeps.forEach((dep) => { - const [target, keys] = dep; - const watchKeys = ([] as string[]).concat(keys); - this.toDispose.pushAll( - watchKeys.map((key) => { - return watch(target, key, () => { - this.refresh(); - }); - }), - ); - }); - } - - if (!this.options.manual) { - this.initialLoad(); - } - } - - run = (params: TableParams) => { - this.params = params; - const { onBefore, onSuccess, onError } = this.options || {}; - if (onBefore) { - onBefore(params); - } - this.loading = true; - this.error = undefined; - this.service(params) - .then((data) => { - if (!this.loading) { - return; - } - this.data = data; - this.pagination = { - current: params[0].current ?? this.pagination.current, - pageSize: params[0].pageSize ?? this.pagination.pageSize, - total: data.total, - }; - onSuccess?.(data, params); - return; - }) - .finally(() => { - this.loading = false; - }) - .catch((e) => { - this.error = e; - onError?.(e, params); - }); - }; - - runAsync = (params: TableParams) => { - this.params = params; - const { onBefore, onSuccess, onError } = this.options || {}; - if (onBefore) { - onBefore(params); - } - this.loading = true; - this.error = undefined; - return this.service(params) - .then((data) => { - if (!this.loading) { - return; - } - this.data = data; - this.pagination = { - current: params[0].current ?? this.pagination.current, - pageSize: params[0].pageSize ?? this.pagination.pageSize, - total: data.total, - }; - onSuccess?.(data, params); - return data; - }) - .catch((e) => { - this.error = e; - onError?.(e, params); - }) - .finally(() => { - this.loading = false; - }); - }; - - refresh = () => { - const formValues = this.form?.getFieldsValue(); - const params = [this.params[0], formValues] as unknown as TableParams; - this.runAsync(params); - }; - - refreshAsync = async () => { - const formValues = this.form?.getFieldsValue(); - const params = [this.params[0], formValues] as unknown as TableParams; - return this.runAsync(params); - }; - - mutate = (data?: Data | { (oldData: Data): Data }) => { - if (typeof data === 'function') { - this.data = (data as any)(this.data); - } else { - this.data = data!; - } - }; - - cancel = () => { - this.loading = false; - }; - - onChange: Required>['onChange'] = ( - pagination, - filters, - sorters, - ) => { - const params = [ - { - current: pagination.current || this.pagination.current, - pageSize: pagination.pageSize || this.pagination.pageSize, - filter: filters, - sorter: sorters, - }, - this.params[1], - ] as unknown as TableParams; - this.run(params); - }; - - submit = () => { - this.pagination.current = 1; - this.form?.validateFields().then((values) => { - const params = [ - { - ...this.params[0], - current: this.pagination.current, - pageSize: this.pagination.pageSize, - }, - values, - ] as unknown as TableParams; - this.run(params); - return; - }); - }; - - reset = () => { - this.form?.resetFields(); - this.pagination.current = 1; - const params = [ - { - ...this.params[0], - current: this.pagination.current, - pageSize: this.pagination.pageSize, - }, - {}, - ] as unknown as TableParams; - this.run(params); - }; - - // 在传入form 时,同时设置初始化的 formValue - setForm = (form: FormInstance>) => { - if (!this.form) { - this.form = form; - if (this.defaultParams && this.defaultParams[1]) { - form.setFieldsValue(this.defaultParams[1]); - } - } else { - console.error('[ManaEnhancer] form has been set, can not set again'); - } - }; - - protected initialLoad = () => { - const defaultParams = this.defaultParams; - const requestParams: TableParams = [] as any; - if (!defaultParams) { - this.run([ - { - current: this.pagination.current, - pageSize: this.pagination.pageSize, - }, - ] as TableParams); - return; - } - - if (defaultParams[0]) { - requestParams[0] = { - current: defaultParams[0].current || this.pagination.current, - pageSize: defaultParams[0].pageSize || this.pagination.pageSize, - }; - } - if (defaultParams[1]) { - requestParams[1] = defaultParams[1]; - } - this.run(requestParams); - }; - - get tableProps(): TableResult>['tableProps'] { - return { - dataSource: this.data.list, - loading: this.loading, - onChange: this.onChange, - pagination: this.pagination, - }; - } - - get search(): TableResult>['search'] { - return { - submit: this.submit, - reset: this.reset, - }; - } - - // TODO: 销毁 watcher - dispose = () => { - this.toDispose.dispose(); - }; -} diff --git a/mana/packages/mana-ui/src/enhancers/antd-table/module.ts b/mana/packages/mana-ui/src/enhancers/antd-table/module.ts deleted file mode 100644 index a5350451..00000000 --- a/mana/packages/mana-ui/src/enhancers/antd-table/module.ts +++ /dev/null @@ -1,42 +0,0 @@ -import { ManaModule } from '@difizen/mana-app'; - -import type { TableParams } from './types'; -import { TableOptions, TableService } from './types'; - -import { AntdTableService } from './index'; - -export const AntdTableServiceFactory = Symbol('antd-table-service-factory'); -export type AntdTableServiceFactory = { - create: = any>( - service: TableService>, - options?: TableOptions>, - ) => AntdTableService; -}; - -export { AntdTableService } from './index'; - -export const AntdTableModule = ManaModule.create().register(AntdTableService, { - token: AntdTableServiceFactory, - useDynamic: (ctx) => { - return { - create: < - TData = any, - TParams extends Record | undefined = undefined, - >( - service: TableService>, - options: TableOptions> = {}, - ) => { - const container = ctx.container.createChild(); - container.register({ - token: TableService, - useValue: service, - }); - container.register({ - token: TableOptions, - useValue: options, - }); - return container.get(AntdTableService); - }, - }; - }, -}); diff --git a/mana/packages/mana-ui/src/enhancers/antd-table/types.ts b/mana/packages/mana-ui/src/enhancers/antd-table/types.ts deleted file mode 100644 index 3483ffdb..00000000 --- a/mana/packages/mana-ui/src/enhancers/antd-table/types.ts +++ /dev/null @@ -1,60 +0,0 @@ -import type { TableProps } from 'antd'; - -import type { Options, Result } from '../request/types'; - -export type Data = { total: number; list: TData[] }; - -export type TableQueryParams = { - current: number; - pageSize: number; - sorter?: any; - filter?: any; - extra?: any; - [key: string]: any; -}; - -export type TableParams< - FormValues extends Record | undefined = undefined, -> = - FormValues extends Record - ? [TableQueryParams, FormValues?] - : [TableQueryParams]; - -export type Pagination = { - current: number; - pageSize: number; - total: number; -}; - -export interface TableResult extends Result { - pagination: { - current: number; - pageSize: number; - total: number; - totalPage: number; - onChange: (current: number, pageSize: number) => void; - changeCurrent: (current: number) => void; - changePageSize: (pageSize: number) => void; - }; - tableProps: { - dataSource: TData[]; - loading: boolean; - onChange: TableProps['onChange']; - pagination: Pagination; - }; - search: { - submit: () => void; - reset: () => void; - }; -} - -export const TableOptions = Symbol('mana-request-table-options'); -export interface TableOptions extends Options, TParams> { - defaultPageSize?: number; - defaultCurrent?: number; -} - -export const TableService = Symbol('mana-antd-table-service'); -export type TableService = (params: TParams) => Promise>; - -export type TableRefreshDep = [Record, string | string[]]; diff --git a/mana/packages/mana-ui/src/enhancers/index.ts b/mana/packages/mana-ui/src/enhancers/index.ts deleted file mode 100644 index 26bde7d5..00000000 --- a/mana/packages/mana-ui/src/enhancers/index.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { ManaModule } from '@difizen/mana-app'; - -import { AntdTableModule } from './antd-table/module'; -import { RequestModule } from './request/module'; - -export { AntdTableService, AntdTableServiceFactory } from './antd-table/module'; - -export { RequestService, RequestFactory } from './request/module'; - -export type { - TableQueryParams, - TableParams, - Pagination, - TableResult, - TableOptions, - TableService, - TableRefreshDep, -} from './antd-table/types'; -export type { Service, Options, Plugins, FetchState, Result } from './request/types'; - -export const EnhancerModule = ManaModule.create().dependOn( - RequestModule, - AntdTableModule, -); diff --git a/mana/packages/mana-ui/src/enhancers/request/fetch-core.ts b/mana/packages/mana-ui/src/enhancers/request/fetch-core.ts deleted file mode 100644 index e1a1e1c3..00000000 --- a/mana/packages/mana-ui/src/enhancers/request/fetch-core.ts +++ /dev/null @@ -1,156 +0,0 @@ -import { DisposableCollection } from '@difizen/mana-common'; -import { prop } from '@difizen/mana-observable'; -import { transient } from '@difizen/mana-syringe'; - -import { isFunction } from '../utils'; - -import type { PluginReturn } from './types'; -import type { FetchState, Options, Service } from './types'; - -/** - * 实现了基础请求 - */ -@transient() -export class Fetch { - // plugin 注入的能力 - pluginReturn: PluginReturn[] = []; - - count = 0; - - @prop() - state: FetchState = { - loading: false, - params: undefined, - data: undefined, - error: undefined, - }; - - toDispose = new DisposableCollection(); - - constructor( - public service: Service, - public options: Options, - // public subscribe: any, - public initState: Partial> = {}, - ) { - this.state = { - ...this.state, - loading: !options.manual, - ...initState, - }; - } - - setState(currentState: Partial> = {}) { - this.state = { - ...this.state, - ...currentState, - }; - } - - runPluginHandlder(event: keyof PluginReturn, ...rest: any[]) { - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore - const r = this.pluginReturn.map((item) => item[event]?.(...rest)).filter(Boolean); - return Object.assign({}, ...r); - } - - runAsync = async (params: TParams): Promise => { - this.count += 1; - const currentCount = this.count; - - const { stopNow = false, ...state } = this.runPluginHandlder('onBefore', params); - - if (stopNow) { - return new Promise(() => { - // - }); - } - - this.setState({ - loading: true, - params, - ...state, - }); - - this.options.onBefore?.(params); - - try { - let { servicePromise } = this.runPluginHandlder( - 'onRequest', - this.service, - params, - ); - if (!servicePromise) { - servicePromise = this.service(params); - } - const res = await servicePromise; - - if (currentCount !== this.count) { - // prevent run.then when request is canceled - return undefined; - } - - this.setState({ - data: res, - loading: false, - error: undefined, - }); - - this.runPluginHandlder('onSuccess', res, params); - this.options.onSuccess?.(res, params); - - this.runPluginHandlder('onFinally', params, res, undefined); - this.options.onFinally?.(params, res, undefined); - - return res; - } catch (error) { - if (currentCount !== this.count) { - // prevent run.then when request is canceled - return new Promise(() => { - // - }); - } - - this.setState({ - error: error as Error, - loading: false, - }); - this.options.onError?.(error as Error, params); - this.runPluginHandlder('onError', error, params); - throw error; - } - }; - - run = (params: TParams) => { - this.runAsync(params).catch((error) => { - if (!this.options.onError) { - console.error(error); - } - }); - }; - - cancel = () => { - this.count += 1; - this.setState({ - loading: false, - }); - - this.runPluginHandlder('onCancel'); - }; - - refresh = () => { - this.run((this.state.params || {}) as TParams); - }; - - refreshAsync = () => { - return this.runAsync((this.state.params || {}) as TParams); - }; - - mutate(data?: TData | ((oldData?: TData) => TData | undefined)) { - const targetData = isFunction(data) ? data(this.state.data) : data; - this.runPluginHandlder('onMutate', targetData); - this.setState({ - data: targetData, - }); - } -} diff --git a/mana/packages/mana-ui/src/enhancers/request/module.ts b/mana/packages/mana-ui/src/enhancers/request/module.ts deleted file mode 100644 index a3032e8f..00000000 --- a/mana/packages/mana-ui/src/enhancers/request/module.ts +++ /dev/null @@ -1,38 +0,0 @@ -import { ManaModule } from '@difizen/mana-core'; - -import { Fetch } from './fetch-core'; -import { AutoRunPlugin } from './plugin/autoRunPlugin'; -import { RequestService } from './request'; -import { Options, Service } from './types'; - -export const RequestFactory = Symbol('mana-request-service-factory'); -export type RequestFactory = { - create: ( - service: Service, - options?: Options, - ) => RequestService; -}; - -export { RequestService } from './request'; - -export const RequestModule = ManaModule.create().register( - Fetch, - RequestService, - AutoRunPlugin, - { - token: RequestFactory, - useDynamic: (ctx) => { - return { - create: ( - service: Service, - options: Options = {}, - ) => { - const container = ctx.container.createChild(); - container.register({ token: Service, useValue: service }); - container.register({ token: Options, useValue: options }); - return container.get(RequestService); - }, - }; - }, - }, -); diff --git a/mana/packages/mana-ui/src/enhancers/request/plugin/autoRunPlugin.ts b/mana/packages/mana-ui/src/enhancers/request/plugin/autoRunPlugin.ts deleted file mode 100644 index 7f879372..00000000 --- a/mana/packages/mana-ui/src/enhancers/request/plugin/autoRunPlugin.ts +++ /dev/null @@ -1,76 +0,0 @@ -import { watch } from '@difizen/mana-observable'; -import { inject } from '@difizen/mana-syringe'; - -import { Fetch } from '../fetch-core'; -import type { PluginReturn } from '../types'; -import { Options } from '../types'; - -// support refreshDeps & ready -export class AutoRunPlugin { - fetchInstance: Fetch; - options: Options; - - constructor( - @inject(Fetch) fetchInstance: Fetch, - @inject(Options) options: Options, - ) { - this.fetchInstance = fetchInstance; - this.options = options; - - const { - manual, - ready = [{ defaultReady: true }, 'defaultReady'], - defaultParams = {}, - refreshDeps = [], - refreshDepsAction, - } = this.options; - - this.fetchInstance.toDispose.push( - watch(ready[0], ready[1], () => { - // 自动更新状态下,ready为true则发起请求 - if (!manual && ready[0][ready[1]]) { - fetchInstance.run(defaultParams as TParams); - } - }), - ); - - if (refreshDeps) { - if (!manual) { - if (refreshDepsAction) { - refreshDepsAction(); - } else { - refreshDeps.forEach((dep) => { - const [target, keys] = dep; - const watchKeys = ([] as string[]).concat(keys); - this.fetchInstance.toDispose.pushAll( - watchKeys.map((key) => { - return watch(target, key, () => { - this.fetchInstance.refresh(); - }); - }), - ); - }); - } - } - } - } - - onBefore = () => { - const ready = this.options.ready; - if (ready === undefined) { - return; - } - if (!ready[0][ready[1]]) { - return { - stopNow: true, - }; - } - return; - }; - - pluginReturn = (): PluginReturn => { - return { - onBefore: this.onBefore, - }; - }; -} diff --git a/mana/packages/mana-ui/src/enhancers/request/request.ts b/mana/packages/mana-ui/src/enhancers/request/request.ts deleted file mode 100644 index 3bbf6e90..00000000 --- a/mana/packages/mana-ui/src/enhancers/request/request.ts +++ /dev/null @@ -1,90 +0,0 @@ -import { inject, transient } from '@difizen/mana-app'; - -import { Fetch } from './fetch-core'; -import { AutoRunPlugin } from './plugin/autoRunPlugin'; -import type { Plugins } from './types'; -import { Options, Service } from './types'; - -@transient() -export class RequestService { - protected service?: Service; - protected options?: Options; - protected plugins?: Plugins[] = []; - - protected fetchInstance: Fetch; - - constructor( - @inject(Service) service: Service, - @inject(Options) options: Options, - ) { - this.service = service; - this.options = options; - // option 中 manual 赋默认值 false - const { manual = false, ...rest } = options; - const fetchOptions = { - manual, - ...rest, - }; - - const ready = fetchOptions?.ready; - - this.fetchInstance = new Fetch(service, fetchOptions, { - loading: !fetchOptions.manual && (ready ? ready[0][ready[1]] : true), - }); - - this.plugins = [AutoRunPlugin].map( - (item: any) => new item(this.fetchInstance, fetchOptions), - ); - - this.fetchInstance.pluginReturn = this.plugins.map((item: any) => - item.pluginReturn(), - ); - - if (!manual) { - const params = - this.fetchInstance.state.params || fetchOptions.defaultParams || {}; - this.fetchInstance.run(params as TParams); - } - } - - get loading() { - return this.fetchInstance.state.loading; - } - - get data() { - return this.fetchInstance.state.data; - } - - get error() { - return this.fetchInstance.state.error; - } - - get params() { - return this.fetchInstance.state.params; - } - - get refresh() { - return this.fetchInstance.refresh; - } - - get refreshAsync() { - return this.fetchInstance.refreshAsync; - } - - get run() { - return this.fetchInstance.run; - } - - get runAsync() { - return this.fetchInstance.runAsync; - } - - get mutate() { - return this.fetchInstance.mutate; - } - - // TODO: 销毁 watcher - dispose = () => { - this.fetchInstance.toDispose.dispose(); - }; -} diff --git a/mana/packages/mana-ui/src/enhancers/request/types.ts b/mana/packages/mana-ui/src/enhancers/request/types.ts deleted file mode 100644 index b7324c10..00000000 --- a/mana/packages/mana-ui/src/enhancers/request/types.ts +++ /dev/null @@ -1,121 +0,0 @@ -import type { Fetch } from './fetch-core'; - -// Service -export const Service = Symbol('mana-request-service'); -export type Service = (args: TParams) => Promise; - -// Options -export type TRequestRefreshDep = [Record, string | string[]]; -export const Options = Symbol('mana-request-options'); -export interface Options { - manual?: boolean; - - onBefore?: (params: TParams) => void; - onSuccess?: (data: TData, params: TParams) => void; - onError?: (e: Error, params: TParams) => void; - // formatResult?: (res: any) => TData; - onFinally?: (params: TParams, data?: TData, e?: Error) => void; - - defaultParams?: TParams; - - // refreshDeps - refreshDeps?: TRequestRefreshDep[]; - refreshDepsAction?: () => void; - - // loading delay - loadingDelay?: number; - - // polling - pollingInterval?: number; - pollingWhenHidden?: boolean; - pollingErrorRetryCount?: number; - - // refresh on window focus - refreshOnWindowFocus?: boolean; - focusTimespan?: number; - - // debounce - debounceWait?: number; - debounceLeading?: boolean; - debounceTrailing?: boolean; - debounceMaxWait?: number; - - // throttle - throttleWait?: number; - throttleLeading?: boolean; - throttleTrailing?: boolean; - - // cache - cacheKey?: string; - cacheTime?: number; - staleTime?: number; - setCache?: (data: CachedData) => void; - getCache?: (params: TParams) => CachedData | undefined; - - // retry - retryCount?: number; - retryInterval?: number; - - // ready - ready?: [Record, string]; -} - -export const Plugins = Symbol('mana-request-plugin'); -export type Plugins = { - ( - fetchInstance: Fetch, - options: Options, - ): PluginReturn; - onInit?: (options: Options) => Partial>; -}; - -export interface PluginReturn { - onBefore?: (params: TParams) => - | ({ - stopNow?: boolean; - returnNow?: boolean; - } & Partial>) - | void; - - onRequest?: ( - service: Service, - params: TParams, - ) => { - servicePromise?: Promise; - }; - - onSuccess?: (data: TData, params: TParams) => void; - onError?: (e: Error, params: TParams) => void; - onFinally?: (params: TParams, data?: TData, e?: Error) => void; - - onCancel?: () => void; - onMutate?: (data: TData) => void; -} - -export const FetchState = Symbol('FetchState'); -export interface FetchState { - loading: boolean; - params?: TParams; - data?: TData; - error?: Error; -} - -// TODO: 缓存plugin -export interface CachedData { - data: TData; - params: TParams; - time: number; -} - -export interface Result { - loading: boolean; - data?: TData; - error?: Error; - params: TParams; - cancel: Fetch['cancel']; - refresh: Fetch['refresh']; - refreshAsync: Fetch['refreshAsync']; - run: Fetch['run']; - runAsync: Fetch['runAsync']; - mutate: Fetch['mutate']; -} diff --git a/mana/packages/mana-ui/src/enhancers/utils/index.ts b/mana/packages/mana-ui/src/enhancers/utils/index.ts deleted file mode 100644 index 782f37c8..00000000 --- a/mana/packages/mana-ui/src/enhancers/utils/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export const isFunction = (value: unknown): value is (...args: any) => any => - typeof value === 'function'; diff --git a/mana/packages/mana-ui/src/index.spec.ts b/mana/packages/mana-ui/src/index.spec.ts deleted file mode 100644 index cbee94ac..00000000 --- a/mana/packages/mana-ui/src/index.spec.ts +++ /dev/null @@ -1,10 +0,0 @@ -import 'react'; -import assert from 'assert'; - -import { AntdTableService } from './index'; - -describe('mana-ui', () => { - it('import', () => { - assert(AntdTableService); - }); -}); diff --git a/mana/packages/mana-ui/src/index.ts b/mana/packages/mana-ui/src/index.ts deleted file mode 100644 index be6759d4..00000000 --- a/mana/packages/mana-ui/src/index.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { ManaModule } from '@difizen/mana-core'; - -import { EnhancerModule } from './enhancers'; - -export * from './enhancers'; - -export const ManaUIModule = ManaModule.create().dependOn(EnhancerModule); diff --git a/mana/packages/mana-ui/tsconfig.json b/mana/packages/mana-ui/tsconfig.json deleted file mode 100644 index c9da781c..00000000 --- a/mana/packages/mana-ui/tsconfig.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "extends": "../../tsconfig.base.json", - "compilerOptions": { - "rootDir": "./src", - "outDir": "es", - "declarationDir": "es" - }, - "types": ["jest"], - "exclude": ["node_modules"], - "include": ["src"] -}