Skip to content

Commit

Permalink
fix: 修复 Safari 浏览器复制/导出报错 (#3050)
Browse files Browse the repository at this point in the history
  • Loading branch information
lijinke666 authored Dec 24, 2024
1 parent 78a0c2c commit da7d9e5
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
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() {
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

0 comments on commit da7d9e5

Please sign in to comment.