diff --git a/.eslintrc.js b/.eslintrc.js index d0205f56a7..a0d0701bbe 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -43,7 +43,12 @@ module.exports = { tabWidth: 2, trailingComma: 'all', printWidth: 80, + arrowParens: 'always', proseWrap: 'never', + htmlWhitespaceSensitivity: 'css', + embeddedLanguageFormatting: 'auto', + singleAttributePerLine: false, + bracketSpacing: true, overrides: [ { files: '.eslintrc', options: { parser: 'json' } }, { files: '.prettierrc', options: { parser: 'json' } }, @@ -57,7 +62,7 @@ module.exports = { ], 'import/no-duplicates': [2, { considerQueryString: true }], 'import/no-deprecated': 1, - 'import/no-cycle': 1, + 'import/no-cycle': 2, 'import/order': [ 2, { diff --git a/.github/workflows/auto-release.yml b/.github/workflows/auto-release.yml index 000f900171..93cca60d9f 100644 --- a/.github/workflows/auto-release.yml +++ b/.github/workflows/auto-release.yml @@ -54,6 +54,9 @@ jobs: - name: Install dependencies run: pnpm bootstrap:ci + - name: Build doctor + run: pnpm build:doctor + - name: Build run: pnpm build diff --git a/.github/workflows/compressed-size.yml b/.github/workflows/compressed-size.yml index fe79eec36a..ff05016645 100644 --- a/.github/workflows/compressed-size.yml +++ b/.github/workflows/compressed-size.yml @@ -30,6 +30,6 @@ jobs: - uses: preactjs/compressed-size-action@v2 with: repo-token: "${{ secrets.GITHUB_TOKEN }}" - pattern: "./packages/{s2-core,s2-react,s2-vue}/dist/**/*.{js,css}" - build-script: "build:umd" + pattern: "./packages/{s2-core,s2-react,s2-react-components,s2-vue}/dist/**/*.{js,css}" + build-script: "build" clean-script: "clean" diff --git a/.gitignore b/.gitignore index 9936a09d18..2c7368fef0 100644 --- a/.gitignore +++ b/.gitignore @@ -24,5 +24,6 @@ packages/s2-*/dist/ packages/s2-*/temp/ packages/s2-*/coverage/ packages/s2-*/stats.html +packages/**/*.css .swc diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d65dbc444b..891e15c6c4 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -7,7 +7,11 @@ "我代码水平不行", "会不会受到鄙视?", "会不会不太好?", 放心,不存在的! -我们欢迎任何形式的贡献,不管是一个**错别字的修改**,还是**一次友好的建议**,不管是通过提交 [Issue](https://github.com/antvis/S2/issues/new/choose), 还是一个帅气 [pull request](https://github.com/antvis/S2/pulls), 亦或是一次钉钉群的讨论,参与 [discussions](https://github.com/antvis/S2/discussions) 的讨论,期待在 [贡献者列表](https://github.com/antvis/S2/graphs/contributors) 里看见你的头像。 +我们欢迎任何形式的贡献,不管是一个**错别字的修改**,还是**一次友好的建议**,不管是通过提交 [Issue](https://github.com/antvis/S2/issues/new/choose), 还是一个帅气 [pull request](https://github.com/antvis/S2/pulls), 亦或是参与 [discussions](https://github.com/antvis/S2/discussions) 的讨论。 + +这是一个开源项目,我们也有繁忙的业务要做,是用自己的业余时间在维护,为爱发电,精力有限,所以有时候 issue 响应速度不是那么及时。 + +如果你遇到了问题,或者对 Issues 和 Discussions 列表的问题感兴趣,可以直接认领并尝试修复,帮助 S2 变得更好,期待在 [贡献者列表](https://github.com/antvis/S2/graphs/contributors) 里看见你的头像。 ## 分支管理 diff --git a/README.en-US.md b/README.en-US.md index 95392e2148..9623c6c970 100644 --- a/README.en-US.md +++ b/README.en-US.md @@ -30,7 +30,7 @@ A practical visualization library for tabular analysis.

- npm bundle size + npm bundle size GitHub discussions @@ -77,9 +77,9 @@ demo components and expansion capabilities, it allows developers to use it quick ## 📦 Installation ```bash -$ npm install @antv/s2@next --save -# yarn add @antv/s2@next -# pnpm add @antv/s2@next +$ npm install @antv/s2 --save +# yarn add @antv/s2 +# pnpm add @antv/s2 ``` ## 🔨 Getting Started @@ -208,11 +208,13 @@ bootstrap() ### 📦 Packages -| Package | Latest | Beta | Alpha | Next | Size | Download | -| - | - | - | - | - | - | - | -| [@antv/s2](https://github.com/antvis/S2/tree/next/packages/s2-core) | ![latest](https://img.shields.io/npm/v/@antv/s2/latest.svg) | ![beta](https://img.shields.io/npm/v/@antv/s2/beta.svg) | ![alpha](https://img.shields.io/npm/v/@antv/s2/alpha.svg) | ![next](https://img.shields.io/npm/v/@antv/s2/next.svg) | ![size](https://img.badgesize.io/https:/unpkg.com/@antv/s2@latest/dist/index.min.js?label=gzip%20size&compression=gzip) | ![download](https://img.shields.io/npm/dm/@antv/s2.svg) | -| [@antv/s2-react](https://github.com/antvis/S2/tree/next/packages/s2-react) | ![latest](https://img.shields.io/npm/v/@antv/s2-react/latest.svg) | ![beta](https://img.shields.io/npm/v/@antv/s2-react/beta.svg) | ![alpha](https://img.shields.io/npm/v/@antv/s2-react/alpha.svg) | ![next](https://img.shields.io/npm/v/@antv/s2-react/next.svg)| ![size](https://img.badgesize.io/https:/unpkg.com/@antv/s2-react@latest/dist/index.min.js?label=gzip%20size&compression=gzip) | ![download](https://img.shields.io/npm/dm/@antv/s2-react.svg) | -| [@antv/s2-vue](https://github.com/antvis/S2/tree/next/packages/s2-vue) | ![latest](https://img.shields.io/npm/v/@antv/s2-vue/latest.svg) | ![beta](https://img.shields.io/npm/v/@antv/s2-vue/beta.svg) | ![alpha](https://img.shields.io/npm/v/@antv/s2-vue/alpha.svg) | ![next](https://img.shields.io/npm/v/@antv/s2-vue/next.svg) | ![size](https://img.badgesize.io/https:/unpkg.com/@antv/s2-vue@latest/dist/index.min.js?label=gzip%20size&compression=gzip) | ![download](https://img.shields.io/npm/dm/@antv/s2-vue.svg) | +| Package | Latest | Next | Size | Download | +| - | - | - | - | - | +| -------- | ------ | --------- | ---------- | ------ | +| [@antv/s2](https://github.com/antvis/S2/tree/next/packages/s2-core) | ![latest](https://img.shields.io/npm/v/@antv/s2/latest.svg?logo=npm) | ![next](https://img.shields.io/npm/v/@antv/s2/next.svg?logo=npm) | ![size](https://img.badgesize.io/https:/unpkg.com/@antv/s2@latest/dist/index.min.js?label=gzip%20size&compression=gzip) | ![download](https://img.shields.io/npm/dm/@antv/s2.svg?logo=npm) | +| [@antv/s2-react](https://github.com/antvis/S2/tree/next/packages/s2-react) | ![latest](https://img.shields.io/npm/v/@antv/s2-react/latest.svg?logo=npm) | ![next](https://img.shields.io/npm/v/@antv/s2-react/next.svg?logo=npm)| ![size](https://img.badgesize.io/https:/unpkg.com/@antv/s2-react@latest/dist/index.min.js?label=gzip%20size&compression=gzip) | ![download](https://img.shields.io/npm/dm/@antv/s2-react.svg?logo=npm) | +| [@antv/s2-react-components](https://github.com/antvis/S2/tree/next/packages/s2-react-components) | ![latest](https://img.shields.io/npm/v/@antv/s2-react-components/latest.svg?logo=npm) | ![next](https://img.shields.io/npm/v/@antv/s2-react-components/next.svg?logo=npm)| ![size](https://img.badgesize.io/https:/unpkg.com/@antv/s2-react-components@latest/dist/index.min.js?label=gzip%20size&compression=gzip) | ![download](https://img.shields.io/npm/dm/@antv/s2-react-components.svg?logo=npm) | +| [@antv/s2-vue](https://github.com/antvis/S2/tree/next/packages/s2-vue) | ![latest](https://img.shields.io/npm/v/@antv/s2-vue/latest.svg?logo=npm) | ![next](https://img.shields.io/npm/v/@antv/s2-vue/next.svg?logo=npm) | ![size](https://img.badgesize.io/https:/unpkg.com/@antv/s2-vue@latest/dist/index.min.js?label=gzip%20size&compression=gzip) | ![download](https://img.shields.io/npm/dm/@antv/s2-vue.svg?logo=npm) | ### 🖥️ Browser Compatibility diff --git a/README.md b/README.md index ebb7941e60..677a3404f0 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@

- npm bundle size + npm bundle size GitHub discussions @@ -73,9 +73,9 @@ S2 是 AntV 在多维交叉分析表格领域的解决方案,完全基于数 ## 📦 安装 ```bash -$ npm install @antv/s2@next --save -# yarn add @antv/s2@next -# pnpm add @antv/s2@next +$ npm install @antv/s2 --save +# yarn add @antv/s2 +# pnpm add @antv/s2 ``` ## 🔨 使用 @@ -204,11 +204,13 @@ bootstrap() ### 📦 版本 -| Package | Latest | Beta | Alpha | Next | Size | Download | -| - | - | - | - | - | - | - | -| [@antv/s2](https://github.com/antvis/S2/tree/next/packages/s2-core) | ![latest](https://img.shields.io/npm/v/@antv/s2/latest.svg) | ![beta](https://img.shields.io/npm/v/@antv/s2/beta.svg) | ![alpha](https://img.shields.io/npm/v/@antv/s2/alpha.svg) | ![next](https://img.shields.io/npm/v/@antv/s2/next.svg) | ![size](https://img.badgesize.io/https:/unpkg.com/@antv/s2@latest/dist/index.min.js?label=gzip%20size&compression=gzip) | ![download](https://img.shields.io/npm/dm/@antv/s2.svg) | -| [@antv/s2-react](https://github.com/antvis/S2/tree/next/packages/s2-react) | ![latest](https://img.shields.io/npm/v/@antv/s2-react/latest.svg) | ![beta](https://img.shields.io/npm/v/@antv/s2-react/beta.svg) | ![alpha](https://img.shields.io/npm/v/@antv/s2-react/alpha.svg) | ![next](https://img.shields.io/npm/v/@antv/s2-react/next.svg)| ![size](https://img.badgesize.io/https:/unpkg.com/@antv/s2-react@latest/dist/index.min.js?label=gzip%20size&compression=gzip) | ![download](https://img.shields.io/npm/dm/@antv/s2-react.svg) | -| [@antv/s2-vue](https://github.com/antvis/S2/tree/next/packages/s2-vue) | ![latest](https://img.shields.io/npm/v/@antv/s2-vue/latest.svg) | ![beta](https://img.shields.io/npm/v/@antv/s2-vue/beta.svg) | ![alpha](https://img.shields.io/npm/v/@antv/s2-vue/alpha.svg) | ![next](https://img.shields.io/npm/v/@antv/s2-vue/next.svg) | ![size](https://img.badgesize.io/https:/unpkg.com/@antv/s2-vue@latest/dist/index.min.js?label=gzip%20size&compression=gzip) | ![download](https://img.shields.io/npm/dm/@antv/s2-vue.svg) | +| Package | Latest | Next | Size | Download | +| - | - | - | - | - | +| -------- | ------ | --------- | ---------- | ------ | +| [@antv/s2](https://github.com/antvis/S2/tree/next/packages/s2-core) | ![latest](https://img.shields.io/npm/v/@antv/s2/latest.svg?logo=npm) | ![next](https://img.shields.io/npm/v/@antv/s2/next.svg?logo=npm) | ![size](https://img.badgesize.io/https:/unpkg.com/@antv/s2@latest/dist/index.min.js?label=gzip%20size&compression=gzip) | ![download](https://img.shields.io/npm/dm/@antv/s2.svg?logo=npm) | +| [@antv/s2-react](https://github.com/antvis/S2/tree/next/packages/s2-react) | ![latest](https://img.shields.io/npm/v/@antv/s2-react/latest.svg?logo=npm) | ![next](https://img.shields.io/npm/v/@antv/s2-react/next.svg?logo=npm)| ![size](https://img.badgesize.io/https:/unpkg.com/@antv/s2-react@latest/dist/index.min.js?label=gzip%20size&compression=gzip) | ![download](https://img.shields.io/npm/dm/@antv/s2-react.svg?logo=npm) | +| [@antv/s2-react-components](https://github.com/antvis/S2/tree/next/packages/s2-react-components) | ![latest](https://img.shields.io/npm/v/@antv/s2-react-components/latest.svg?logo=npm) | ![next](https://img.shields.io/npm/v/@antv/s2-react-components/next.svg?logo=npm)| ![size](https://img.badgesize.io/https:/unpkg.com/@antv/s2-react-components@latest/dist/index.min.js?label=gzip%20size&compression=gzip) | ![download](https://img.shields.io/npm/dm/@antv/s2-react-components.svg?logo=npm) | +| [@antv/s2-vue](https://github.com/antvis/S2/tree/next/packages/s2-vue) | ![latest](https://img.shields.io/npm/v/@antv/s2-vue/latest.svg?logo=npm) | ![next](https://img.shields.io/npm/v/@antv/s2-vue/next.svg?logo=npm) | ![size](https://img.badgesize.io/https:/unpkg.com/@antv/s2-vue@latest/dist/index.min.js?label=gzip%20size&compression=gzip) | ![download](https://img.shields.io/npm/dm/@antv/s2-vue.svg?logo=npm) | ### 🖥️ 兼容环境 diff --git a/build.config.base.mjs b/build.config.base.mjs new file mode 100644 index 0000000000..a2a703a47b --- /dev/null +++ b/build.config.base.mjs @@ -0,0 +1,145 @@ +/* eslint-disable max-lines-per-function */ +/* eslint-disable import/order */ +import { viteCommonjs } from '@originjs/vite-plugin-commonjs'; +import { toLower } from 'lodash'; +import path from 'path'; +import peerDepsExternal from 'rollup-plugin-peer-deps-external'; +import { visualizer } from 'rollup-plugin-visualizer'; + +export const getBaseConfig = () => { + const entry = './src/index.ts'; + + const OUT_DIR_NAME_MAP = { + es: 'esm', + cjs: 'lib', + umd: 'dist', + }; + + const format = process.env.FORMAT; + const isAnalysisMode = process.env.ANALYSIS; + const isDevMode = process.env.PLAYGROUND; + const outDir = OUT_DIR_NAME_MAP[format]; + const isUMD = format === 'umd'; + const isESM = format === 'es'; + + const define = { + 'process.env.NODE_ENV': JSON.stringify( + isDevMode ? 'development' : 'production', + ), + }; + + const resolve = { + mainFields: ['src', 'module', 'main'], + alias: [], + }; + + if (isDevMode) { + // 防止开发模式下直接加载 s2-core 中的主题 less + resolve.alias.push( + ...[ + { + find: /^(.*)\/theme\/(.*)\.less$/, + replacement: '$1/theme/$2.less?inline', + }, + { + find: /^@antv\/s2$/, + replacement: path.join(__dirname, './packages/s2-core/src'), + }, + ], + ); + } + + const getViteConfig = ( + { port, name, libName, plugins } = { + port: 3001, + plugins: [], + }, + ) => { + const filename = isUMD ? `${toLower(name || libName)}.min` : '[name]'; + + return { + server: { + port, + hmr: true, + }, + + resolve, + + define: { + 'process.env.NODE_ENV': JSON.stringify( + isDevMode ? 'development' : 'production', + ), + }, + + plugins: [ + peerDepsExternal(), + !isDevMode && viteCommonjs(), + isAnalysisMode && + visualizer({ + open: true, + gzipSize: true, + brotliSize: true, + }), + ...plugins, + ].filter(Boolean), + + css: { + preprocessorOptions: { + less: { + javascriptEnabled: true, + }, + }, + modules: { + /** + * 样式小驼峰转化 + * css: goods-list => tsx: goodsList + */ + localsConvention: 'camelCase', + }, + }, + + build: { + target: 'es2015', + minify: isUMD ? 'esbuild' : false, + sourcemap: true, + lib: { + name: libName, + entry, + formats: [format], + }, + outDir, + rollupOptions: { + output: { + dir: outDir, + entryFileNames: `${filename}.js`, + assetFileNames: `${filename}.[ext]`, + globals: { + vue: 'Vue', + react: 'React', + 'react-dom': 'ReactDOM', + '@antv/s2': 'S2', + '@antv/s2-react': 'S2React', + lodash: '_', + antd: 'antd', + 'ant-design-vue': 'antd', + }, + }, + }, + }, + }; + }; + + return { + entry, + getViteConfig, + define, + format, + resolve, + isAnalysisMode, + outDir, + OUT_DIR_NAME_MAP, + isDevMode, + isUMD, + isESM, + }; +}; diff --git a/jest.config.base.js b/jest.config.base.js index 7a9905c693..38232a0aa7 100644 --- a/jest.config.base.js +++ b/jest.config.base.js @@ -43,16 +43,16 @@ module.exports = { '\\.svg$': 'jest-raw-loader', }, moduleNameMapper: { + '\\.svg$': '/__tests__/__mocks__/svg.ts', '^@/(.*)': '/src/$1', '^tests/(.*)': '/__tests__/$1', '^@antv/s2$': path.join(__dirname, 'packages/s2-core/src'), - '^@antv/s2-shared$': path.join(__dirname, 'packages/s2-shared/src'), + '^@antv/s2/esm/(.*)$': path.join(__dirname, 'packages/s2-core/src/$1'), '^@antv/s2-react$': path.join(__dirname, 'packages/s2-react/src'), '^@antv/s2-react-components$': path.join( __dirname, 'packages/s2-react-components/src', ), - '\\.svg$': '/__tests__/__mocks__/svg.ts', /* ignore module query: foo.less?a=1 -> foo.less */ '(.+)\\.(.+)\\?(.*)$': '$1.$2', }, diff --git a/package.json b/package.json index f03c70a303..32bbc30fea 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,7 @@ "url": "https://github.com/antvis/S2.git" }, "license": "MIT", + "files": [], "scripts": { "preinstall": "npx only-allow pnpm", "bootstrap": "pnpm install", @@ -32,6 +33,7 @@ "core:start": "pnpm --filter @antv/s2 start", "core:watch": " pnpm --filter @antv/s2 watch", "core:build": "pnpm --filter @antv/s2 build", + "core:build-esm": "pnpm --filter @antv/s2 build:esm", "core:test": "pnpm --filter @antv/s2 test", "core:test-coverage": "pnpm --filter @antv/s2 test:coverage", "core:sync-event": "pnpm --filter @antv/s2 sync-event", @@ -55,7 +57,7 @@ "build:umd": "pnpm -r --filter './packages/*' --stream build:umd", "build:size-limit": "pnpm -r --filter './packages/*' --stream build:size-limit", "build:size-limit-json": "pnpm -r --filter './packages/*' --stream build:size-limit-json", - "release": "pnpm -r --filter !@antv/s2-shared --filter !@antv/s2-site --workspace-concurrency=1 exec npx --no-install semantic-release", + "release": "pnpm -r --filter !@antv/s2-site --workspace-concurrency=1 exec npx --no-install semantic-release", "release:preview": "pnpm release --dry-run --no-ci", "release:bump-version": "node ./scripts/bump-version.js", "test": "pnpm -r --filter './packages/*' --stream test", @@ -77,7 +79,6 @@ "site:build": "NODE_OPTIONS='--max-old-space-size=4096' pnpm --filter @antv/s2-site build", "site:preview": "pnpm --filter @antv/s2-site preview", "site:deploy": "pnpm --filter @antv/s2-site deploy", - "share:test": "pnpm --filter @antv/s2-shared test", "format": "prettier . --write" }, "commitlint": { @@ -162,7 +163,7 @@ "jest-url-loader": "^0.1.0", "less": "^4.2.0", "lint-staged": "^15.2.5", - "lodash-es": "^4.17.21", + "lodash": "^4.17.21", "markdownlint-cli": "^0.41.0", "npm-run-all": "^4.1.5", "ora": "^8.0.1", diff --git a/packages/s2-core/README.en-US.md b/packages/s2-core/README.en-US.md index dfdd422fa8..bd7894d5a1 100644 --- a/packages/s2-core/README.en-US.md +++ b/packages/s2-core/README.en-US.md @@ -211,8 +211,8 @@ bootstrap() | Package | Latest | Beta | Alpha | Next | Size | Download | | - | - | - | - | - | - | - | | [@antv/s2](https://github.com/antvis/S2/tree/next/packages/s2-core) | ![latest](https://img.shields.io/npm/v/@antv/s2/latest.svg) | ![beta](https://img.shields.io/npm/v/@antv/s2/beta.svg) | ![alpha](https://img.shields.io/npm/v/@antv/s2/alpha.svg) | ![next](https://img.shields.io/npm/v/@antv/s2/next.svg) | ![size](https://img.badgesize.io/https:/unpkg.com/@antv/s2@latest/dist/index.min.js?label=gzip%20size&compression=gzip) | ![download](https://img.shields.io/npm/dm/@antv/s2.svg) | -| [@antv/s2-react](https://github.com/antvis/S2/tree/next/packages/s2-react) | ![latest](https://img.shields.io/npm/v/@antv/s2-react/latest.svg) | ![beta](https://img.shields.io/npm/v/@antv/s2-react/beta.svg) | ![alpha](https://img.shields.io/npm/v/@antv/s2-react/alpha.svg) | ![next](https://img.shields.io/npm/v/@antv/s2-react/next.svg)| ![size](https://img.badgesize.io/https:/unpkg.com/@antv/s2-react@latest/dist/index.min.js?label=gzip%20size&compression=gzip) | ![download](https://img.shields.io/npm/dm/@antv/s2-react.svg) | -| [@antv/s2-vue](https://github.com/antvis/S2/tree/next/packages/s2-vue) | ![latest](https://img.shields.io/npm/v/@antv/s2-vue/latest.svg) | ![beta](https://img.shields.io/npm/v/@antv/s2-vue/beta.svg) | ![alpha](https://img.shields.io/npm/v/@antv/s2-vue/alpha.svg) | ![next](https://img.shields.io/npm/v/@antv/s2-vue/next.svg) | ![size](https://img.badgesize.io/https:/unpkg.com/@antv/s2-vue@latest/dist/index.min.js?label=gzip%20size&compression=gzip) | ![download](https://img.shields.io/npm/dm/@antv/s2-vue.svg) | +| [@antv/s2-react](https://github.com/antvis/S2/tree/next/packages/s2-react) | ![latest](https://img.shields.io/npm/v/@antv/s2-react/latest.svg) | ![beta](https://img.shields.io/npm/v/@antv/s2-react/beta.svg) | ![alpha](https://img.shields.io/npm/v/@antv/s2-react/alpha.svg) | ![next](https://img.shields.io/npm/v/@antv/s2-react/next.svg)| ![size](https://img.badgesize.io/https:/unpkg.com/@antv/s2-react/dist/s2-react.min.js?label=gzip%20size&compression=gzip) | ![download](https://img.shields.io/npm/dm/@antv/s2-react.svg) | +| [@antv/s2-vue](https://github.com/antvis/S2/tree/next/packages/s2-vue) | ![latest](https://img.shields.io/npm/v/@antv/s2-vue/latest.svg) | ![beta](https://img.shields.io/npm/v/@antv/s2-vue/beta.svg) | ![alpha](https://img.shields.io/npm/v/@antv/s2-vue/alpha.svg) | ![next](https://img.shields.io/npm/v/@antv/s2-vue/next.svg) | ![size](https://img.badgesize.io/https:/unpkg.com/@antv/s2-vue/dist/s2-vue.min.js?label=gzip%20size&compression=gzip) | ![download](https://img.shields.io/npm/dm/@antv/s2-vue.svg) | ## 👤 Author diff --git a/packages/s2-core/README.md b/packages/s2-core/README.md index c6dca6a56e..3c03e975aa 100644 --- a/packages/s2-core/README.md +++ b/packages/s2-core/README.md @@ -29,7 +29,7 @@

- npm bundle size + npm bundle size GitHub discussions @@ -207,8 +207,8 @@ bootstrap() | Package | Latest | Beta | Alpha | Next | Size | Download | | - | - | - | - | - | - | - | | [@antv/s2](https://github.com/antvis/S2/tree/next/packages/s2-core) | ![latest](https://img.shields.io/npm/v/@antv/s2/latest.svg) | ![beta](https://img.shields.io/npm/v/@antv/s2/beta.svg) | ![alpha](https://img.shields.io/npm/v/@antv/s2/alpha.svg) | ![next](https://img.shields.io/npm/v/@antv/s2/next.svg) | ![size](https://img.badgesize.io/https:/unpkg.com/@antv/s2@latest/dist/index.min.js?label=gzip%20size&compression=gzip) | ![download](https://img.shields.io/npm/dm/@antv/s2.svg) | -| [@antv/s2-react](https://github.com/antvis/S2/tree/next/packages/s2-react) | ![latest](https://img.shields.io/npm/v/@antv/s2-react/latest.svg) | ![beta](https://img.shields.io/npm/v/@antv/s2-react/beta.svg) | ![alpha](https://img.shields.io/npm/v/@antv/s2-react/alpha.svg) | ![next](https://img.shields.io/npm/v/@antv/s2-react/next.svg)| ![size](https://img.badgesize.io/https:/unpkg.com/@antv/s2-react@latest/dist/index.min.js?label=gzip%20size&compression=gzip) | ![download](https://img.shields.io/npm/dm/@antv/s2-react.svg) | -| [@antv/s2-vue](https://github.com/antvis/S2/tree/next/packages/s2-vue) | ![latest](https://img.shields.io/npm/v/@antv/s2-vue/latest.svg) | ![beta](https://img.shields.io/npm/v/@antv/s2-vue/beta.svg) | ![alpha](https://img.shields.io/npm/v/@antv/s2-vue/alpha.svg) | ![next](https://img.shields.io/npm/v/@antv/s2-vue/next.svg) | ![size](https://img.badgesize.io/https:/unpkg.com/@antv/s2-vue@latest/dist/index.min.js?label=gzip%20size&compression=gzip) | ![download](https://img.shields.io/npm/dm/@antv/s2-vue.svg) | +| [@antv/s2-react](https://github.com/antvis/S2/tree/next/packages/s2-react) | ![latest](https://img.shields.io/npm/v/@antv/s2-react/latest.svg) | ![beta](https://img.shields.io/npm/v/@antv/s2-react/beta.svg) | ![alpha](https://img.shields.io/npm/v/@antv/s2-react/alpha.svg) | ![next](https://img.shields.io/npm/v/@antv/s2-react/next.svg)| ![size](https://img.badgesize.io/https:/unpkg.com/@antv/s2-react@latest/dist/s2-react.min.js?label=gzip%20size&compression=gzip) | ![download](https://img.shields.io/npm/dm/@antv/s2-react.svg) | +| [@antv/s2-vue](https://github.com/antvis/S2/tree/next/packages/s2-vue) | ![latest](https://img.shields.io/npm/v/@antv/s2-vue/latest.svg) | ![beta](https://img.shields.io/npm/v/@antv/s2-vue/beta.svg) | ![alpha](https://img.shields.io/npm/v/@antv/s2-vue/alpha.svg) | ![next](https://img.shields.io/npm/v/@antv/s2-vue/next.svg) | ![size](https://img.badgesize.io/https:/unpkg.com/@antv/s2-vue@latest/dist/s2-vue.min.js?label=gzip%20size&compression=gzip) | ![download](https://img.shields.io/npm/dm/@antv/s2-vue.svg) | ## 问题反馈 diff --git a/packages/s2-core/__tests__/setup.js b/packages/s2-core/__tests__/setup.js index 95ba1ba1bb..1f37195929 100644 --- a/packages/s2-core/__tests__/setup.js +++ b/packages/s2-core/__tests__/setup.js @@ -14,3 +14,5 @@ jest.mock('@/ui/hd-adapter', () => { }), }; }); + +jest.setTimeout(60 * 1000); diff --git a/packages/s2-core/__tests__/unit/interaction/row-column-resize-spec.ts b/packages/s2-core/__tests__/unit/interaction/row-column-resize-spec.ts index a1e069dd0e..d07288ceea 100644 --- a/packages/s2-core/__tests__/unit/interaction/row-column-resize-spec.ts +++ b/packages/s2-core/__tests__/unit/interaction/row-column-resize-spec.ts @@ -134,6 +134,22 @@ describe('Interaction Row Column Resize Tests', () => { return resizeInfo; }; + const createCells = () => { + const children = [ + createMockCellInfo('test-cell-a', { isLeaf: true }).getNode(), + createMockCellInfo('test-cell-b', { isLeaf: true }).getNode(), + ]; + + return [ + createMockCellInfo('test-row-cell-1', { + children, + }).mockCell, + createMockCellInfo('test-row-cell-2', { + children, + }).mockCell, + ]; + }; + beforeEach(() => { MockRootInteraction.mockClear(); @@ -167,14 +183,6 @@ describe('Interaction Row Column Resize Tests', () => { createMockCellInfo('test-col-cell-a').mockCell, createMockCellInfo('test-col-cell-b').mockCell, ]; - - // 模拟多选 - jest - .spyOn(Node, 'getAllLeaveNodes') - .mockImplementationOnce(() => [ - createMockCellInfo('test-cell-a').getNode(), - createMockCellInfo('test-cell-b').getNode(), - ]); }); test('should register events', () => { @@ -825,6 +833,9 @@ describe('Interaction Row Column Resize Tests', () => { }, }); + jest + .spyOn(s2.interaction, 'getActiveColCells') + .mockImplementationOnce(() => createCells()); jest .spyOn(s2.interaction, 'isSelectedState') .mockImplementationOnce(() => true); @@ -845,6 +856,9 @@ describe('Interaction Row Column Resize Tests', () => { }, }); + jest + .spyOn(s2.interaction, 'getActiveRowCells') + .mockImplementationOnce(() => createCells()); jest .spyOn(s2.interaction, 'isSelectedState') .mockImplementationOnce(() => true); @@ -858,10 +872,7 @@ describe('Interaction Row Column Resize Tests', () => { // 模拟多选 jest .spyOn(s2.interaction, 'getActiveRowCells') - .mockImplementationOnce(() => [ - createMockCellInfo('test-row-cell-1').mockCell, - createMockCellInfo('test-row-cell-2').mockCell, - ]); + .mockImplementationOnce(() => createCells()); jest .spyOn(s2.interaction, 'isSelectedState') .mockImplementationOnce(() => true); @@ -884,10 +895,7 @@ describe('Interaction Row Column Resize Tests', () => { // 模拟多选 jest .spyOn(s2.interaction, 'getActiveColCells') - .mockImplementationOnce(() => [ - createMockCellInfo('test-col-cell-1').mockCell, - createMockCellInfo('test-col-cell-2').mockCell, - ]); + .mockImplementationOnce(() => createCells()); jest .spyOn(s2.interaction, 'isSelectedState') .mockImplementationOnce(() => true); diff --git a/packages/s2-shared/__tests__/unit/utils/__snapshots__/drill-down-spec.ts.snap b/packages/s2-core/__tests__/unit/shared/utils/__snapshots__/drill-down-spec.ts.snap similarity index 100% rename from packages/s2-shared/__tests__/unit/utils/__snapshots__/drill-down-spec.ts.snap rename to packages/s2-core/__tests__/unit/shared/utils/__snapshots__/drill-down-spec.ts.snap diff --git a/packages/s2-shared/__tests__/unit/utils/__snapshots__/options-spec.ts.snap b/packages/s2-core/__tests__/unit/shared/utils/__snapshots__/options-spec.ts.snap similarity index 100% rename from packages/s2-shared/__tests__/unit/utils/__snapshots__/options-spec.ts.snap rename to packages/s2-core/__tests__/unit/shared/utils/__snapshots__/options-spec.ts.snap diff --git a/packages/s2-shared/__tests__/unit/utils/classnames-spec.ts b/packages/s2-core/__tests__/unit/shared/utils/classnames-spec.ts similarity index 79% rename from packages/s2-shared/__tests__/unit/utils/classnames-spec.ts rename to packages/s2-core/__tests__/unit/shared/utils/classnames-spec.ts index 8aaf270005..449817e2f7 100644 --- a/packages/s2-shared/__tests__/unit/utils/classnames-spec.ts +++ b/packages/s2-core/__tests__/unit/shared/utils/classnames-spec.ts @@ -1,4 +1,4 @@ -import { getStrategySheetTooltipClsName } from '../../../src/utils/classnames'; +import { getStrategySheetTooltipClsName } from '../../../../src/shared'; describe('classnames test', () => { test('#getStrategySheetTooltipClsName()', () => { diff --git a/packages/s2-shared/__tests__/unit/utils/drill-down-spec.ts b/packages/s2-core/__tests__/unit/shared/utils/drill-down-spec.ts similarity index 93% rename from packages/s2-shared/__tests__/unit/utils/drill-down-spec.ts rename to packages/s2-core/__tests__/unit/shared/utils/drill-down-spec.ts index e9bb7ae3a4..2c9c4fb2a0 100644 --- a/packages/s2-shared/__tests__/unit/utils/drill-down-spec.ts +++ b/packages/s2-core/__tests__/unit/shared/utils/drill-down-spec.ts @@ -1,20 +1,20 @@ import { - GEvent, - PivotDataSet, S2Event, Store, + type GEvent, type Node, + type PivotDataSet, type SpreadSheet, -} from '@antv/s2'; -import type { PartDrillDown } from '../../../src/interface'; +} from '../../../../src'; +import type { PartDrillDown } from '../../../../src/shared'; import { buildDrillDownOptions, defaultPartDrillDownDisplayCondition, getDrillDownCache, handleActionIconClick, handleDrillDown, -} from '../../../src/utils/drill-down'; -import { sleep } from '../../util/helpers'; +} from '../../../../src/shared'; +import { sleep } from '../../../util/helpers'; describe('drill-down test', () => { let s2: SpreadSheet; diff --git a/packages/s2-shared/__tests__/unit/utils/options-spec.ts b/packages/s2-core/__tests__/unit/shared/utils/options-spec.ts similarity index 84% rename from packages/s2-shared/__tests__/unit/utils/options-spec.ts rename to packages/s2-core/__tests__/unit/shared/utils/options-spec.ts index 909e1fe25b..22b1a80674 100644 --- a/packages/s2-shared/__tests__/unit/utils/options-spec.ts +++ b/packages/s2-core/__tests__/unit/shared/utils/options-spec.ts @@ -1,5 +1,5 @@ -import { type S2Options } from '@antv/s2'; -import { getBaseSheetComponentOptions } from '../../../src/utils/options'; +import type { S2Options } from '../../../../src'; +import { getBaseSheetComponentOptions } from '../../../../src/shared'; describe('Options Tests', () => { test('should get safety options', () => { diff --git a/packages/s2-shared/__tests__/unit/utils/resize-spec.ts b/packages/s2-core/__tests__/unit/shared/utils/resize-spec.ts similarity index 90% rename from packages/s2-shared/__tests__/unit/utils/resize-spec.ts rename to packages/s2-core/__tests__/unit/shared/utils/resize-spec.ts index 7097678881..5bb8e561bd 100644 --- a/packages/s2-shared/__tests__/unit/utils/resize-spec.ts +++ b/packages/s2-core/__tests__/unit/shared/utils/resize-spec.ts @@ -1,8 +1,5 @@ -import { PivotSheet } from '@antv/s2'; -import { - analyzeAdaptive, - createResizeObserver, -} from '../../../src/utils/resize'; +import { PivotSheet } from '../../../../src'; +import { analyzeAdaptive, createResizeObserver } from '../../../../src/shared'; describe('resize test', () => { test('#analyzeAdaptive()', () => { diff --git a/packages/s2-core/__tests__/unit/utils/interaction/__snapshots__/formatter-spec.ts.snap b/packages/s2-core/__tests__/unit/utils/interaction/__snapshots__/formatter-spec.ts.snap index a93b98952b..cfabafa96b 100644 --- a/packages/s2-core/__tests__/unit/utils/interaction/__snapshots__/formatter-spec.ts.snap +++ b/packages/s2-core/__tests__/unit/utils/interaction/__snapshots__/formatter-spec.ts.snap @@ -4,6 +4,7 @@ exports[`#getBaseCellData() should get correctly cell data 1`] = ` Object { "target": Object { "cellType": undefined, + "children": Array [], "colId": "0", "colIndex": 0, "cornerType": "", @@ -15,6 +16,7 @@ Object { "getStyle": [MockFunction], "hideInteractionShape": [MockFunction], "id": "test-a", + "isLeaf": false, "isTextOverflowing": [MockFunction], "level": 0, "parentNode": [Circular], @@ -42,11 +44,13 @@ Object { "y": 0, }, "viewMeta": Object { + "children": Array [], "colId": "0", "colIndex": 0, "cornerType": "", "field": "test-a", "id": "test-a", + "isLeaf": false, "level": 0, "rowIndex": 0, "spreadsheet": Object { diff --git a/packages/s2-core/__tests__/util/helpers.ts b/packages/s2-core/__tests__/util/helpers.ts index da05d2ce6f..bca47a2757 100644 --- a/packages/s2-core/__tests__/util/helpers.ts +++ b/packages/s2-core/__tests__/util/helpers.ts @@ -257,6 +257,8 @@ export const createMockCellInfo = ( level = 0, cornerType = '', cellType = undefined, + children = [], + isLeaf = false, }: Partial = {}, ) => { const mockCellViewMeta: Partial = { @@ -270,6 +272,8 @@ export const createMockCellInfo = ( cornerType, x: 0, y: 0, + children, + isLeaf, spreadsheet: { dataCfg: { meta: null, @@ -297,6 +301,8 @@ export const createMockCellInfo = ( 'colId', 'field', 'cornerType', + 'children', + 'isLeaf', ]); const mockCell = { ...mockCellViewMeta, diff --git a/packages/s2-core/package.json b/packages/s2-core/package.json index 4fc9953ca3..06ff5b6462 100644 --- a/packages/s2-core/package.json +++ b/packages/s2-core/package.json @@ -27,7 +27,7 @@ "dist/*" ], "main": "lib/index.js", - "unpkg": "dist/index.min.js", + "unpkg": "dist/s2.min.js", "module": "esm/index.js", "types": "esm/index.d.ts", "directories": { @@ -41,20 +41,18 @@ "README.md" ], "scripts": { - "build": "npm-run-all clean --parallel build:umd build:cjs build:esm build:dts", + "build": "npm-run-all clean --parallel build:cjs build:esm build:umd", "build:analysis": "cross-env FORMAT=esm ANALYSIS=true rollup -c rollup.config.mjs", - "build:cjs": "cross-env FORMAT=cjs rollup -c rollup.config.mjs", - "build:dts": "run-s dts:*", - "build:esm": "cross-env FORMAT=es rollup -c rollup.config.mjs", + "build:cjs": "tsc --module commonjs --outDir lib -p tsconfig.build.json && pnpm build:sync-assets lib/", + "build:esm": "tsc --module ESNext --outDir esm -p tsconfig.build.json && pnpm build:sync-assets esm/", "build:size-limit": "size-limit", "build:size-limit-json": "pnpm build:size-limit -- --json", + "build:sync-assets": "rsync -av --include='*/' --include='*.less' --include='*.svg' --exclude='*' src/", "build:umd": "cross-env FORMAT=umd rollup -c rollup.config.mjs", "clean": "rimraf lib esm dist temp", - "dts:build": "tsc -p tsconfig.declaration.json", - "dts:extract": "cross-env LIB=s2-core node ../../scripts/dts.js", "start": "pnpm test:live", "sync-event": "node ./scripts/sync-event.mjs", - "test": "jest --passWithNoTests --detectOpenHandles", + "test": "jest --passWithNoTests", "test:ci": "pnpm test -- --maxWorkers=3", "test:ci-coverage": "pnpm test:coverage --maxWorkers=3", "test:coverage": "pnpm test -- --coverage", @@ -90,12 +88,12 @@ }, "size-limit": [ { - "path": "./dist/index.min.js", + "path": "./dist/s2.min.js", "import": "{ createComponent }", - "limit": "200 kB" + "limit": "240 kB" }, { - "path": "./dist/style.min.css", + "path": "./dist/s2.min.css", "limit": "5 kB" } ], diff --git a/packages/s2-core/rollup.config.mjs b/packages/s2-core/rollup.config.mjs index c92c130032..1244e2952e 100644 --- a/packages/s2-core/rollup.config.mjs +++ b/packages/s2-core/rollup.config.mjs @@ -33,7 +33,6 @@ const plugins = [ peerDepsExternal(), alias({ entries: [ - { find: 'lodash', replacement: 'lodash-es' }, { find: /^(?.*).less\?inline$/, replacement: '$1.less', @@ -52,6 +51,10 @@ const plugins = [ tsconfigOverride: { outDir, include: ['src', '../../global.d.ts'], + compilerOptions: { + declaration: false, + useDefineForClassFields: false, + }, }, }), postcss({ @@ -62,7 +65,7 @@ const plugins = [ stylus: null, less: { javascriptEnabled: true }, }, - extract: `style${isUmdFormat ? '.min' : ''}.css`, + extract: `s2${isUmdFormat ? '.min' : ''}.css`, }), /** 主题变量 less 不需要 extract&inject */ postcss({ @@ -82,7 +85,7 @@ if (enableAnalysis) { } if (isUmdFormat) { - output.file = 'dist/index.min.js'; + output.file = 'dist/s2.min.js'; plugins.push(terser()); } else { output.dir = outDir; diff --git a/packages/s2-core/scripts/test-live.mjs b/packages/s2-core/scripts/test-live.mjs index a29a794bc4..ac491d2ea5 100644 --- a/packages/s2-core/scripts/test-live.mjs +++ b/packages/s2-core/scripts/test-live.mjs @@ -1,14 +1,14 @@ /* eslint-disable import/no-extraneous-dependencies */ import { execSync } from 'child_process'; -import ora from 'ora'; import { glob } from 'glob'; import { default as inquirer } from 'inquirer'; import { default as autoCompletePrompt } from 'inquirer-autocomplete-prompt'; +import ora from 'ora'; inquirer.registerPrompt('autocomplete', autoCompletePrompt); function run(path) { - const command = `cross-env DEBUG_MODE=1 npx jest ${path} --passWithNoTests --detectOpenHandles`; + const command = `cross-env DEBUG_MODE=1 npx jest ${path} --passWithNoTests`; const jestSpinner = ora(`[测试运行中]: ${command}`).start(); try { diff --git a/packages/s2-core/src/cell/merged-cell.ts b/packages/s2-core/src/cell/merged-cell.ts index 4c7ca45b8c..c344240eee 100644 --- a/packages/s2-core/src/cell/merged-cell.ts +++ b/packages/s2-core/src/cell/merged-cell.ts @@ -2,12 +2,12 @@ import { isEmpty } from 'lodash'; import { CellType } from '../common/constant'; import { CellBorderPosition, type ViewMeta } from '../common/interface'; import type { SpreadSheet } from '../sheet-type'; -import { getBorderPositionAndStyle } from '../utils'; -import { renderLine, renderPolygon } from '../utils/g-renders'; +import { getBorderPositionAndStyle } from '../utils/cell/cell'; import { getPolygonPoints, getRightAndBottomCells, -} from '../utils/interaction/merge-cell'; +} from '../utils/cell/merged-cell'; +import { renderLine, renderPolygon } from '../utils/g-renders'; import { drawCustomContent } from '../utils/text'; import { DataCell } from './data-cell'; diff --git a/packages/s2-core/src/facet/index.ts b/packages/s2-core/src/facet/index.ts index 080b7e7092..432f387965 100644 --- a/packages/s2-core/src/facet/index.ts +++ b/packages/s2-core/src/facet/index.ts @@ -1,7 +1,7 @@ -import { BaseFacet } from './base-facet'; -import { FrozenFacet } from './frozen-facet'; -import { PivotFacet } from './pivot-facet'; -import { TableFacet } from './table-facet'; +export { BaseFacet } from './base-facet'; +export { FrozenFacet } from './frozen-facet'; +export { PivotFacet } from './pivot-facet'; +export { TableFacet } from './table-facet'; export * from './header'; -export { BaseFacet, FrozenFacet, PivotFacet, TableFacet }; +export * from './layout'; diff --git a/packages/s2-core/src/facet/layout/build-gird-hierarchy.ts b/packages/s2-core/src/facet/layout/build-gird-hierarchy.ts index 53f32bf23c..eeae45bc32 100644 --- a/packages/s2-core/src/facet/layout/build-gird-hierarchy.ts +++ b/packages/s2-core/src/facet/layout/build-gird-hierarchy.ts @@ -76,6 +76,8 @@ const buildTotalGridHierarchy = (params: GridHeaderParams) => { level: index, parentNode, query, + // eslint-disable-next-line @typescript-eslint/no-use-before-define + handler: buildGridHierarchy, }); }; @@ -130,18 +132,18 @@ const buildNormalGridHierarchy = (params: GridHeaderParams) => { level: index, parentNode, query, + // eslint-disable-next-line @typescript-eslint/no-use-before-define + handler: buildGridHierarchy, }); }; /** * Build grid hierarchy in rows or columns - * - * @param params */ -export const buildGridHierarchy = (params: GridHeaderParams) => { +export function buildGridHierarchy(params: GridHeaderParams) { if (params.parentNode.isTotals) { buildTotalGridHierarchy(params); } else { buildNormalGridHierarchy(params); } -}; +} diff --git a/packages/s2-core/src/facet/layout/build-header-hierarchy.ts b/packages/s2-core/src/facet/layout/build-header-hierarchy.ts index 1048f3e3ae..5a6732d0e3 100644 --- a/packages/s2-core/src/facet/layout/build-header-hierarchy.ts +++ b/packages/s2-core/src/facet/layout/build-header-hierarchy.ts @@ -5,17 +5,17 @@ import { type CustomTreeNode, } from '../../common'; import type { PivotDataSet } from '../../data-set'; -import { buildGridHierarchy } from '../layout/build-gird-hierarchy'; -import { buildCustomTreeHierarchy } from '../layout/build-row-custom-tree-hierarchy'; -import { buildRowTreeHierarchy } from '../layout/build-row-tree-hierarchy'; -import { buildTableHierarchy } from '../layout/build-table-hierarchy'; -import { Hierarchy } from '../layout/hierarchy'; +import { buildGridHierarchy } from './build-gird-hierarchy'; +import { buildCustomTreeHierarchy } from './build-row-custom-tree-hierarchy'; +import { buildRowTreeHierarchy } from './build-row-tree-hierarchy'; +import { buildTableHierarchy } from './build-table-hierarchy'; +import { Hierarchy } from './hierarchy'; import type { BuildHeaderParams, BuildHeaderResult, HeaderParams, -} from '../layout/interface'; -import { Node } from '../layout/node'; +} from './interface'; +import { Node } from './node'; const handleCustomTreeHierarchy = (params: HeaderParams) => { const { rootNode, hierarchy, fields, spreadsheet, isRowHeader } = params; diff --git a/packages/s2-core/src/facet/layout/build-table-hierarchy.ts b/packages/s2-core/src/facet/layout/build-table-hierarchy.ts index 7f2abfcacd..fd01a57540 100644 --- a/packages/s2-core/src/facet/layout/build-table-hierarchy.ts +++ b/packages/s2-core/src/facet/layout/build-table-hierarchy.ts @@ -1,5 +1,6 @@ import { SERIES_NUMBER_FIELD } from '../../common/constant'; import { generateHeaderNodes } from '../../utils/layout/generate-header-nodes'; +import { buildGridHierarchy } from './build-gird-hierarchy'; import type { HeaderParams } from './interface'; export const buildTableHierarchy = (params: HeaderParams) => { @@ -30,5 +31,6 @@ export const buildTableHierarchy = (params: HeaderParams) => { query: {}, addMeasureInTotalQuery: false, addTotalMeasureInTotal: false, + handler: buildGridHierarchy, }); }; diff --git a/packages/s2-core/src/facet/layout/index.ts b/packages/s2-core/src/facet/layout/index.ts new file mode 100644 index 0000000000..7a167beddb --- /dev/null +++ b/packages/s2-core/src/facet/layout/index.ts @@ -0,0 +1,4 @@ +export { buildGridHierarchy } from './build-gird-hierarchy'; +export { buildTableHierarchy } from './build-table-hierarchy'; +export { Hierarchy } from './hierarchy'; +export { Node } from './node'; diff --git a/packages/s2-core/src/facet/layout/interface.ts b/packages/s2-core/src/facet/layout/interface.ts index ec30f09da9..f458f5a266 100644 --- a/packages/s2-core/src/facet/layout/interface.ts +++ b/packages/s2-core/src/facet/layout/interface.ts @@ -43,6 +43,7 @@ export interface HeaderNodesParams extends GridHeaderParams { fieldValues: FieldValue[]; level: number; query: Record; + handler: (params: HeaderNodesParams) => void; } export interface HeaderParams { diff --git a/packages/s2-core/src/index.ts b/packages/s2-core/src/index.ts index fbb947e838..11823b302d 100644 --- a/packages/s2-core/src/index.ts +++ b/packages/s2-core/src/index.ts @@ -1,7 +1,5 @@ export { FederatedPointerEvent as GEvent } from '@antv/g'; -export { buildTableHierarchy } from './facet/layout/build-table-hierarchy'; -export { Hierarchy } from './facet/layout/hierarchy'; -export { Node } from './facet/layout/node'; + export { getTheme } from './theme'; export * from './cell'; @@ -9,6 +7,7 @@ export * from './common'; export * from './data-set'; export * from './facet'; export * from './interaction'; +export * from './shared'; export * from './sheet-type'; export * from './ui/tooltip'; export * from './utils'; diff --git a/packages/s2-shared/src/constant/classnames.ts b/packages/s2-core/src/shared/constant/classnames.ts similarity index 70% rename from packages/s2-shared/src/constant/classnames.ts rename to packages/s2-core/src/shared/constant/classnames.ts index 29b190edfb..5f42e2f6f4 100644 --- a/packages/s2-shared/src/constant/classnames.ts +++ b/packages/s2-core/src/shared/constant/classnames.ts @@ -1,4 +1,4 @@ -import { S2_PREFIX_CLS } from '@antv/s2'; +import { S2_PREFIX_CLS } from '../../common/constant/classnames'; export const DRILL_DOWN_PRE_CLASS = `${S2_PREFIX_CLS}-drill-down`; diff --git a/packages/s2-shared/src/constant/i18n/en_US.ts b/packages/s2-core/src/shared/constant/i18n/en_US.ts similarity index 100% rename from packages/s2-shared/src/constant/i18n/en_US.ts rename to packages/s2-core/src/shared/constant/i18n/en_US.ts diff --git a/packages/s2-shared/src/constant/i18n/index.ts b/packages/s2-core/src/shared/constant/i18n/index.ts similarity index 76% rename from packages/s2-shared/src/constant/i18n/index.ts rename to packages/s2-core/src/shared/constant/i18n/index.ts index 5ad2364fba..1ed7ac81db 100644 --- a/packages/s2-shared/src/constant/i18n/index.ts +++ b/packages/s2-core/src/shared/constant/i18n/index.ts @@ -1,4 +1,4 @@ -import type { LocaleType } from '@antv/s2'; +import type { LocaleType } from '../../../common/i18n'; import { EN_US } from './en_US'; import { RU } from './ru_RU'; import { ZH_CN } from './zh_CN'; diff --git a/packages/s2-shared/src/constant/i18n/ru_RU.ts b/packages/s2-core/src/shared/constant/i18n/ru_RU.ts similarity index 100% rename from packages/s2-shared/src/constant/i18n/ru_RU.ts rename to packages/s2-core/src/shared/constant/i18n/ru_RU.ts diff --git a/packages/s2-shared/src/constant/i18n/zh_CN.ts b/packages/s2-core/src/shared/constant/i18n/zh_CN.ts similarity index 100% rename from packages/s2-shared/src/constant/i18n/zh_CN.ts rename to packages/s2-core/src/shared/constant/i18n/zh_CN.ts diff --git a/packages/s2-shared/src/constant/index.ts b/packages/s2-core/src/shared/constant/index.ts similarity index 100% rename from packages/s2-shared/src/constant/index.ts rename to packages/s2-core/src/shared/constant/index.ts diff --git a/packages/s2-shared/src/constant/option.ts b/packages/s2-core/src/shared/constant/option.ts similarity index 84% rename from packages/s2-shared/src/constant/option.ts rename to packages/s2-core/src/shared/constant/option.ts index 8c4e359e48..98808b3be5 100644 --- a/packages/s2-shared/src/constant/option.ts +++ b/packages/s2-core/src/shared/constant/option.ts @@ -1,4 +1,4 @@ -import type { S2Options } from '@antv/s2'; +import type { S2Options } from '../../common'; export const SHEET_COMPONENT_DEFAULT_OPTIONS: S2Options = { tooltip: { diff --git a/packages/s2-shared/src/constant/resize.ts b/packages/s2-core/src/shared/constant/resize.ts similarity index 100% rename from packages/s2-shared/src/constant/resize.ts rename to packages/s2-core/src/shared/constant/resize.ts diff --git a/packages/s2-shared/src/constant/sort.ts b/packages/s2-core/src/shared/constant/sort.ts similarity index 90% rename from packages/s2-shared/src/constant/sort.ts rename to packages/s2-core/src/shared/constant/sort.ts index 8464aa5467..d8b92ce702 100644 --- a/packages/s2-shared/src/constant/sort.ts +++ b/packages/s2-core/src/shared/constant/sort.ts @@ -1,4 +1,4 @@ -import { S2_PREFIX_CLS, i18n } from '@antv/s2'; +import { i18n, S2_PREFIX_CLS } from '../../common'; export const getSortMethod = () => [ { diff --git a/packages/s2-shared/src/constant/theme.ts b/packages/s2-core/src/shared/constant/theme.ts similarity index 71% rename from packages/s2-shared/src/constant/theme.ts rename to packages/s2-core/src/shared/constant/theme.ts index b9691f0832..8bb0c51171 100644 --- a/packages/s2-shared/src/constant/theme.ts +++ b/packages/s2-core/src/shared/constant/theme.ts @@ -1,4 +1,4 @@ -import { S2_PREFIX_CLS } from '@antv/s2'; +import { S2_PREFIX_CLS } from '../../common'; /** * 注入主题 css 变量的节点名 diff --git a/packages/s2-shared/src/icons/calendar-icon.svg b/packages/s2-core/src/shared/icons/calendar-icon.svg similarity index 100% rename from packages/s2-shared/src/icons/calendar-icon.svg rename to packages/s2-core/src/shared/icons/calendar-icon.svg diff --git a/packages/s2-shared/src/icons/col-icon.svg b/packages/s2-core/src/shared/icons/col-icon.svg similarity index 100% rename from packages/s2-shared/src/icons/col-icon.svg rename to packages/s2-core/src/shared/icons/col-icon.svg diff --git a/packages/s2-shared/src/icons/dot-icon.svg b/packages/s2-core/src/shared/icons/dot-icon.svg similarity index 100% rename from packages/s2-shared/src/icons/dot-icon.svg rename to packages/s2-core/src/shared/icons/dot-icon.svg diff --git a/packages/s2-shared/src/icons/location-icon.svg b/packages/s2-core/src/shared/icons/location-icon.svg similarity index 100% rename from packages/s2-shared/src/icons/location-icon.svg rename to packages/s2-core/src/shared/icons/location-icon.svg diff --git a/packages/s2-shared/src/icons/row-icon.svg b/packages/s2-core/src/shared/icons/row-icon.svg similarity index 100% rename from packages/s2-shared/src/icons/row-icon.svg rename to packages/s2-core/src/shared/icons/row-icon.svg diff --git a/packages/s2-shared/src/icons/search-icon.svg b/packages/s2-core/src/shared/icons/search-icon.svg similarity index 100% rename from packages/s2-shared/src/icons/search-icon.svg rename to packages/s2-core/src/shared/icons/search-icon.svg diff --git a/packages/s2-shared/src/icons/sort-icon.svg b/packages/s2-core/src/shared/icons/sort-icon.svg similarity index 100% rename from packages/s2-shared/src/icons/sort-icon.svg rename to packages/s2-core/src/shared/icons/sort-icon.svg diff --git a/packages/s2-shared/src/icons/switcher-icon.svg b/packages/s2-core/src/shared/icons/switcher-icon.svg similarity index 100% rename from packages/s2-shared/src/icons/switcher-icon.svg rename to packages/s2-core/src/shared/icons/switcher-icon.svg diff --git a/packages/s2-shared/src/icons/text-icon.svg b/packages/s2-core/src/shared/icons/text-icon.svg similarity index 100% rename from packages/s2-shared/src/icons/text-icon.svg rename to packages/s2-core/src/shared/icons/text-icon.svg diff --git a/packages/s2-shared/src/icons/value-icon.svg b/packages/s2-core/src/shared/icons/value-icon.svg similarity index 100% rename from packages/s2-shared/src/icons/value-icon.svg rename to packages/s2-core/src/shared/icons/value-icon.svg diff --git a/packages/s2-core/src/shared/index.ts b/packages/s2-core/src/shared/index.ts new file mode 100644 index 0000000000..28e208300f --- /dev/null +++ b/packages/s2-core/src/shared/index.ts @@ -0,0 +1,5 @@ +export * from './constant'; +export * from './interface'; +export * from './utils'; + +export * from './interface'; diff --git a/packages/s2-shared/src/interface.ts b/packages/s2-core/src/shared/interface.ts similarity index 92% rename from packages/s2-shared/src/interface.ts rename to packages/s2-core/src/shared/interface.ts index 89a9d57527..3e901b69dc 100644 --- a/packages/s2-shared/src/interface.ts +++ b/packages/s2-core/src/shared/interface.ts @@ -1,39 +1,41 @@ +import { FederatedPointerEvent as GEvent } from '@antv/g'; +import type { + ColCell, + CornerCell, + DataCell, + MergedCell, + RowCell, + SeriesNumberCell, + TableDataCell, +} from '../cell'; import type { BaseTooltipOperatorMenuOptions, CellScrollPosition, CellSelectedHandler, - ColCell, CopyableList, - CornerCell, - DataCell, - GEvent, HeaderActionIcon, HiddenColumnsInfo, LayoutResult, - MergedCell, - Node, Pagination, RawData, ResizeInfo, ResizeParams, - RowCell, RowCellCollapsedParams, S2CellType, S2DataConfig, S2MountContainer, S2Options, S2RenderOptions, - SeriesNumberCell, SortParams, - SpreadSheet, - TableDataCell, TargetCellInfo, ThemeCfg, TooltipContentType, TooltipOperatorOptions, ViewMeta, ViewMetaData, -} from '@antv/s2'; +} from '../common'; +import type { Node } from '../facet/layout/node'; +import type { SpreadSheet } from '../sheet-type'; // 是否开启自适应宽高,并指定容器 export type Adaptive = @@ -61,27 +63,10 @@ export type LayoutPaginationParams = { total: number; current: number; }; -type _ShowPagination = - | boolean - | { - onShowSizeChange?: (pageSize: number) => void; - onChange?: (current: number) => void; - }; - -type ShowPagination = - OverrideShowPagination extends true - ? Options extends { - pagination?: { onShowSizeChange?: unknown; onChange?: unknown }; - } - ? boolean | Options['pagination'] - : _ShowPagination - : _ShowPagination; export interface BaseSheetComponentProps< PartialDrillDown = PartDrillDown, - Header = unknown, Options = S2Options, - OverrideShowPagination = false, > { sheetType?: SheetType; spreadsheet?: ( @@ -94,9 +79,7 @@ export interface BaseSheetComponentProps< loading?: boolean; partDrillDown?: PartialDrillDown; adaptive?: Adaptive; - showPagination?: ShowPagination; themeCfg?: ThemeCfg; - header?: Header; // ============== Row Cell ==================== onRowCellHover?: (data: TargetCellInfo) => void; @@ -185,8 +168,9 @@ export interface BaseSheetComponentProps< onBeforeRender?: () => void; onAfterRender?: () => void; onMounted?: (spreadsheet: SpreadSheet) => void; - onUpdate?: (renderOptions: S2RenderOptions) => S2RenderOptions; + onUpdate?: (renderOptions: S2RenderOptions) => S2RenderOptions | void; onUpdateAfterRender?: (renderOptions: S2RenderOptions) => void; + onLoading?: (loading: boolean) => void; onDestroy?: () => void; // ============== Resize ==================== @@ -258,18 +242,21 @@ export interface TooltipOperatorProps

} // 下钻相关类型 -export interface BaseDataSet { +export interface BaseDrillDownDataSet { name: string; value: string; type?: 'text' | 'location' | 'date'; disabled?: boolean; } -export interface BaseDrillDownComponentProps { +export interface BaseDrillDownComponentProps< + DataSet = BaseDrillDownDataSet, + Text = string, +> { className?: string; - titleText?: string; + title?: Text; searchText?: string; - clearButtonText?: string; + clearText?: Text; dataSet?: DataSet[] | undefined; drillFields?: string[]; disabledFields?: string[]; diff --git a/packages/s2-shared/src/styles/drill-down.less b/packages/s2-core/src/shared/styles/drill-down.less similarity index 94% rename from packages/s2-shared/src/styles/drill-down.less rename to packages/s2-core/src/shared/styles/drill-down.less index 40beb64006..4d4ec9e556 100644 --- a/packages/s2-shared/src/styles/drill-down.less +++ b/packages/s2-core/src/shared/styles/drill-down.less @@ -12,14 +12,15 @@ font-size: 14px; padding: 0 16px; margin-top: 16px; + align-items: center; + justify-content: space-between; button { position: absolute; right: 0; - top: -4px; + top: 0; font-size: 12px; color: #1890ff; - letter-spacing: -0.2px; line-height: 20px; } } diff --git a/packages/s2-shared/src/styles/theme/dark.less b/packages/s2-core/src/shared/styles/theme/dark.less similarity index 100% rename from packages/s2-shared/src/styles/theme/dark.less rename to packages/s2-core/src/shared/styles/theme/dark.less diff --git a/packages/s2-shared/src/styles/tooltip/index.less b/packages/s2-core/src/shared/styles/tooltip/index.less similarity index 98% rename from packages/s2-shared/src/styles/tooltip/index.less rename to packages/s2-core/src/shared/styles/tooltip/index.less index 9276ce94a4..9918ab9578 100644 --- a/packages/s2-shared/src/styles/tooltip/index.less +++ b/packages/s2-core/src/shared/styles/tooltip/index.less @@ -1,4 +1,4 @@ -@import '../variables.less'; +@import '../../../ui/tooltip/index.less'; .@{tooltip-cls-prefix} { &-tips, diff --git a/packages/s2-shared/src/styles/tooltip/operator.less b/packages/s2-core/src/shared/styles/tooltip/operator.less similarity index 100% rename from packages/s2-shared/src/styles/tooltip/operator.less rename to packages/s2-core/src/shared/styles/tooltip/operator.less diff --git a/packages/s2-shared/src/styles/variables.less b/packages/s2-core/src/shared/styles/variables.less similarity index 84% rename from packages/s2-shared/src/styles/variables.less rename to packages/s2-core/src/shared/styles/variables.less index 8dacd99a63..aeacc6a3a3 100644 --- a/packages/s2-shared/src/styles/variables.less +++ b/packages/s2-core/src/shared/styles/variables.less @@ -1,4 +1,4 @@ -@import '@antv/s2/src/styles/variables.less'; +@import '../../styles/variables.less'; @tooltip-operator-cls-prefix: ~'@{s2-cls-prefix}-tooltip-operator'; @tooltip-menu-item-text-color: rgba(0, 0, 0, 0.65); @@ -19,6 +19,3 @@ // 头部组件 @header-cls-prefix: ~'@{s2-cls-prefix}-header'; - -// 图标 -@icon-cls-prefix: ~'@{s2-cls-prefix}-icon'; diff --git a/packages/s2-shared/src/utils/classnames.ts b/packages/s2-core/src/shared/utils/classnames.ts similarity index 100% rename from packages/s2-shared/src/utils/classnames.ts rename to packages/s2-core/src/shared/utils/classnames.ts diff --git a/packages/s2-shared/src/utils/drill-down.ts b/packages/s2-core/src/shared/utils/drill-down.ts similarity index 95% rename from packages/s2-shared/src/utils/drill-down.ts rename to packages/s2-core/src/shared/utils/drill-down.ts index 22b3e82b19..3bceec5f95 100644 --- a/packages/s2-shared/src/utils/drill-down.ts +++ b/packages/s2-core/src/shared/utils/drill-down.ts @@ -1,14 +1,14 @@ +import { FederatedPointerEvent as GEvent } from '@antv/g'; +import { clone, filter, isEmpty, size } from 'lodash'; import { S2Event, - type GEvent, type HeaderActionIcon, - type Node, type PartDrillDownDataCache, - type PivotDataSet, type S2Options, - type SpreadSheet, -} from '@antv/s2'; -import { clone, filter, isEmpty, size } from 'lodash'; +} from '../../common'; +import type { PivotDataSet } from '../../data-set'; +import type { Node } from '../../facet/layout/node'; +import type { SpreadSheet } from '../../sheet-type'; import type { PartDrillDown, PartDrillDownInfo } from '../interface'; export interface DrillDownParams { diff --git a/packages/s2-core/src/shared/utils/index.ts b/packages/s2-core/src/shared/utils/index.ts new file mode 100644 index 0000000000..c02e3a9f01 --- /dev/null +++ b/packages/s2-core/src/shared/utils/index.ts @@ -0,0 +1,4 @@ +export * from './classnames'; +export * from './drill-down'; +export * from './options'; +export * from './resize'; diff --git a/packages/s2-shared/src/utils/options.ts b/packages/s2-core/src/shared/utils/options.ts similarity index 72% rename from packages/s2-shared/src/utils/options.ts rename to packages/s2-core/src/shared/utils/options.ts index 52be6f8424..c33f488184 100644 --- a/packages/s2-shared/src/utils/options.ts +++ b/packages/s2-core/src/shared/utils/options.ts @@ -1,4 +1,5 @@ -import { customMerge, DEFAULT_OPTIONS, type S2Options } from '@antv/s2'; +import { DEFAULT_OPTIONS, type S2Options } from '../../common'; +import { customMerge } from '../../utils'; import { SHEET_COMPONENT_DEFAULT_OPTIONS } from '../constant/option'; export const getBaseSheetComponentOptions = ( diff --git a/packages/s2-shared/src/utils/resize.ts b/packages/s2-core/src/shared/utils/resize.ts similarity index 98% rename from packages/s2-shared/src/utils/resize.ts rename to packages/s2-core/src/shared/utils/resize.ts index 5e0c1fd46a..8d278c1f12 100644 --- a/packages/s2-shared/src/utils/resize.ts +++ b/packages/s2-core/src/shared/utils/resize.ts @@ -1,5 +1,5 @@ -import { floor } from '@antv/s2'; import { debounce, isBoolean } from 'lodash'; +import { floor } from '../../utils'; import { RESIZE_RENDER_DELAY } from '../constant/resize'; import type { Adaptive, ResizeEffectParams } from '../interface'; diff --git a/packages/s2-core/src/sheet-type/spread-sheet.ts b/packages/s2-core/src/sheet-type/spread-sheet.ts index 3a38d9edb5..28b888d1d1 100644 --- a/packages/s2-core/src/sheet-type/spread-sheet.ts +++ b/packages/s2-core/src/sheet-type/spread-sheet.ts @@ -488,6 +488,7 @@ export abstract class SpreadSheet extends EE { const canvas = this.getCanvasElement(); if (canvas) { + // @ts-ignore // eslint-disable-next-line no-underscore-dangle delete canvas.__s2_instance__; } diff --git a/packages/s2-core/src/styles/variables.less b/packages/s2-core/src/styles/variables.less index 9bf51d15f8..a74d8d3dab 100644 --- a/packages/s2-core/src/styles/variables.less +++ b/packages/s2-core/src/styles/variables.less @@ -1,8 +1,11 @@ // s2 类名前缀 @s2-cls-prefix: antv-s2; +// css 变量前缀 +@css-var-prefix: ~'--@{s2-cls-prefix}'; + // Tooltip @tooltip-cls-prefix: ~'@{s2-cls-prefix}-tooltip'; -// css 变量前缀 -@css-var-prefix: ~'--@{s2-cls-prefix}'; +// 图标 +@icon-cls-prefix: ~'@{s2-cls-prefix}-icon'; diff --git a/packages/s2-core/src/utils/cell/header-cell.ts b/packages/s2-core/src/utils/cell/header-cell.ts index eb16aee33c..cca3206659 100644 --- a/packages/s2-core/src/utils/cell/header-cell.ts +++ b/packages/s2-core/src/utils/cell/header-cell.ts @@ -14,16 +14,17 @@ import type { import type { Node } from '../../facet/layout/node'; const normalizeIcons = ( - icons: HeaderActionName[], + icons: HeaderActionName[] = [], position: IconPosition = 'right', -) => - icons.map((icon) => { +) => { + return icons.map((icon) => { if (typeof icon === 'string') { return { name: icon, position }; } return icon; }); +}; const normalizeActionIconCfg = (actionIconList: HeaderActionIcon[] = []) => actionIconList.map( diff --git a/packages/s2-core/src/utils/cell/index.ts b/packages/s2-core/src/utils/cell/index.ts new file mode 100644 index 0000000000..e7b8f4e0bc --- /dev/null +++ b/packages/s2-core/src/utils/cell/index.ts @@ -0,0 +1,6 @@ +export * from './cell'; +export * from './data-cell'; +export * from './header-cell'; +export * from './merged-cell'; +export * from './table-col-cell'; +export * from './text-scrolling'; diff --git a/packages/s2-core/src/utils/cell/merged-cell.ts b/packages/s2-core/src/utils/cell/merged-cell.ts new file mode 100644 index 0000000000..378335f457 --- /dev/null +++ b/packages/s2-core/src/utils/cell/merged-cell.ts @@ -0,0 +1,140 @@ +import { find, forEach, includes, isEqual } from 'lodash'; +import type { DataCell } from '../../cell'; + +/** + * according to the coordinates of the starting point of the rectangle, + * return the four sides of the rectangle in a clockwise direction. + * [TopLeft] --- [TopRight] + * | | + * [BottomLeft] -[BottomRight] + * @param x + * @param y + * @param width + * @param height + */ +export const getRectangleEdges = ( + x: number, + y: number, + width: number, + height: number, +) => { + const topLeft: [number, number] = [x, y]; + + const topRight: [number, number] = [x + width, y]; + + const bottomRight: [number, number] = [x + width, y + height]; + + const bottomLeft: [number, number] = [x, y + height]; + + return [ + [topLeft, topRight], + [topRight, bottomRight], + [bottomRight, bottomLeft], + [bottomLeft, topLeft], + ]; +}; + +/** + * return the edges without overlapping edges + * @param edges the collection of edges + */ +export const unique = (edges: [number, number][][]) => { + const result: [number, number][][] = []; + + forEach(edges, (edge) => { + const reverseEdge = [edge[1], edge[0]]; + + if (!JSON.stringify(edges).includes(JSON.stringify(reverseEdge))) { + result.push(edge); + } + }); + + return result; +}; + +/** + * return the edge according to the coordinate of current edge + * eg: curEdge: [[0,0], [100,0]] then the next edge: [[100, 0 ], [100, 100]] + * @param curEdge the coordinate of current edge + * @param edges the collection of edges + */ +export const getNextEdge = ( + curEdge: [number, number][], + edges: [number, number][][], +): [number, number][] | undefined => + find(edges, (edge) => isEqual(edge[0], curEdge[1])); +/** + * return all the points of the polygon + * @param cells the collection of information of cells which needed be merged + */ +export const getPolygonPoints = (cells: DataCell[]) => { + let allEdges: [number, number][][] = []; + + cells.forEach((cell) => { + const meta = cell.getMeta(); + const { x, y, width, height } = meta; + + allEdges = allEdges.concat(getRectangleEdges(x, y, width, height)); + }); + allEdges = unique(allEdges); + + let allPoints: [number, number][] = []; + const startEdge = allEdges[0]; + let curEdge = startEdge; + let nextEdge: [number, number][] | undefined = []; + + while (!isEqual(startEdge, nextEdge)) { + allPoints = allPoints.concat(curEdge); + nextEdge = getNextEdge(curEdge, allEdges); + curEdge = nextEdge!; + } + + return allPoints; +}; + +export const getRightAndBottomCells = (cells: DataCell[]) => { + const right: DataCell[] = []; + const bottom: DataCell[] = []; + const bottomRightCornerCell: DataCell[] = []; + + cells.forEach((cell) => { + const [row, col] = cell.position || []; + + if ( + !find( + cells, + (temp) => temp.position?.[0] === row + 1 && temp.position?.[1] === col, + ) + ) { + bottom.push(cell); + } + + if ( + !find( + cells, + (temp) => temp.position?.[1] === col + 1 && temp.position?.[0] === row, + ) + ) { + right.push(cell); + } + }); + + // 在绘制了 right border 后,如果它上面的 cell 也是 merge cell 中的,且无需绘制 right 时,需要单独为其位置 bottomRight corner 的 border,反正连线会断 + right.forEach((cell) => { + const [row, col] = cell.position || []; + const top = find( + cells, + (temp) => temp.position?.[0] === row - 1 && temp.position?.[1] === col, + ); + + if (top && !includes(right, top)) { + bottomRightCornerCell.push(top); + } + }); + + return { + bottom, + right, + bottomRightCornerCell, + }; +}; diff --git a/packages/s2-core/src/utils/export/copy/common.ts b/packages/s2-core/src/utils/export/copy/common.ts index d47f3ef743..5737cd1a38 100644 --- a/packages/s2-core/src/utils/export/copy/common.ts +++ b/packages/s2-core/src/utils/export/copy/common.ts @@ -1,5 +1,5 @@ import { escape, map, max } from 'lodash'; -import type { DataItem, SimpleData } from '../../../common'; +import type { CellMeta, DataItem, SimpleData } from '../../../common'; import { LINE_SEPARATOR, ROOT_NODE_ID, TAB_SEPARATOR } from '../../../common'; import { CopyMIMEType, @@ -13,6 +13,7 @@ import { type Transformer, } from '../../../common/interface/export'; import type { Node } from '../../../facet/layout/node'; +import type { SpreadSheet } from '../../../sheet-type/spread-sheet'; // 把 string[][] 矩阵转换成 CopyablePlain export const matrixPlainTextTransformer = ( @@ -228,3 +229,13 @@ export const getNodeFormatData = (leafNode: Node) => { return line; }; + +export const getHeaderNodeFromMeta = ( + meta: CellMeta, + spreadsheet: SpreadSheet, +) => { + const { rowIndex, colIndex } = meta; + const { facet } = spreadsheet; + + return [facet.getRowNodeByIndex(rowIndex), facet.getColNodeByIndex(colIndex)]; +}; diff --git a/packages/s2-core/src/utils/export/copy/core.ts b/packages/s2-core/src/utils/export/copy/core.ts index 109f9dd6da..a5f71ff55e 100644 --- a/packages/s2-core/src/utils/export/copy/core.ts +++ b/packages/s2-core/src/utils/export/copy/core.ts @@ -27,16 +27,6 @@ import { processSelectedTableByHeader, } from './table-copy'; -export const getHeaderNodeFromMeta = ( - meta: CellMeta, - spreadsheet: SpreadSheet, -) => { - const { rowIndex, colIndex } = meta; - const { facet } = spreadsheet; - - return [facet.getRowNodeByIndex(rowIndex), facet.getColNodeByIndex(colIndex)]; -}; - /** * 返回选中数据单元格生成的二维数组( CellMeta[][]) * @param { CellMeta[] } cells @@ -222,3 +212,50 @@ export const asyncProcessAllSelected = ( return asyncProcessSelectedAllTable(params); }; + +/** + * 异步获取文本数据 (text/plain) + * @example + const data = await asyncGetAllPlainData({ + sheetInstance: s2, + split: '\t', + formatOptions: true, + }); + */ +export const asyncGetAllPlainData = async (params: CopyAllDataParams) => { + const result = await asyncProcessAllSelected(params); + + return result[0].content; +}; + +/** + * 异步获取富文本数据 (text/html) + * @example + const data = await asyncGetAllHtmlData({ + sheetInstance: s2, + split: '\t', + formatOptions: true, + }); + */ +export const asyncGetAllHtmlData = async (params: CopyAllDataParams) => { + const result = await asyncProcessAllSelected(params); + + return result[1].content; +}; + +/** + * 异步获取数据 + * - 文本 (text/plain) + * - 富文本 (text/html) + * @example + const data = await asyncGetAllData({ + sheetInstance: s2, + split: '\t', + formatOptions: true, + }); + */ +export const asyncGetAllData = async (params: CopyAllDataParams) => { + const result = await asyncProcessAllSelected(params); + + return result; +}; diff --git a/packages/s2-core/src/utils/export/copy/index.ts b/packages/s2-core/src/utils/export/copy/index.ts index dd7fcf3393..330a27906b 100644 --- a/packages/s2-core/src/utils/export/copy/index.ts +++ b/packages/s2-core/src/utils/export/copy/index.ts @@ -1,6 +1,9 @@ -import type { SheetCopyConstructorParams } from '../../../common/interface/export'; -import { getSelectedData } from './core'; -import { PivotDataCellCopy } from './pivot-data-cell-copy'; - -export { PivotDataCellCopy, getSelectedData }; -export type { SheetCopyConstructorParams }; +export type { SheetCopyConstructorParams } from '../../../common/interface/export'; +export { + asyncGetAllData, + asyncGetAllHtmlData, + asyncGetAllPlainData, + getSelectedData, +} from './core'; +export { PivotDataCellCopy } from './pivot-data-cell-copy'; +export { strategyCopy } from './strategy-copy'; diff --git a/packages/s2-core/src/utils/export/copy/pivot-data-cell-copy.ts b/packages/s2-core/src/utils/export/copy/pivot-data-cell-copy.ts index de0759c258..72e21f42cb 100644 --- a/packages/s2-core/src/utils/export/copy/pivot-data-cell-copy.ts +++ b/packages/s2-core/src/utils/export/copy/pivot-data-cell-copy.ts @@ -38,10 +38,10 @@ import { BaseDataCellCopy } from './base-data-cell-copy'; import { assembleMatrix, completeMatrix, + getHeaderNodeFromMeta, getMaxRowLen, getNodeFormatData, } from './common'; -import { getHeaderNodeFromMeta } from './core'; export class PivotDataCellCopy extends BaseDataCellCopy { protected leafRowNodes: Node[] = []; diff --git a/packages/s2-react/src/components/export/strategy-copy.ts b/packages/s2-core/src/utils/export/copy/strategy-copy.ts similarity index 91% rename from packages/s2-react/src/components/export/strategy-copy.ts rename to packages/s2-core/src/utils/export/copy/strategy-copy.ts index a7f838c3e4..f5d635ae8e 100644 --- a/packages/s2-react/src/components/export/strategy-copy.ts +++ b/packages/s2-core/src/utils/export/copy/strategy-copy.ts @@ -1,18 +1,17 @@ -import { - PivotDataCellCopy, - assembleMatrix, - getEmptyPlaceholder, - getHeaderList, - getNodeFormatData, - safeJsonParse, - type CopyAllDataParams, - type CopyableList, - type Node, - type SheetCopyConstructorParams, - type SimpleData, - type ViewMeta, -} from '@antv/s2'; import { flatten, forEach, get, isArray, isNil, isObject, map } from 'lodash'; +import type { + CopyAllDataParams, + CopyableList, + SheetCopyConstructorParams, + SimpleData, + ViewMeta, +} from '../../../common'; +import type { Node } from '../../../facet/layout/node'; +import { safeJsonParse } from '../../common'; +import { getEmptyPlaceholder } from '../../text'; +import { getHeaderList } from '../method'; +import { assembleMatrix, getNodeFormatData } from './common'; +import { PivotDataCellCopy } from './pivot-data-cell-copy'; /** * Process the multi-measure with single-lines diff --git a/packages/s2-core/src/utils/export/copy/table-copy.ts b/packages/s2-core/src/utils/export/copy/table-copy.ts index 22d281044e..92dbda7abb 100644 --- a/packages/s2-core/src/utils/export/copy/table-copy.ts +++ b/packages/s2-core/src/utils/export/copy/table-copy.ts @@ -18,8 +18,7 @@ import { getSelectedRows, } from '../method'; import { BaseDataCellCopy } from './base-data-cell-copy'; -import { assembleMatrix } from './common'; -import { getHeaderNodeFromMeta } from './core'; +import { assembleMatrix, getHeaderNodeFromMeta } from './common'; class TableDataCellCopy extends BaseDataCellCopy { private displayData: RawData[]; diff --git a/packages/s2-core/src/utils/export/index.ts b/packages/s2-core/src/utils/export/index.ts index f5998817fc..694abfb13a 100644 --- a/packages/s2-core/src/utils/export/index.ts +++ b/packages/s2-core/src/utils/export/index.ts @@ -1,11 +1,11 @@ -import type { +export type { CopyableList, FormatOptions, } from '../../common/interface/export'; -import { assembleMatrix, getMaxRowLen, getNodeFormatData } from './copy/common'; -import { getHeaderList } from './method'; + +export { assembleMatrix, getMaxRowLen, getNodeFormatData } from './copy/common'; +export { asyncGetAllPlainData } from './copy/core'; +export { getHeaderList } from './method'; export * from './copy'; export * from './utils'; -export { assembleMatrix, getHeaderList, getMaxRowLen, getNodeFormatData }; -export type { CopyableList, FormatOptions }; diff --git a/packages/s2-core/src/utils/export/utils.ts b/packages/s2-core/src/utils/export/utils.ts index d12f34dbf3..7799d081bf 100644 --- a/packages/s2-core/src/utils/export/utils.ts +++ b/packages/s2-core/src/utils/export/utils.ts @@ -1,11 +1,9 @@ import { concat, get } from 'lodash'; import { CopyMIMEType, - type CopyAllDataParams, type Copyable, type CopyableItem, } from '../../common/interface/export'; -import { asyncProcessAllSelected } from './copy/core'; /** * 同步复制 @@ -114,50 +112,3 @@ export const download = (dataString: string, fileName: string) => { console.error(error); } }; - -/** - * 异步获取文本数据 (text/plain) - * @example - const data = await asyncGetAllPlainData({ - sheetInstance: s2, - split: '\t', - formatOptions: true, - }); - */ -export const asyncGetAllPlainData = async (params: CopyAllDataParams) => { - const result = await asyncProcessAllSelected(params); - - return result[0].content; -}; - -/** - * 异步获取富文本数据 (text/html) - * @example - const data = await asyncGetAllHtmlData({ - sheetInstance: s2, - split: '\t', - formatOptions: true, - }); - */ -export const asyncGetAllHtmlData = async (params: CopyAllDataParams) => { - const result = await asyncProcessAllSelected(params); - - return result[1].content; -}; - -/** - * 异步获取数据 - * - 文本 (text/plain) - * - 富文本 (text/html) - * @example - const data = await asyncGetAllData({ - sheetInstance: s2, - split: '\t', - formatOptions: true, - }); - */ -export const asyncGetAllData = async (params: CopyAllDataParams) => { - const result = await asyncProcessAllSelected(params); - - return result; -}; diff --git a/packages/s2-core/src/utils/index.ts b/packages/s2-core/src/utils/index.ts index 74db754040..7f1c657c26 100644 --- a/packages/s2-core/src/utils/index.ts +++ b/packages/s2-core/src/utils/index.ts @@ -1,8 +1,7 @@ export { auto } from './formatter'; export * from './canvas'; -export * from './cell/cell'; -export * from './cell/data-cell'; +export * from './cell'; export * from './color'; export * from './common'; export * from './export'; diff --git a/packages/s2-core/src/utils/interaction/merge-cell.ts b/packages/s2-core/src/utils/interaction/merge-cell.ts index 4804104755..4d4329c089 100644 --- a/packages/s2-core/src/utils/interaction/merge-cell.ts +++ b/packages/s2-core/src/utils/interaction/merge-cell.ts @@ -4,7 +4,6 @@ import { filter, find, forEach, - includes, isEmpty, isEqual, map, @@ -20,145 +19,6 @@ import type { } from '../../common/interface'; import type { SpreadSheet } from '../../sheet-type'; -/** - * according to the coordinates of the starting point of the rectangle, - * return the four sides of the rectangle in a clockwise direction. - * [TopLeft] --- [TopRight] - * | | - * [BottomLeft] -[BottomRight] - * @param x - * @param y - * @param width - * @param height - */ -export const getRectangleEdges = ( - x: number, - y: number, - width: number, - height: number, -) => { - const topLeft: [number, number] = [x, y]; - - const topRight: [number, number] = [x + width, y]; - - const bottomRight: [number, number] = [x + width, y + height]; - - const bottomLeft: [number, number] = [x, y + height]; - - return [ - [topLeft, topRight], - [topRight, bottomRight], - [bottomRight, bottomLeft], - [bottomLeft, topLeft], - ]; -}; - -/** - * return the edges without overlapping edges - * @param edges the collection of edges - */ -export const unique = (edges: [number, number][][]) => { - const result: [number, number][][] = []; - - forEach(edges, (edge) => { - const reverseEdge = [edge[1], edge[0]]; - - if (!JSON.stringify(edges).includes(JSON.stringify(reverseEdge))) { - result.push(edge); - } - }); - - return result; -}; - -/** - * return the edge according to the coordinate of current edge - * eg: curEdge: [[0,0], [100,0]] then the next edge: [[100, 0 ], [100, 100]] - * @param curEdge the coordinate of current edge - * @param edges the collection of edges - */ -export const getNextEdge = ( - curEdge: [number, number][], - edges: [number, number][][], -): [number, number][] | undefined => - find(edges, (edge) => isEqual(edge[0], curEdge[1])); - -/** - * return all the points of the polygon - * @param cells the collection of information of cells which needed be merged - */ -export const getPolygonPoints = (cells: DataCell[]) => { - let allEdges: [number, number][][] = []; - - cells.forEach((cell) => { - const meta = cell.getMeta(); - const { x, y, width, height } = meta; - - allEdges = allEdges.concat(getRectangleEdges(x, y, width, height)); - }); - allEdges = unique(allEdges); - - let allPoints: [number, number][] = []; - const startEdge = allEdges[0]; - let curEdge = startEdge; - let nextEdge: [number, number][] | undefined = []; - - while (!isEqual(startEdge, nextEdge)) { - allPoints = allPoints.concat(curEdge); - nextEdge = getNextEdge(curEdge, allEdges); - curEdge = nextEdge!; - } - - return allPoints; -}; - -export const getRightAndBottomCells = (cells: DataCell[]) => { - const right: DataCell[] = []; - const bottom: DataCell[] = []; - const bottomRightCornerCell: DataCell[] = []; - - cells.forEach((cell) => { - const [row, col] = cell.position || []; - - if ( - !find( - cells, - (temp) => temp.position?.[0] === row + 1 && temp.position?.[1] === col, - ) - ) { - bottom.push(cell); - } - - if ( - !find( - cells, - (temp) => temp.position?.[1] === col + 1 && temp.position?.[0] === row, - ) - ) { - right.push(cell); - } - }); - - // 在绘制了 right border 后,如果它上面的 cell 也是 merge cell 中的,且无需绘制 right 时,需要单独为其位置 bottomRight corner 的 border,反正连线会断 - right.forEach((cell) => { - const [row, col] = cell.position || []; - const top = find( - cells, - (temp) => temp.position?.[0] === row - 1 && temp.position?.[1] === col, - ); - - if (top && !includes(right, top)) { - bottomRightCornerCell.push(top); - } - }); - - return { - bottom, - right, - bottomRightCornerCell, - }; -}; - /** * get cells on the outside of visible area through mergeCellInfo * @param invisibleCellInfo diff --git a/packages/s2-core/src/utils/layout/generate-header-nodes.ts b/packages/s2-core/src/utils/layout/generate-header-nodes.ts index b17e6ca92c..677ecafcf2 100644 --- a/packages/s2-core/src/utils/layout/generate-header-nodes.ts +++ b/packages/s2-core/src/utils/layout/generate-header-nodes.ts @@ -1,6 +1,5 @@ import { EMPTY_FIELD_VALUE, EXTRA_FIELD } from '../../common/constant'; import { i18n } from '../../common/i18n'; -import { buildGridHierarchy } from '../../facet/layout/build-gird-hierarchy'; import type { FieldValue, HeaderNodesParams, @@ -25,6 +24,7 @@ export const generateHeaderNodes = (params: HeaderNodesParams) => { addMeasureInTotalQuery, addTotalMeasureInTotal, spreadsheet, + handler, } = params; const isTableMode = spreadsheet.isTableMode(); @@ -150,7 +150,7 @@ export const generateHeaderNodes = (params: HeaderNodesParams) => { hierarchy.pushIndexNode(node); node.rowIndex = hierarchy.getIndexNodes().length - 1; } else { - buildGridHierarchy({ + handler?.({ addTotalMeasureInTotal, addMeasureInTotalQuery, parentNode: node, @@ -158,7 +158,7 @@ export const generateHeaderNodes = (params: HeaderNodesParams) => { fields, hierarchy, spreadsheet, - }); + } as HeaderNodesParams); } } }; diff --git a/packages/s2-core/src/utils/theme.ts b/packages/s2-core/src/utils/theme.ts index f84f16242e..6cbf01a3e5 100644 --- a/packages/s2-core/src/utils/theme.ts +++ b/packages/s2-core/src/utils/theme.ts @@ -1,6 +1,6 @@ import { PALETTE_MAP, STYLE_ELEMENT_ID } from '../common/constant'; import type { Palette, ThemeName } from '../common/interface/theme'; -import DarkVars from '../styles/theme/dark.less?inline'; +import DarkVars from '../styles/theme/dark.less'; import { injectCssText } from './inject-css-text'; /** @@ -15,5 +15,8 @@ export const getPalette = (themeName?: ThemeName): Palette => { */ export const injectThemeVars = (themeName?: ThemeName) => { // 目前仅 dark 主题需要定制 - injectCssText(STYLE_ELEMENT_ID, themeName === 'dark' ? DarkVars : ''); + injectCssText( + STYLE_ELEMENT_ID, + themeName === 'dark' ? (DarkVars as string) : '', + ); }; diff --git a/packages/s2-core/tsconfig.build.json b/packages/s2-core/tsconfig.build.json new file mode 100644 index 0000000000..5edc7028ae --- /dev/null +++ b/packages/s2-core/tsconfig.build.json @@ -0,0 +1,7 @@ +{ + "extends": "./tsconfig.json", + "include": ["src/**/*", "./typings.d.ts", "../../global.d.ts"], + "compilerOptions": { + "paths": {} + } +} diff --git a/packages/s2-core/tsconfig.declaration.json b/packages/s2-core/tsconfig.declaration.json deleted file mode 100644 index 2dc92e6c64..0000000000 --- a/packages/s2-core/tsconfig.declaration.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "extends": "./tsconfig.json", - "compilerOptions": { - "declarationDir": "temp", - "declaration": true, - "emitDeclarationOnly": true, - "paths": {} - }, - "include": ["src", "../../global.d.ts"] -} diff --git a/packages/s2-core/tsconfig.json b/packages/s2-core/tsconfig.json index 0c0c597cfc..197cba5581 100644 --- a/packages/s2-core/tsconfig.json +++ b/packages/s2-core/tsconfig.json @@ -3,7 +3,6 @@ "compilerOptions": { "paths": { "@antv/s2": ["s2-core/src/index.ts"], - "@antv/s2-shared": ["s2-shared/src/index.ts"], "@/*": ["s2-core/src/*"], "tests/*": ["s2-core/__tests__/*"] }, diff --git a/packages/s2-react-components/README.md b/packages/s2-react-components/README.md index d31c6b5198..e06763c763 100644 --- a/packages/s2-react-components/README.md +++ b/packages/s2-react-components/README.md @@ -34,7 +34,7 @@ $ pnpm add @antv/s2-react-components ```tsx import React from 'React' import { ThemePanel, TextAlignPanel, FrozenPanel } from '@antv/s2-react-components' -import '@antv/s2-components/dist/style.min.css' +import '@antv/s2-react-components/dist/s2-react-components.min.css' const App = () => { return ( @@ -84,7 +84,7 @@ const App = () => { ```tsx import React from 'React' import { ThemePanel } from '@antv/s2-react-components' -import '@antv/s2-components/dist/style.min.css' +import '@antv/s2-react-components/dist/s2-react-components.min.css' const App = () => { const s2Ref = React.useRef(); diff --git a/packages/s2-react-components/__tests__/__mocks__/svg.ts b/packages/s2-react-components/__tests__/__mocks__/svg.ts new file mode 100644 index 0000000000..828bbe5d33 --- /dev/null +++ b/packages/s2-react-components/__tests__/__mocks__/svg.ts @@ -0,0 +1,4 @@ +// eslint-disable-next-line import/no-default-export +export default 'SvgrURL'; + +export const ReactComponent = 'div'; diff --git a/packages/s2-react/__tests__/bugs/issue-1736-spec.tsx b/packages/s2-react-components/__tests__/bugs/issue-1736-spec.tsx similarity index 58% rename from packages/s2-react/__tests__/bugs/issue-1736-spec.tsx rename to packages/s2-react-components/__tests__/bugs/issue-1736-spec.tsx index 57b683e029..c919df4ca2 100644 --- a/packages/s2-react/__tests__/bugs/issue-1736-spec.tsx +++ b/packages/s2-react-components/__tests__/bugs/issue-1736-spec.tsx @@ -3,11 +3,14 @@ * https://github.com/antvis/S2/issues/1736 * Export dropdown visible state error */ -import { Export } from '@/components/export'; +import { Export } from '@/components'; import { waitFor } from '@testing-library/react'; import React from 'react'; import type { Root } from 'react-dom/client'; -import { getMockSheetInstance, renderComponent } from 'tests/util/helpers'; +import { + getMockSheetInstance, + renderComponent, +} from '../../../s2-react/__tests__/util/helpers'; describe('header export component render tests', () => { let unmount: Root['unmount']; @@ -16,27 +19,12 @@ describe('header export component render tests', () => { unmount?.(); }); - test('should render export and dropdown keep invisible', async () => { - const sheet = getMockSheetInstance(); - - unmount = renderComponent(); - - await waitFor(() => { - // export 组件 - expect(document.querySelector('.antv-s2-export')).toBeDefined(); - - // dropdown 不应该渲染 - expect(document.querySelector('.ant-dropdown')).toBe(null); - }); - }); - test('should render export dropdown menu', async () => { const sheet = getMockSheetInstance(); unmount = renderComponent( +
+ +
+ +`; + +exports[`AdvancedSort Component Tests should render custom icon and text 1`] = ` + +
+ +
+
+`; diff --git a/packages/s2-react-components/__tests__/unit/components/advanced-sort/__snapshots__/custom-sort-spec.tsx.snap b/packages/s2-react-components/__tests__/unit/components/advanced-sort/__snapshots__/custom-sort-spec.tsx.snap new file mode 100644 index 0000000000..42d036cd3f --- /dev/null +++ b/packages/s2-react-components/__tests__/unit/components/advanced-sort/__snapshots__/custom-sort-spec.tsx.snap @@ -0,0 +1,646 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`CustomSort Component Tests should render component 1`] = ` + +
+
+
  • + + 杭州市 + + + + + + + + + + + + + + + + +
  • +
  • + + 绍兴市 + + + + + + + + + + + + + + + + +
  • +
  • + + 宁波市 + + + + + + + + + + + + + + + + +
  • +
  • + + 舟山市 + + + + + + + + + + + + + + + + +
  • +
  • + + 成都市 + + + + + + + + + + + + + + + + +
  • +
  • + + 绵阳市 + + + + + + + + + + + + + + + + +
  • +
  • + + 南充市 + + + + + + + + + + + + + + + + +
  • +
  • + + 乐山市 + + + + + + + + + + + + + + + + +
  • +
    +
    +
    +`; diff --git a/packages/s2-react-components/__tests__/unit/components/advanced-sort/advanced-sort-spec.tsx b/packages/s2-react-components/__tests__/unit/components/advanced-sort/advanced-sort-spec.tsx new file mode 100644 index 0000000000..3a725ae3dd --- /dev/null +++ b/packages/s2-react-components/__tests__/unit/components/advanced-sort/advanced-sort-spec.tsx @@ -0,0 +1,68 @@ +import { AdvancedSort } from '@/components'; +import { StepForwardOutlined } from '@ant-design/icons'; +import type { BaseDataSet } from '@antv/s2'; +import { fireEvent, render, screen } from '@testing-library/react'; +import React from 'react'; +import { getMockSheetInstance } from '../../../../../s2-react/__tests__/util/helpers'; + +describe('AdvancedSort Component Tests', () => { + const sheetInstance = getMockSheetInstance(); + + sheetInstance.dataCfg = { + data: [], + fields: { + rows: ['a', 'b'], + columns: ['c', 'd'], + values: ['e', 'f'], + }, + }; + sheetInstance.dataSet = { + ...sheetInstance.dataCfg, + getFieldName: jest.fn(), + getDimensionValues: jest.fn(), + } as unknown as BaseDataSet; + + test('should render component', () => { + const { asFragment, container } = render( + , + ); + + expect(asFragment()).toMatchSnapshot(); + expect(screen.getByText('高级排序')).toBeDefined(); + expect(container.querySelector('.antv-s2-advanced-sort-btn')).toBeDefined(); + }); + + test('should render custom icon and text', () => { + const { asFragment, container } = render( + } + text="自定义" + className="test" + sheetInstance={sheetInstance} + />, + ); + + expect(asFragment()).toMatchSnapshot(); + expect(container.querySelector('.test')).toBeDefined(); + expect(container.querySelector('.anticon-step-forward')).toBeDefined(); + expect(screen.getByText('自定义')).toBeDefined(); + }); + + test('should open sort panel', () => { + const onSortOpen = jest.fn(); + const onSortConfirm = jest.fn(); + + render( + , + ); + + fireEvent.click(screen.getByText('高级排序')); + + expect(screen.getByText('可选字段')).toBeDefined(); + expect(onSortOpen).toHaveBeenCalledTimes(1); + }); +}); diff --git a/packages/s2-react-components/__tests__/unit/components/advanced-sort/custom-sort-spec.tsx b/packages/s2-react-components/__tests__/unit/components/advanced-sort/custom-sort-spec.tsx new file mode 100644 index 0000000000..6886ef22fb --- /dev/null +++ b/packages/s2-react-components/__tests__/unit/components/advanced-sort/custom-sort-spec.tsx @@ -0,0 +1,24 @@ +import { CustomSort } from '@/components'; +import { render } from '@testing-library/react'; +import React from 'react'; + +describe('CustomSort Component Tests', () => { + test('should render component', () => { + const { asFragment } = render( + , + ); + + expect(asFragment()).toMatchSnapshot(); + }); +}); diff --git a/packages/s2-react-components/__tests__/unit/components/drill-down/__snapshots__/drill-down-spec.tsx.snap b/packages/s2-react-components/__tests__/unit/components/drill-down/__snapshots__/drill-down-spec.tsx.snap new file mode 100644 index 0000000000..a57365cea4 --- /dev/null +++ b/packages/s2-react-components/__tests__/unit/components/drill-down/__snapshots__/drill-down-spec.tsx.snap @@ -0,0 +1,688 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`DrillDown Component Tests should render component 1`] = ` + +
    +
    +
    + 选择下钻维度 +
    + +
    + + + + + + + + + + + + + + + +
    +
    + + + + + + + + + + + + + + + + +
    +
    + No data +
    +
    +