Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 修复 Safari 浏览器复制/导出报错 #3050

Merged
merged 1 commit into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/s2-core/src/utils/export/copy/base-data-cell-copy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,11 @@ export abstract class BaseDataCellCopy {

return ((value) => value) as Formatter;
}

/**
* Safari 等不支持 requestIdleCallback 的浏览器, 降级为同步
*/
protected isEnableASync() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

引入 isEnableASync 方法是一个很好的改进,确保了在不支持 requestIdleCallback 的浏览器中能够正常降级为同步操作,避免了潜在的错误。

return this.config.async && !!window.requestIdleCallback;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ export class PivotDataCellCopy extends BaseDataCellCopy {
let dataMatrix: SimpleData[][] = [];

// 把两类导出都封装成异步的,保证导出类型的一致
if (this.config.async) {
if (this.isEnableASync()) {
dataMatrix =
(await this.getDataMatrixByHeaderNodeRIC()) as SimpleData[][];
} else {
Expand Down
2 changes: 1 addition & 1 deletion packages/s2-core/src/utils/export/copy/table-copy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ class TableDataCellCopy extends BaseDataCellCopy {
}

async asyncProcessSelectedTable(allSelected = false): Promise<CopyableList> {
const matrix = this.config.async
const matrix = this.isEnableASync()
? await this.getDataMatrixRIC()
: await Promise.resolve(this.getDataMatrix());

Expand Down
2 changes: 1 addition & 1 deletion s2-site/docs/common/copy-export.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ download(data, 'filename') // filename.csv
| split | 分隔符 | `string` | | ✓ |
| formatOptions | 是否使用 [S2DataConfig.Meta](/api/general/s2-data-config#meta) 进行格式化,可以分别对数据单元格和行列头进行格式化,传 `boolean` 会同时对单元格和行列头生效。 | `boolean \| { formatHeader?: boolean, formatData?: boolean }`| `true` | |
| customTransformer | 导出时支持自定义 (transformer) 数据导出格式化方法 | (transformer: `Transformer`) => [`Partial<Transformer>`](#transformer) | | |
| async | 是否异步复制/导出 | boolean | `true` | |
| async | 是否异步复制/导出(当浏览器不支持 `requestIdleCallback` 时,会强制降级为**同步**) | boolean | `true` | |

##### copyToClipboard

Expand Down
Loading