@antv/s2
Version:
effective spreadsheet render core lib
51 lines • 2.27 kB
JavaScript
import { map } from 'lodash';
import { AsyncRenderThreshold, TAB_SEPARATOR, } from '../../../common';
import { CopyMIMEType } from '../../../common/interface/export';
import { escapeField, getHeaderList, getHeaderMeasureFieldNames, } from '../method';
import { unifyConfig } from './common';
export class BaseDataCellCopy {
initIdleCallbackCount(rowLength) {
this.idleCallbackCount =
rowLength >= AsyncRenderThreshold ? AsyncRenderThreshold : rowLength;
}
constructor(params) {
this.matrixHtmlTransformer = (dataMatrix) => {
return this.config.transformers[CopyMIMEType.HTML](dataMatrix);
};
const { spreadsheet, isExport = false, config } = params;
this.spreadsheet = spreadsheet;
this.config = unifyConfig({ config, spreadsheet, isExport });
}
getHeaderNodeMatrix(node) {
const { formatHeader } = this.config;
return getHeaderMeasureFieldNames(getHeaderList(node.id), node.spreadsheet, formatHeader);
}
matrixPlainTextTransformer(dataMatrix, separator) {
const escapeDataMatrix = map(dataMatrix, (row) => map(row, escapeField));
return this.config.transformers[CopyMIMEType.PLAIN](escapeDataMatrix, separator);
}
matrixTransformer(dataMatrix, separator = TAB_SEPARATOR) {
return [
this.matrixPlainTextTransformer(dataMatrix, separator),
this.matrixHtmlTransformer(dataMatrix),
];
}
getFormatter(options) {
const { field, rowIndex, colIndex } = options;
if (this.config.formatData) {
const viewMeta = this.spreadsheet.facet.getCellMeta(rowIndex, colIndex);
return (value) => {
const formatter = this.spreadsheet.dataSet.getFieldFormatter(field);
return formatter === null || formatter === void 0 ? void 0 : formatter(value, viewMeta === null || viewMeta === void 0 ? void 0 : viewMeta.data, viewMeta);
};
}
return ((value) => value);
}
/**
* Safari 等不支持 requestIdleCallback 的浏览器, 降级为同步
*/
isEnableASync() {
return this.config.async && !!window.requestIdleCallback;
}
}
//# sourceMappingURL=base-data-cell-copy.js.map