<commit_before>import {
    ColumnDefine, TableCellSetting, TableHeadSetting, TableSyncRenderer
} from "./table-typings";
import {SortAs, SortOrder} from "../../core/data/component-data";
import {CommonUtils} from "../../core/utils/common-utils";
import {TableCellRendererBase} from "./table-renderer";

export class TableUtils {
    public static updateHeaderSettings(columnDefine: ColumnDefine, settings: TableHeadSetting): TableHeadSetting {
        if (!settings) {
            settings = {
                cellData: null, width: null, visible: true, renderer: null, clazz: '', field: '',
                sortable: false, sortAs: SortAs.string, defaultSortOrder: SortOrder.default
            };
        }
        settings.width = columnDefine.width;
        settings.field = <string>columnDefine.target;
        let headerDef = columnDefine.header;
        if (headerDef) {
            settings.cellData = CommonUtils.isDefined(headerDef.text) ? headerDef.text : settings.cellData;
            settings.renderer = TableUtils.getRenderer(headerDef.renderer);
            settings.clazz = headerDef.clazz;
            settings.sortable = headerDef.sortable;
            settings.sortAs = CommonUtils.isDefined(headerDef.sortAs) ? headerDef.sortAs : settings.sortAs;
            settings.defaultSortOrder = CommonUtils.isDefined(headerDef.sortAs) ?
                headerDef.defaultSortOrder : settings.defaultSortOrder;
        }
        return settings;
    }

    public static updateCellSettings(columnDefine: ColumnDefine, settings: TableCellSetting): TableCellSetting {
        if (!settings) {
            settings = {
                cellData: '', width: null, visible: true, renderer: null, clazz: '', rowSpan: 1,
                editable: false, editorRenderer: null, group: null, field: null, tooltip: null
            }
        }
        settings.width = columnDefine.width;
        settings.group = columnDefine.group;
        settings.field = <string>columnDefine.target;
        let cellDef = columnDefine.cell;
        if (cellDef) {
            settings.renderer = TableUtils.getRenderer(cellDef.renderer);
            settings.clazz = cellDef.clazz;
            settings.editable = cellDef.editable;
            settings.editorRenderer = cellDef.editorRenderer;
            settings.tooltip = cellDef.tooltip;
        }
        return settings;
    }

    public static getRenderer(renderer): TableSyncRenderer {
        if (renderer instanceof Function && !(renderer.prototype instanceof TableCellRendererBase)) {
            return renderer();
        }
        return renderer;
    }

    public static getGenerator(columnDefine: ColumnDefine, property: string): Function {
        return columnDefine.cell && columnDefine.cell[property] instanceof Function ? columnDefine.cell[property] : null;
    }
}<commit_msg>add table async renderer<commit_after>import {
    ColumnDefine, TableCellSetting, TableHeadSetting, TableSyncRenderer
} from "./table-typings";
import {SortAs, SortOrder} from "../../core/data/component-data";
import {CommonUtils} from "../../core/utils/common-utils";
import {TableCellRendererBase} from "./table-renderer";

export class TableUtils {
    public static updateHeaderSettings(columnDefine: ColumnDefine, settings: TableHeadSetting): TableHeadSetting {
        if (!settings) {
            settings = {
                cellData: null, width: null, visible: true, renderer: null, clazz: '', field: '',
                sortable: false, sortAs: SortAs.string, defaultSortOrder: SortOrder.default
            };
        }
        settings.width = columnDefine.width;
        settings.field = <string>columnDefine.target;
        let headerDef = columnDefine.header;
        if (headerDef) {
            settings.cellData = CommonUtils.isDefined(headerDef.text) ? headerDef.text : settings.cellData;
            settings.renderer = TableUtils.getRenderer(headerDef.renderer);
            settings.clazz = headerDef.clazz;
            settings.sortable = headerDef.sortable;
            settings.sortAs = CommonUtils.isDefined(headerDef.sortAs) ? headerDef.sortAs : settings.sortAs;
            settings.defaultSortOrder = CommonUtils.isDefined(headerDef.sortAs) ?
                headerDef.defaultSortOrder : settings.defaultSortOrder;
        }
        return settings;
    }

    public static updateCellSettings(columnDefine: ColumnDefine, settings: TableCellSetting): TableCellSetting {
        if (!settings) {
            settings = {
                cellData: '', width: null, visible: true, renderer: null, clazz: '', rowSpan: 1,
                editable: false, editorRenderer: null, group: null, field: null, tooltip: null
            }
        }
        settings.width = columnDefine.width;
        settings.group = columnDefine.group;
        settings.field = <string>columnDefine.target;
        let cellDef = columnDefine.cell;
        if (cellDef) {
            settings.renderer = TableUtils.getRenderer(cellDef.renderer);
            settings.clazz = cellDef.clazz;
            settings.editable = cellDef.editable;
            settings.editorRenderer = TableUtils.getRenderer(cellDef.editorRenderer);
            settings.tooltip = cellDef.tooltip;
        }
        return settings;
    }

    public static getRenderer(renderer): TableSyncRenderer {
        if (renderer instanceof Function && !(renderer.prototype instanceof TableCellRendererBase)) {
            try {
                return renderer();
            } catch (e) {
                return undefined;
            }
        }
        return renderer;
    }

    public static getGenerator(columnDefine: ColumnDefine, property: string): Function {
        return columnDefine.cell && columnDefine.cell[property] instanceof Function ? columnDefine.cell[property] : null;
    }
}
{'fraction_non_alphanumeric': 0.09953504391251937, 'fraction_numerical': 0.00034441191665231615, 'mean_word_length': 2.5896168108776267, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4999905', 'n_tokens_mistral': 1503, 'n_tokens_neox': 1469, 'n_words': 328}