From 279977b817399a0e03d152e0fc1944c873480b00 Mon Sep 17 00:00:00 2001 From: vben Date: Wed, 5 Apr 2023 22:29:16 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=80=90=E6=AD=A5=E6=8A=BD=E7=A6=BB?= =?UTF-8?q?=E9=83=A8=E5=88=86=E5=8C=85=E5=88=B0packages?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.development | 4 - internal/vite-config/package.json | 1 + internal/vite-config/src/config/package.ts | 38 +++- internal/vite-config/src/index.ts | 1 + package.json | 1 + packages/hooks/.commitlintrc.js | 107 +++++++++ packages/hooks/.eslintignore | 15 ++ packages/hooks/.eslintrc.js | 4 + packages/hooks/.prettierignore | 10 + packages/hooks/.prettierrc.js | 19 ++ packages/hooks/.stylelintignore | 2 + packages/hooks/.stylelintrc.js | 4 + packages/hooks/build.config.ts | 10 + packages/hooks/package.json | 38 ++++ packages/hooks/src/index.ts | 2 + .../src/lifecycle}/onMountedOrActivated.ts | 9 +- packages/hooks/tsconfig.json | 5 + packages/types/.commitlintrc.js | 107 +++++++++ packages/types/.eslintignore | 15 ++ packages/types/.eslintrc.js | 4 + packages/types/.prettierignore | 10 + packages/types/.prettierrc.js | 19 ++ packages/types/.stylelintignore | 2 + packages/types/.stylelintrc.js | 4 + packages/types/build.config.ts | 10 + packages/types/package.json | 31 +++ packages/types/src/index.ts | 1 + packages/types/src/utils.ts | 16 ++ packages/types/tsconfig.json | 5 + pnpm-lock.yaml | 210 +++++++++++++++++- src/components/Markdown/src/Markdown.vue | 12 +- .../Markdown/src/MarkdownViewer.vue | 12 +- .../Table/src/hooks/useTableScroll.ts | 2 +- src/components/Tinymce/src/Editor.vue | 2 +- src/directives/ripple/index.less | 4 +- src/enums/sizeEnum.ts | 14 -- src/hooks/component/useFormItem.ts | 15 +- src/hooks/core/useLockFn.ts | 17 -- src/hooks/web/useContentHeight.ts | 2 +- src/utils/env.ts | 1 - types/global.d.ts | 1 - 41 files changed, 726 insertions(+), 60 deletions(-) create mode 100644 packages/hooks/.commitlintrc.js create mode 100644 packages/hooks/.eslintignore create mode 100644 packages/hooks/.eslintrc.js create mode 100644 packages/hooks/.prettierignore create mode 100644 packages/hooks/.prettierrc.js create mode 100644 packages/hooks/.stylelintignore create mode 100644 packages/hooks/.stylelintrc.js create mode 100644 packages/hooks/build.config.ts create mode 100644 packages/hooks/package.json create mode 100644 packages/hooks/src/index.ts rename {src/hooks/core => packages/hooks/src/lifecycle}/onMountedOrActivated.ts (50%) create mode 100644 packages/hooks/tsconfig.json create mode 100644 packages/types/.commitlintrc.js create mode 100644 packages/types/.eslintignore create mode 100644 packages/types/.eslintrc.js create mode 100644 packages/types/.prettierignore create mode 100644 packages/types/.prettierrc.js create mode 100644 packages/types/.stylelintignore create mode 100644 packages/types/.stylelintrc.js create mode 100644 packages/types/build.config.ts create mode 100644 packages/types/package.json create mode 100644 packages/types/src/index.ts create mode 100644 packages/types/src/utils.ts create mode 100644 packages/types/tsconfig.json delete mode 100644 src/hooks/core/useLockFn.ts diff --git a/.env.development b/.env.development index 9f061593..ed7a6b20 100644 --- a/.env.development +++ b/.env.development @@ -4,10 +4,6 @@ VITE_USE_MOCK = true # public path VITE_PUBLIC_PATH = / -# Cross-domain proxy, you can configure multiple -# Please note that no line breaks -VITE_PROXY = [["/basic-api","http://localhost:3000"],["/upload","http://localhost:3300/upload"]] - # Basic interface address SPA VITE_GLOB_API_URL=/basic-api diff --git a/internal/vite-config/package.json b/internal/vite-config/package.json index 60843a2c..6bdf96f3 100644 --- a/internal/vite-config/package.json +++ b/internal/vite-config/package.json @@ -47,6 +47,7 @@ "sass": "^1.60.0", "unocss": "^0.50.6", "vite-plugin-compression": "^0.5.1", + "vite-plugin-dts": "^2.2.0", "vite-plugin-html": "^3.2.0", "vite-plugin-mock": "^2.9.6", "vite-plugin-purge-icons": "^0.9.2", diff --git a/internal/vite-config/src/config/package.ts b/internal/vite-config/src/config/package.ts index 4a8bf059..78e62bc4 100644 --- a/internal/vite-config/src/config/package.ts +++ b/internal/vite-config/src/config/package.ts @@ -1,5 +1,39 @@ -function definePackageConfig() { - // TODO: +import { type UserConfig, defineConfig, mergeConfig } from 'vite'; +import { readPackageJSON } from 'pkg-types'; +import { commonConfig } from './common'; +import dts from 'vite-plugin-dts'; + +interface DefineOptions { + overrides?: UserConfig; + options?: {}; +} + +function definePackageConfig(defineOptions: DefineOptions = {}) { + const { overrides = {} } = defineOptions; + const root = process.cwd(); + return defineConfig(async () => { + const { dependencies = {}, peerDependencies = {} } = await readPackageJSON(root); + const packageConfig: UserConfig = { + build: { + lib: { + entry: 'src/index.ts', + formats: ['es'], + fileName: () => 'index.mjs', + }, + rollupOptions: { + external: [...Object.keys(dependencies), ...Object.keys(peerDependencies)], + }, + }, + plugins: [ + dts({ + logLevel: 'error', + }), + ], + }; + const mergedConfig = mergeConfig(commonConfig, packageConfig); + + return mergeConfig(mergedConfig, overrides); + }); } export { definePackageConfig }; diff --git a/internal/vite-config/src/index.ts b/internal/vite-config/src/index.ts index d012651d..9ef1e80f 100644 --- a/internal/vite-config/src/index.ts +++ b/internal/vite-config/src/index.ts @@ -1 +1,2 @@ export * from './config/application'; +export * from './config/package'; diff --git a/package.json b/package.json index afa19b0c..8dfcef55 100644 --- a/package.json +++ b/package.json @@ -70,6 +70,7 @@ "@iconify/iconify": "^3.1.0", "@logicflow/core": "^1.2.1", "@logicflow/extension": "^1.2.1", + "@vben/hooks": "workspace:*", "@vueuse/core": "^9.13.0", "@vueuse/shared": "^9.13.0", "@zxcvbn-ts/core": "^2.2.1", diff --git a/packages/hooks/.commitlintrc.js b/packages/hooks/.commitlintrc.js new file mode 100644 index 00000000..151ead3c --- /dev/null +++ b/packages/hooks/.commitlintrc.js @@ -0,0 +1,107 @@ +const fs = require('fs'); +const path = require('path'); +const { execSync } = require('child_process'); + +const scopes = fs + .readdirSync(path.resolve(__dirname, 'src'), { withFileTypes: true }) + .filter((dirent) => dirent.isDirectory()) + .map((dirent) => dirent.name.replace(/s$/, '')); + +// precomputed scope +const scopeComplete = execSync('git status --porcelain || true') + .toString() + .trim() + .split('\n') + .find((r) => ~r.indexOf('M src')) + ?.replace(/(\/)/g, '%%') + ?.match(/src%%((\w|-)*)/)?.[1] + ?.replace(/s$/, ''); + +/** @type {import('cz-git').UserConfig} */ +module.exports = { + ignores: [(commit) => commit.includes('init')], + extends: ['@commitlint/config-conventional'], + rules: { + 'body-leading-blank': [2, 'always'], + 'footer-leading-blank': [1, 'always'], + 'header-max-length': [2, 'always', 108], + 'subject-empty': [2, 'never'], + 'type-empty': [2, 'never'], + 'subject-case': [0], + 'type-enum': [ + 2, + 'always', + [ + 'feat', + 'fix', + 'perf', + 'style', + 'docs', + 'test', + 'refactor', + 'build', + 'ci', + 'chore', + 'revert', + 'wip', + 'workflow', + 'types', + 'release', + ], + ], + }, + prompt: { + /** @use `yarn commit :f` */ + alias: { + f: 'docs: fix typos', + r: 'docs: update README', + s: 'style: update code format', + b: 'build: bump dependencies', + c: 'chore: update config', + }, + customScopesAlign: !scopeComplete ? 'top' : 'bottom', + defaultScope: scopeComplete, + scopes: [...scopes, 'mock'], + allowEmptyIssuePrefixs: false, + allowCustomIssuePrefixs: false, + + // English + typesAppend: [ + { value: 'wip', name: 'wip: work in process' }, + { value: 'workflow', name: 'workflow: workflow improvements' }, + { value: 'types', name: 'types: type definition file changes' }, + ], + + // 中英文对照版 + // messages: { + // type: '选择你要提交的类型 :', + // scope: '选择一个提交范围 (可选):', + // customScope: '请输入自定义的提交范围 :', + // subject: '填写简短精炼的变更描述 :\n', + // body: '填写更加详细的变更描述 (可选)。使用 "|" 换行 :\n', + // breaking: '列举非兼容性重大的变更 (可选)。使用 "|" 换行 :\n', + // footerPrefixsSelect: '选择关联issue前缀 (可选):', + // customFooterPrefixs: '输入自定义issue前缀 :', + // footer: '列举关联issue (可选) 例如: #31, #I3244 :\n', + // confirmCommit: '是否提交或修改commit ?', + // }, + // types: [ + // { value: 'feat', name: 'feat: 新增功能' }, + // { value: 'fix', name: 'fix: 修复缺陷' }, + // { value: 'docs', name: 'docs: 文档变更' }, + // { value: 'style', name: 'style: 代码格式' }, + // { value: 'refactor', name: 'refactor: 代码重构' }, + // { value: 'perf', name: 'perf: 性能优化' }, + // { value: 'test', name: 'test: 添加疏漏测试或已有测试改动' }, + // { value: 'build', name: 'build: 构建流程、外部依赖变更 (如升级 npm 包、修改打包配置等)' }, + // { value: 'ci', name: 'ci: 修改 CI 配置、脚本' }, + // { value: 'revert', name: 'revert: 回滚 commit' }, + // { value: 'chore', name: 'chore: 对构建过程或辅助工具和库的更改 (不影响源文件、测试用例)' }, + // { value: 'wip', name: 'wip: 正在开发中' }, + // { value: 'workflow', name: 'workflow: 工作流程改进' }, + // { value: 'types', name: 'types: 类型定义文件修改' }, + // ], + // emptyScopesAlias: 'empty: 不填写', + // customScopesAlias: 'custom: 自定义', + }, +}; diff --git a/packages/hooks/.eslintignore b/packages/hooks/.eslintignore new file mode 100644 index 00000000..348631b2 --- /dev/null +++ b/packages/hooks/.eslintignore @@ -0,0 +1,15 @@ + +*.sh +node_modules +*.md +*.woff +*.ttf +.vscode +.idea +dist +/public +/docs +.husky +.local +/bin +Dockerfile diff --git a/packages/hooks/.eslintrc.js b/packages/hooks/.eslintrc.js new file mode 100644 index 00000000..870eb080 --- /dev/null +++ b/packages/hooks/.eslintrc.js @@ -0,0 +1,4 @@ +module.exports = { + root: true, + extends: ['@vben'], +}; diff --git a/packages/hooks/.prettierignore b/packages/hooks/.prettierignore new file mode 100644 index 00000000..a1759d04 --- /dev/null +++ b/packages/hooks/.prettierignore @@ -0,0 +1,10 @@ +dist +.local +.output.js +node_modules + +**/*.svg +**/*.sh + +public +.npmrc diff --git a/packages/hooks/.prettierrc.js b/packages/hooks/.prettierrc.js new file mode 100644 index 00000000..4a24e88c --- /dev/null +++ b/packages/hooks/.prettierrc.js @@ -0,0 +1,19 @@ +module.exports = { + printWidth: 100, + semi: true, + vueIndentScriptAndStyle: true, + singleQuote: true, + trailingComma: 'all', + proseWrap: 'never', + htmlWhitespaceSensitivity: 'strict', + endOfLine: 'auto', + plugins: ['prettier-plugin-packagejson'], + overrides: [ + { + files: '.*rc', + options: { + parser: 'json', + }, + }, + ], +}; diff --git a/packages/hooks/.stylelintignore b/packages/hooks/.stylelintignore new file mode 100644 index 00000000..6cd69e0b --- /dev/null +++ b/packages/hooks/.stylelintignore @@ -0,0 +1,2 @@ +dist +public diff --git a/packages/hooks/.stylelintrc.js b/packages/hooks/.stylelintrc.js new file mode 100644 index 00000000..65320e77 --- /dev/null +++ b/packages/hooks/.stylelintrc.js @@ -0,0 +1,4 @@ +module.exports = { + root: true, + extends: ['@vben/stylelint-config'], +}; diff --git a/packages/hooks/build.config.ts b/packages/hooks/build.config.ts new file mode 100644 index 00000000..20c8b54a --- /dev/null +++ b/packages/hooks/build.config.ts @@ -0,0 +1,10 @@ +import { defineBuildConfig } from 'unbuild'; + +export default defineBuildConfig({ + clean: true, + entries: ['src/index'], + declaration: true, + rollup: { + emitCJS: true, + }, +}); diff --git a/packages/hooks/package.json b/packages/hooks/package.json new file mode 100644 index 00000000..e27e9ea9 --- /dev/null +++ b/packages/hooks/package.json @@ -0,0 +1,38 @@ +{ + "name": "@vben/hooks", + "version": "1.0.0", + "homepage": "https://github.com/vbenjs/vue-vben-admin", + "bugs": { + "url": "https://github.com/vbenjs/vue-vben-admin/issues" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/vbenjs/vue-vben-admin.git", + "directory": "packages/hooks" + }, + "license": "MIT", + "sideEffects": false, + "exports": { + ".": { + "default": "./src/index.ts" + } + }, + "main": "./src/index.ts", + "module": "./src/index.ts", + "files": [ + "dist" + ], + "scripts": { + "//build": "pnpm unbuild", + "//stub": "pnpm unbuild --stub", + "clean": "pnpm rimraf .turbo node_modules dist", + "lint": "pnpm eslint ." + }, + "dependencies": { + "@vueuse/core": "^9.13.0", + "vue": "^3.2.47" + }, + "devDependencies": { + "@vben/types": "workspace:*" + } +} diff --git a/packages/hooks/src/index.ts b/packages/hooks/src/index.ts new file mode 100644 index 00000000..7610804d --- /dev/null +++ b/packages/hooks/src/index.ts @@ -0,0 +1,2 @@ +// life-cycle +export * from './lifecycle/onMountedOrActivated'; diff --git a/src/hooks/core/onMountedOrActivated.ts b/packages/hooks/src/lifecycle/onMountedOrActivated.ts similarity index 50% rename from src/hooks/core/onMountedOrActivated.ts rename to packages/hooks/src/lifecycle/onMountedOrActivated.ts index ffabf18d..6037593c 100644 --- a/src/hooks/core/onMountedOrActivated.ts +++ b/packages/hooks/src/lifecycle/onMountedOrActivated.ts @@ -1,6 +1,11 @@ +import { type AnyFunction } from '@vben/types'; import { nextTick, onMounted, onActivated } from 'vue'; -export function onMountedOrActivated(hook: Fn) { +/** + * 在 OnMounted 或者 OnActivated 时触发 + * @param hook 任何函数(包括异步函数) + */ +function onMountedOrActivated(hook: AnyFunction) { let mounted: boolean; onMounted(() => { @@ -16,3 +21,5 @@ export function onMountedOrActivated(hook: Fn) { } }); } + +export { onMountedOrActivated }; diff --git a/packages/hooks/tsconfig.json b/packages/hooks/tsconfig.json new file mode 100644 index 00000000..41b8470a --- /dev/null +++ b/packages/hooks/tsconfig.json @@ -0,0 +1,5 @@ +{ + "$schema": "https://json.schemastore.org/tsconfig", + "extends": "@vben/ts-config/vue.json", + "include": ["src"] +} diff --git a/packages/types/.commitlintrc.js b/packages/types/.commitlintrc.js new file mode 100644 index 00000000..151ead3c --- /dev/null +++ b/packages/types/.commitlintrc.js @@ -0,0 +1,107 @@ +const fs = require('fs'); +const path = require('path'); +const { execSync } = require('child_process'); + +const scopes = fs + .readdirSync(path.resolve(__dirname, 'src'), { withFileTypes: true }) + .filter((dirent) => dirent.isDirectory()) + .map((dirent) => dirent.name.replace(/s$/, '')); + +// precomputed scope +const scopeComplete = execSync('git status --porcelain || true') + .toString() + .trim() + .split('\n') + .find((r) => ~r.indexOf('M src')) + ?.replace(/(\/)/g, '%%') + ?.match(/src%%((\w|-)*)/)?.[1] + ?.replace(/s$/, ''); + +/** @type {import('cz-git').UserConfig} */ +module.exports = { + ignores: [(commit) => commit.includes('init')], + extends: ['@commitlint/config-conventional'], + rules: { + 'body-leading-blank': [2, 'always'], + 'footer-leading-blank': [1, 'always'], + 'header-max-length': [2, 'always', 108], + 'subject-empty': [2, 'never'], + 'type-empty': [2, 'never'], + 'subject-case': [0], + 'type-enum': [ + 2, + 'always', + [ + 'feat', + 'fix', + 'perf', + 'style', + 'docs', + 'test', + 'refactor', + 'build', + 'ci', + 'chore', + 'revert', + 'wip', + 'workflow', + 'types', + 'release', + ], + ], + }, + prompt: { + /** @use `yarn commit :f` */ + alias: { + f: 'docs: fix typos', + r: 'docs: update README', + s: 'style: update code format', + b: 'build: bump dependencies', + c: 'chore: update config', + }, + customScopesAlign: !scopeComplete ? 'top' : 'bottom', + defaultScope: scopeComplete, + scopes: [...scopes, 'mock'], + allowEmptyIssuePrefixs: false, + allowCustomIssuePrefixs: false, + + // English + typesAppend: [ + { value: 'wip', name: 'wip: work in process' }, + { value: 'workflow', name: 'workflow: workflow improvements' }, + { value: 'types', name: 'types: type definition file changes' }, + ], + + // 中英文对照版 + // messages: { + // type: '选择你要提交的类型 :', + // scope: '选择一个提交范围 (可选):', + // customScope: '请输入自定义的提交范围 :', + // subject: '填写简短精炼的变更描述 :\n', + // body: '填写更加详细的变更描述 (可选)。使用 "|" 换行 :\n', + // breaking: '列举非兼容性重大的变更 (可选)。使用 "|" 换行 :\n', + // footerPrefixsSelect: '选择关联issue前缀 (可选):', + // customFooterPrefixs: '输入自定义issue前缀 :', + // footer: '列举关联issue (可选) 例如: #31, #I3244 :\n', + // confirmCommit: '是否提交或修改commit ?', + // }, + // types: [ + // { value: 'feat', name: 'feat: 新增功能' }, + // { value: 'fix', name: 'fix: 修复缺陷' }, + // { value: 'docs', name: 'docs: 文档变更' }, + // { value: 'style', name: 'style: 代码格式' }, + // { value: 'refactor', name: 'refactor: 代码重构' }, + // { value: 'perf', name: 'perf: 性能优化' }, + // { value: 'test', name: 'test: 添加疏漏测试或已有测试改动' }, + // { value: 'build', name: 'build: 构建流程、外部依赖变更 (如升级 npm 包、修改打包配置等)' }, + // { value: 'ci', name: 'ci: 修改 CI 配置、脚本' }, + // { value: 'revert', name: 'revert: 回滚 commit' }, + // { value: 'chore', name: 'chore: 对构建过程或辅助工具和库的更改 (不影响源文件、测试用例)' }, + // { value: 'wip', name: 'wip: 正在开发中' }, + // { value: 'workflow', name: 'workflow: 工作流程改进' }, + // { value: 'types', name: 'types: 类型定义文件修改' }, + // ], + // emptyScopesAlias: 'empty: 不填写', + // customScopesAlias: 'custom: 自定义', + }, +}; diff --git a/packages/types/.eslintignore b/packages/types/.eslintignore new file mode 100644 index 00000000..348631b2 --- /dev/null +++ b/packages/types/.eslintignore @@ -0,0 +1,15 @@ + +*.sh +node_modules +*.md +*.woff +*.ttf +.vscode +.idea +dist +/public +/docs +.husky +.local +/bin +Dockerfile diff --git a/packages/types/.eslintrc.js b/packages/types/.eslintrc.js new file mode 100644 index 00000000..870eb080 --- /dev/null +++ b/packages/types/.eslintrc.js @@ -0,0 +1,4 @@ +module.exports = { + root: true, + extends: ['@vben'], +}; diff --git a/packages/types/.prettierignore b/packages/types/.prettierignore new file mode 100644 index 00000000..a1759d04 --- /dev/null +++ b/packages/types/.prettierignore @@ -0,0 +1,10 @@ +dist +.local +.output.js +node_modules + +**/*.svg +**/*.sh + +public +.npmrc diff --git a/packages/types/.prettierrc.js b/packages/types/.prettierrc.js new file mode 100644 index 00000000..4a24e88c --- /dev/null +++ b/packages/types/.prettierrc.js @@ -0,0 +1,19 @@ +module.exports = { + printWidth: 100, + semi: true, + vueIndentScriptAndStyle: true, + singleQuote: true, + trailingComma: 'all', + proseWrap: 'never', + htmlWhitespaceSensitivity: 'strict', + endOfLine: 'auto', + plugins: ['prettier-plugin-packagejson'], + overrides: [ + { + files: '.*rc', + options: { + parser: 'json', + }, + }, + ], +}; diff --git a/packages/types/.stylelintignore b/packages/types/.stylelintignore new file mode 100644 index 00000000..6cd69e0b --- /dev/null +++ b/packages/types/.stylelintignore @@ -0,0 +1,2 @@ +dist +public diff --git a/packages/types/.stylelintrc.js b/packages/types/.stylelintrc.js new file mode 100644 index 00000000..65320e77 --- /dev/null +++ b/packages/types/.stylelintrc.js @@ -0,0 +1,4 @@ +module.exports = { + root: true, + extends: ['@vben/stylelint-config'], +}; diff --git a/packages/types/build.config.ts b/packages/types/build.config.ts new file mode 100644 index 00000000..20c8b54a --- /dev/null +++ b/packages/types/build.config.ts @@ -0,0 +1,10 @@ +import { defineBuildConfig } from 'unbuild'; + +export default defineBuildConfig({ + clean: true, + entries: ['src/index'], + declaration: true, + rollup: { + emitCJS: true, + }, +}); diff --git a/packages/types/package.json b/packages/types/package.json new file mode 100644 index 00000000..e2d90237 --- /dev/null +++ b/packages/types/package.json @@ -0,0 +1,31 @@ +{ + "name": "@vben/types", + "version": "1.0.0", + "homepage": "https://github.com/vbenjs/vue-vben-admin", + "bugs": { + "url": "https://github.com/vbenjs/vue-vben-admin/issues" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/vbenjs/vue-vben-admin.git", + "directory": "packages/types" + }, + "license": "MIT", + "sideEffects": false, + "exports": { + ".": { + "default": "./src/index.ts" + } + }, + "main": "./src/index.ts", + "module": "./src/index.ts", + "files": [ + "dist" + ], + "scripts": { + "//build": "pnpm unbuild", + "//stub": "pnpm unbuild --stub", + "clean": "pnpm rimraf .turbo node_modules dist", + "lint": "pnpm eslint ." + } +} diff --git a/packages/types/src/index.ts b/packages/types/src/index.ts new file mode 100644 index 00000000..04bca77e --- /dev/null +++ b/packages/types/src/index.ts @@ -0,0 +1 @@ +export * from './utils'; diff --git a/packages/types/src/utils.ts b/packages/types/src/utils.ts new file mode 100644 index 00000000..d55f1a9b --- /dev/null +++ b/packages/types/src/utils.ts @@ -0,0 +1,16 @@ +/** + * 任意类型的函数 + */ +type AnyFunction = AnyNormalFunction | AnyPromiseFunction; + +/** + * 任意类型的异步函数 + */ +type AnyPromiseFunction = (...arg: any) => PromiseLike; + +/** + * 任意类型的普通函数 + */ +type AnyNormalFunction = (...arg: any) => any; + +export { type AnyFunction, type AnyPromiseFunction, type AnyNormalFunction }; diff --git a/packages/types/tsconfig.json b/packages/types/tsconfig.json new file mode 100644 index 00000000..41b8470a --- /dev/null +++ b/packages/types/tsconfig.json @@ -0,0 +1,5 @@ +{ + "$schema": "https://json.schemastore.org/tsconfig", + "extends": "@vben/ts-config/vue.json", + "include": ["src"] +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f532b629..e4e0bd35 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -16,6 +16,9 @@ importers: '@logicflow/extension': specifier: ^1.2.1 version: 1.2.1 + '@vben/hooks': + specifier: workspace:* + version: link:packages/hooks '@vueuse/core': specifier: ^9.13.0 version: 9.13.0(vue@3.2.47) @@ -415,6 +418,9 @@ importers: vite-plugin-compression: specifier: ^0.5.1 version: 0.5.1(vite@4.3.0-beta.1) + vite-plugin-dts: + specifier: ^2.2.0 + version: 2.2.0(@types/node@18.15.11)(rollup@2.79.1)(vite@4.3.0-beta.1) vite-plugin-html: specifier: ^3.2.0 version: 3.2.0(vite@4.3.0-beta.1) @@ -428,6 +434,21 @@ importers: specifier: ^2.0.1 version: 2.0.1(vite@4.3.0-beta.1) + packages/hooks: + dependencies: + '@vueuse/core': + specifier: ^9.13.0 + version: 9.13.0(vue@3.2.47) + vue: + specifier: ^3.2.47 + version: 3.2.47 + devDependencies: + '@vben/types': + specifier: workspace:* + version: link:../types + + packages/types: {} + packages: /@ampproject/remapping@2.2.0: @@ -1391,6 +1412,49 @@ packages: preact: 10.13.2 dev: false + /@microsoft/api-extractor-model@7.26.4(@types/node@18.15.11): + resolution: {integrity: sha512-PDCgCzXDo+SLY5bsfl4bS7hxaeEtnXj7XtuzEE+BtALp7B5mK/NrS2kHWU69pohgsRmEALycQdaQPXoyT2i5MQ==} + dependencies: + '@microsoft/tsdoc': 0.14.2 + '@microsoft/tsdoc-config': 0.16.2 + '@rushstack/node-core-library': 3.55.2(@types/node@18.15.11) + transitivePeerDependencies: + - '@types/node' + dev: true + + /@microsoft/api-extractor@7.34.4(@types/node@18.15.11): + resolution: {integrity: sha512-HOdcci2nT40ejhwPC3Xja9G+WSJmWhCUKKryRfQYsmE9cD+pxmBaKBKCbuS9jUcl6bLLb4Gz+h7xEN5r0QiXnQ==} + hasBin: true + dependencies: + '@microsoft/api-extractor-model': 7.26.4(@types/node@18.15.11) + '@microsoft/tsdoc': 0.14.2 + '@microsoft/tsdoc-config': 0.16.2 + '@rushstack/node-core-library': 3.55.2(@types/node@18.15.11) + '@rushstack/rig-package': 0.3.18 + '@rushstack/ts-command-line': 4.13.2 + colors: 1.2.5 + lodash: 4.17.21 + resolve: 1.22.1 + semver: 7.3.8 + source-map: 0.6.1 + typescript: 4.8.4 + transitivePeerDependencies: + - '@types/node' + dev: true + + /@microsoft/tsdoc-config@0.16.2: + resolution: {integrity: sha512-OGiIzzoBLgWWR0UdRJX98oYO+XKGf7tiK4Zk6tQ/E4IJqGCe7dvkTvgDZV5cFJUzLGDOjeAXrnZoA6QkVySuxw==} + dependencies: + '@microsoft/tsdoc': 0.14.2 + ajv: 6.12.6 + jju: 1.4.0 + resolve: 1.19.0 + dev: true + + /@microsoft/tsdoc@0.14.2: + resolution: {integrity: sha512-9b8mPpKrfeGRuhFH5iO1iwCLeIIsV6+H1sRfxbkoGXIyQE2BTsPd9zqSqQJ+pv5sJ/hT5M1zvOFL02MnEezFug==} + dev: true + /@nodelib/fs.scandir@2.1.5: resolution: {integrity: sha512-vq24Bq3ym5HEQm2NKCr3yXDwjc7vTsEThRDnkp2DK9p1uqLR+DHurm/NOTo0KG7HYHU7eppKZj3MyqYuMBf62g==} engines: {node: '>= 8'} @@ -1681,6 +1745,40 @@ packages: rollup: 3.20.2 dev: true + /@rushstack/node-core-library@3.55.2(@types/node@18.15.11): + resolution: {integrity: sha512-SaLe/x/Q/uBVdNFK5V1xXvsVps0y7h1sN7aSJllQyFbugyOaxhNRF25bwEDnicARNEjJw0pk0lYnJQ9Kr6ev0A==} + peerDependencies: + '@types/node': '*' + peerDependenciesMeta: + '@types/node': + optional: true + dependencies: + '@types/node': 18.15.11 + colors: 1.2.5 + fs-extra: 7.0.1 + import-lazy: 4.0.0 + jju: 1.4.0 + resolve: 1.22.1 + semver: 7.3.8 + z-schema: 5.0.5 + dev: true + + /@rushstack/rig-package@0.3.18: + resolution: {integrity: sha512-SGEwNTwNq9bI3pkdd01yCaH+gAsHqs0uxfGvtw9b0LJXH52qooWXnrFTRRLG1aL9pf+M2CARdrA9HLHJys3jiQ==} + dependencies: + resolve: 1.22.1 + strip-json-comments: 3.1.1 + dev: true + + /@rushstack/ts-command-line@4.13.2: + resolution: {integrity: sha512-bCU8qoL9HyWiciltfzg7GqdfODUeda/JpI0602kbN5YH22rzTxyqYvv7aRLENCM7XCQ1VRs7nMkEqgJUOU8Sag==} + dependencies: + '@types/argparse': 1.0.38 + argparse: 1.0.10 + colors: 1.2.5 + string-argv: 0.3.1 + dev: true + /@simonwep/pickr@1.8.2: resolution: {integrity: sha512-/l5w8BIkrpP6n1xsetx9MWPWlU6OblN5YgZZphxan0Tq4BByTCETL6lyIeY8lagalS2Nbt4F2W034KHLIiunKA==} dependencies: @@ -1697,6 +1795,15 @@ packages: engines: {node: '>=10.13.0'} dev: true + /@ts-morph/common@0.18.1: + resolution: {integrity: sha512-RVE+zSRICWRsfrkAw5qCAK+4ZH9kwEFv5h0+/YeHTLieWP7F4wWq4JsKFuNWG+fYh/KF+8rAtgdj5zb2mm+DVA==} + dependencies: + fast-glob: 3.2.12 + minimatch: 5.1.6 + mkdirp: 1.0.4 + path-browserify: 1.0.1 + dev: true + /@tsconfig/node10@1.0.9: resolution: {integrity: sha512-jNsYVVxU8v5g43Erja32laIDHXeoNvFEpX33OK4d6hljo3jDhCBDhx5dhCCTMWUojscpAagGiRkBKxpdl9fxqA==} dev: true @@ -1718,6 +1825,10 @@ packages: dependencies: '@types/node': 18.15.11 + /@types/argparse@1.0.38: + resolution: {integrity: sha512-ebDJ9b0e702Yr7pWgB0jzm+CX4Srzz8RcXtLJDJB+BSccqMa36uyH/zUsSYao5+BD1ytv3k3rPYCq4mAE1hsXA==} + dev: true + /@types/body-parser@1.19.2: resolution: {integrity: sha512-ALYone6pm6QmwZoAgeyNksccT9Q4AWZQ6PvfwR37GT6r6FWUPguq6sUmNGSMV2Wr761oQoBxwGGa6DR5o1DC9g==} dependencies: @@ -3206,6 +3317,10 @@ packages: engines: {iojs: '>= 1.0.0', node: '>= 0.12.0'} dev: false + /code-block-writer@11.0.3: + resolution: {integrity: sha512-NiujjUFB4SwScJq2bwbYUtXbZhBSlY6vYzm++3Q6oC+U+injTqfPYFK8wS9COOmb2lueqp0ZRB4nK1VYeHgNyw==} + dev: true + /codemirror@5.65.12: resolution: {integrity: sha512-z2jlHBocElRnPYysN2HAuhXbO3DNB0bcSKmNz3hcWR2Js2Dkhc1bEOxG93Z3DeUrnm+qx56XOY5wQmbP5KY0sw==} dev: false @@ -3250,6 +3365,11 @@ packages: resolution: {integrity: sha512-3tlv/dIP7FWvj3BsbHrGLJ6l/oKh1O3TcgBqMn+yyCagOxc23fyzDS6HypQbgxWbkpDnf52p1LuR4eWDQ/K9WQ==} dev: true + /colors@1.2.5: + resolution: {integrity: sha512-erNRLao/Y3Fv54qUa0LBB+//Uf3YwMUmdJinN20yMXm9zdKKqH9wt7R9IIVZ+K7ShzfpLV/Zg8+VyrBJYB4lpg==} + engines: {node: '>=0.1.90'} + dev: true + /combined-stream@1.0.8: resolution: {integrity: sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==} engines: {node: '>= 0.8'} @@ -3287,7 +3407,6 @@ packages: /commander@9.5.0: resolution: {integrity: sha512-KRs7WVDKg86PWiuAqhDrAQnTXZKraVcCc6vFdL14qrZ/DcWwuRo7VoiYXalXO7S5GKpqYiVEwCbgFDfxNHKJBQ==} engines: {node: ^12.20.0 || >=14} - dev: false /commondir@1.0.1: resolution: {integrity: sha512-W9pAhw0ja1Edb5GVdIF1mjZw/ASI0AlShXM83UUGe2DVr5TdAPEA1OA8m/g8zWp9x6On7gqufY+FatDbC3MDQg==} @@ -4543,6 +4662,15 @@ packages: jsonfile: 6.1.0 universalify: 2.0.0 + /fs-extra@7.0.1: + resolution: {integrity: sha512-YJDaCJZEnBmcbw13fvdAM9AwNOJwOzrE4pqMqBq5nFiEqXUqHwlK4B+3pUw6JNvfSPtX05xFHtYy/1ni01eGCw==} + engines: {node: '>=6 <7 || >=8'} + dependencies: + graceful-fs: 4.2.11 + jsonfile: 4.0.0 + universalify: 0.1.2 + dev: true + /fs-extra@8.1.0: resolution: {integrity: sha512-yhlQgA6mnOJUKOsRUFsgJdQCvkKhcz8tlZG5HBQfReYZy46OwLcY+Zia0mtdHsOo9y/hP+CxMN0TU9QxoOtG4g==} engines: {node: '>=6 <7 || >=8'} @@ -5350,6 +5478,10 @@ packages: hasBin: true dev: true + /jju@1.4.0: + resolution: {integrity: sha512-8wb9Yw966OSxApiCt0K3yNJL8pnNeIv+OEq2YMidz4FKP6nonSRoOXc80iXY4JaN2FC11B9qsNmDsm+ZOfMROA==} + dev: true + /joycon@3.1.1: resolution: {integrity: sha512-34wB/Y7MW7bzjKRjUKTa46I2Z7eV62Rkhva+KkopW7Qvv/OSWBqvkSY7vusOPrNuZcUG3tApvdVgNB8POj3SPw==} engines: {node: '>=10'} @@ -5791,6 +5923,10 @@ packages: resolution: {integrity: sha512-C5N2Z3DgnnKr0LOpv/hKCgKdb7ZZwafIrsesve6lmzvZIRZRGaZ/l6Q8+2W7NaT+ZwO3fFlSCzCzrDCFdJfZ4g==} dev: false + /lodash.get@4.4.2: + resolution: {integrity: sha512-z+Uw/vLuy6gQe8cfaFWD7p0wVv8fJl3mbzXh33RS+0oW2wvUqiRXiQ69gLWSLpgB5/6sU+r6BlQR0MBILadqTQ==} + dev: true + /lodash.groupby@4.6.0: resolution: {integrity: sha512-5dcWxm23+VAoz+awKmBaiBvzox8+RqMgFhi7UvX9DHZr2HdxHXM/Wrf8cfKpsW37RNrvtPn6hSwNqurSILbmJw==} dev: false @@ -5801,7 +5937,6 @@ packages: /lodash.isequal@4.5.0: resolution: {integrity: sha512-pDo3lu8Jhfjqls6GkMgpahsF9kCyayhgykjyLMNFTKWrpVdAQtYyB4muAMWozBB4ig/dtWAmsMxLEI8wuz+DYQ==} - dev: false /lodash.isfunction@3.0.9: resolution: {integrity: sha512-AirXNj15uRIMMPihnkInB4i3NHeb4iBtNg9WRWuK2o31S+ePwwNmDPaTL3o7dTJ+VXNZim7rFs4rxN4YU1oUJw==} @@ -5923,6 +6058,13 @@ packages: '@jridgewell/sourcemap-codec': 1.4.14 dev: true + /magic-string@0.29.0: + resolution: {integrity: sha512-WcfidHrDjMY+eLjlU+8OvwREqHwpgCeKVBUpQ3OhYYuvfaYCUgcbuBzappNzZvg/v8onU3oQj+BYpkOJe9Iw4Q==} + engines: {node: '>=12'} + dependencies: + '@jridgewell/sourcemap-codec': 1.4.14 + dev: true + /magic-string@0.30.0: resolution: {integrity: sha512-LA+31JYDJLs82r2ScLrlz1GjSgu66ZV518eyWT+S8VhyQn/JL0u9MeBOvQMGYiPk1DBiSN9DDMOcXvigJZaViQ==} engines: {node: '>=12'} @@ -6661,6 +6803,10 @@ packages: engines: {node: '>=0.10.0'} dev: true + /path-browserify@1.0.1: + resolution: {integrity: sha512-b7uo2UCUOYZcnF/3ID0lulOJi/bafxa1xPe7ZPsammBSpjSWQkjNxlt635YGS2MiR9GjvuXCtz2emr3jbsz98g==} + dev: true + /path-exists@4.0.0: resolution: {integrity: sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==} engines: {node: '>=8'} @@ -7330,6 +7476,13 @@ packages: deprecated: https://github.com/lydell/resolve-url#deprecated dev: true + /resolve@1.19.0: + resolution: {integrity: sha512-rArEXAgsBG4UgRGcynxWIWKFvh/XZCcS8UJdHhwy91zwAvCZIbcs+vAbflgBnNjYMs/i/i+/Ux6IZhML1yPvxg==} + dependencies: + is-core-module: 2.11.0 + path-parse: 1.0.7 + dev: true + /resolve@1.22.1: resolution: {integrity: sha512-nBpuuYuY5jFsli/JIs1oldw6fOQCBioohqWZg/2hiaOybXOft4lonv85uDOKXdf8rhyK159cxU5cDcK/NKk8zw==} hasBin: true @@ -8397,6 +8550,13 @@ packages: resolution: {integrity: sha512-Y/arvbn+rrz3JCKl9C4kVNfTfSm2/mEp5FSz5EsZSANGPSlQrpRI5M4PKF+mJnE52jOO90PnPSc3Ur3bTQw0gA==} dev: true + /ts-morph@17.0.1: + resolution: {integrity: sha512-10PkHyXmrtsTvZSL+cqtJLTgFXkU43Gd0JCc0Rw6GchWbqKe0Rwgt1v3ouobTZwQzF1mGhDeAlWYBMGRV7y+3g==} + dependencies: + '@ts-morph/common': 0.18.1 + code-block-writer: 11.0.3 + dev: true + /ts-node@10.9.1(@types/node@18.15.11)(typescript@5.0.3): resolution: {integrity: sha512-NtVysVPkxxrwFGUUxGYhfux8k78pQB3JqYBXlLRZgdGUqTO5wU/UyHop5p70iEbGhB7q5KmiZiU0Y3KlJrScEw==} hasBin: true @@ -8623,6 +8783,12 @@ packages: mime-types: 2.1.35 dev: false + /typescript@4.8.4: + resolution: {integrity: sha512-QCh+85mCy+h0IGff8r5XWzOVSbBO+KfeYrMQh7NJ58QujwcE22u+NUSmUxqF+un70P9GXKxa2HCNiTTMJknyjQ==} + engines: {node: '>=4.2.0'} + hasBin: true + dev: true + /typescript@5.0.3: resolution: {integrity: sha512-xv8mOEDnigb/tN9PSMTwSEqAnUvkoXMQlicOb0IUVDBSQCgBSaAAROUZYy2IcUy5qU6XajK5jjjO7TMWqBTKZA==} engines: {node: '>=12.20'} @@ -8834,6 +9000,11 @@ packages: spdx-expression-parse: 3.0.1 dev: true + /validator@13.9.0: + resolution: {integrity: sha512-B+dGG8U3fdtM0/aNK4/X8CXq/EcxU2WPrPEkJGslb47qyHsxmbggTWK0yEA4qnYVNF+nxNlN88o14hIcPmSIEA==} + engines: {node: '>= 0.10'} + dev: true + /vary@1.1.2: resolution: {integrity: sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==} engines: {node: '>= 0.8'} @@ -8857,6 +9028,29 @@ packages: - supports-color dev: true + /vite-plugin-dts@2.2.0(@types/node@18.15.11)(rollup@2.79.1)(vite@4.3.0-beta.1): + resolution: {integrity: sha512-XmZtv02I7eGWm3DrZbLo1AdJK5gCisk9GqJBpY4N63pDYR6AVUnlyjFP5FCBvSBUfgE0Ppl90bKgtJU9k3AzFw==} + engines: {node: ^14.18.0 || >=16.0.0} + peerDependencies: + vite: '>=2.9.0' + dependencies: + '@babel/parser': 7.21.4 + '@microsoft/api-extractor': 7.34.4(@types/node@18.15.11) + '@rollup/pluginutils': 5.0.2(rollup@2.79.1) + '@rushstack/node-core-library': 3.55.2(@types/node@18.15.11) + debug: 4.3.4 + fast-glob: 3.2.12 + fs-extra: 10.1.0 + kolorist: 1.7.0 + magic-string: 0.29.0 + ts-morph: 17.0.1 + vite: 4.3.0-beta.1(@types/node@18.15.11)(less@4.1.3)(sass@1.60.0) + transitivePeerDependencies: + - '@types/node' + - rollup + - supports-color + dev: true + /vite-plugin-html@3.2.0(vite@4.3.0-beta.1): resolution: {integrity: sha512-2VLCeDiHmV/BqqNn5h2V+4280KRgQzCFN47cst3WiNK848klESPQnzuC3okH5XHtgwHH/6s1Ho/YV6yIO0pgoQ==} peerDependencies: @@ -9389,6 +9583,18 @@ packages: engines: {node: '>=10'} dev: true + /z-schema@5.0.5: + resolution: {integrity: sha512-D7eujBWkLa3p2sIpJA0d1pr7es+a7m0vFAnZLlCEKq/Ij2k0MLi9Br2UPxoxdYystm5K1yeBGzub0FlYUEWj2Q==} + engines: {node: '>=8.0.0'} + hasBin: true + dependencies: + lodash.get: 4.4.2 + lodash.isequal: 4.5.0 + validator: 13.9.0 + optionalDependencies: + commander: 9.5.0 + dev: true + /zip-stream@4.1.0: resolution: {integrity: sha512-zshzwQW7gG7hjpBlgeQP9RuyPGNxvJdzR8SUM3QhxCnLjWN2E7j3dOvpeDcQoETfHx0urRS7EtmVToql7YpU4A==} engines: {node: '>= 10'} diff --git a/src/components/Markdown/src/Markdown.vue b/src/components/Markdown/src/Markdown.vue index c80c779b..0843abef 100644 --- a/src/components/Markdown/src/Markdown.vue +++ b/src/components/Markdown/src/Markdown.vue @@ -18,7 +18,7 @@ import { useLocale } from '/@/locales/useLocale'; import { useModalContext } from '../../Modal'; import { useRootSetting } from '/@/hooks/setting/useRootSetting'; - import { onMountedOrActivated } from '/@/hooks/core/onMountedOrActivated'; + import { onMountedOrActivated } from '@vben/hooks'; import { getTheme } from './getTheme'; type Lang = 'zh_CN' | 'en_US' | 'ja_JP' | 'ko_KR' | undefined; @@ -31,8 +31,8 @@ }, emits: ['change', 'get', 'update:value'], setup(props, { attrs, emit }) { - const wrapRef = ref(null); - const vditorRef = ref(null) as Ref>; + const wrapRef = ref(null); + const vditorRef = ref(null) as Ref; const initedRef = ref(false); const modalFn = useModalContext(); @@ -85,7 +85,7 @@ return lang; }); function init() { - const wrapEl = unref(wrapRef) as HTMLElement; + const wrapEl = unref(wrapRef); if (!wrapEl) return; const bindValue = { ...attrs, ...props }; const insEditor = new Vditor(wrapEl, { @@ -140,7 +140,9 @@ if (!vditorInstance) return; try { vditorInstance?.destroy?.(); - } catch (error) {} + } catch (error) { + // + } vditorRef.value = null; initedRef.value = false; } diff --git a/src/components/Markdown/src/MarkdownViewer.vue b/src/components/Markdown/src/MarkdownViewer.vue index 538cedaf..ea5d7fa4 100644 --- a/src/components/Markdown/src/MarkdownViewer.vue +++ b/src/components/Markdown/src/MarkdownViewer.vue @@ -5,19 +5,19 @@