Skip to content

Commit

Permalink
chore: use better FormatterResultObject interface names
Browse files Browse the repository at this point in the history
  • Loading branch information
ghiscoding-SE authored and ghiscoding committed Nov 14, 2023
1 parent 9446740 commit a683ab9
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 21 deletions.
6 changes: 3 additions & 3 deletions src/models/column.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import type {
Editor,
EditorValidator,
Formatter,
FormatterHtmlResultObject,
FormatterResultObject,
FormatterResultWithHtml,
FormatterResultWithText,
GroupTotalsFormatter,
Grouping,
HeaderButtonsOrMenu
Expand All @@ -26,7 +26,7 @@ type Join<T extends any[], D extends string> =
F extends string ? string extends F ? string : `${F}${D}${Join<R, D>}` : never : string;
/* eslint-enable @typescript-eslint/indent */

export type FormatterOverrideCallback = (row: number, cell: number, val: any, columnDef: Column, item: any, grid: SlickGrid) => string | FormatterResultObject | FormatterHtmlResultObject;
export type FormatterOverrideCallback = (row: number, cell: number, val: any, columnDef: Column, item: any, grid: SlickGrid) => string | FormatterResultWithHtml | FormatterResultWithText;

export interface Column<TData = any> {
/** Defaults to false, should we always render the column? */
Expand Down
6 changes: 3 additions & 3 deletions src/models/excelCopyBufferOption.interface.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { CellRange, Column, FormatterHtmlResultObject, FormatterResultObject, } from './index';
import type { CellRange, Column, FormatterResultWithHtml, FormatterResultWithText } from './index';
import type { SlickEventData } from '../slick.core';

export interface ExcelCopyBufferOption<T = any> {
Expand All @@ -15,10 +15,10 @@ export interface ExcelCopyBufferOption<T = any> {
copiedCellStyleLayerKey?: string;

/** option to specify a custom column value extractor function */
dataItemColumnValueExtractor?: (item: any, columnDef: Column<T>) => string | FormatterResultObject | FormatterHtmlResultObject | null;
dataItemColumnValueExtractor?: (item: any, columnDef: Column<T>) => string | FormatterResultWithHtml | FormatterResultWithText | null;

/** option to specify a custom column value setter function */
dataItemColumnValueSetter?: (item: any, columnDef: Column<T>, value: any) => string | FormatterResultObject | FormatterHtmlResultObject | null;
dataItemColumnValueSetter?: (item: any, columnDef: Column<T>, value: any) => string | FormatterResultWithHtml | FormatterResultWithText | null;

/** option to specify a custom handler for paste actions */
clipboardCommandHandler?: (editCommand: any) => void;
Expand Down
4 changes: 2 additions & 2 deletions src/models/formatter.interface.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Column, FormatterHtmlResultObject, FormatterResultObject } from './index';
import type { Column, FormatterResultWithHtml, FormatterResultWithText } from './index';
import type { SlickGrid } from '../slick.grid';

export declare type Formatter<T = any> = (row: number, cell: number, value: any, columnDef: Column<T>, dataContext: T, grid: SlickGrid) => string | FormatterResultObject | FormatterHtmlResultObject | HTMLElement;
export declare type Formatter<T = any> = (row: number, cell: number, value: any, columnDef: Column<T>, dataContext: T, grid: SlickGrid) => string | HTMLElement | FormatterResultWithHtml | FormatterResultWithText;
10 changes: 6 additions & 4 deletions src/models/formatterResultObject.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@ export interface FormatterResultObject {
/** Optional CSS classes to remove from the cell div container. */
removeClasses?: string;

/** Text to be displayed in the cell, basically the formatter output. */
text: string | HTMLElement;

/** Optional tooltip text when hovering the cell div container. */
toolTip?: string;
}

export interface FormatterHtmlResultObject extends Omit<FormatterResultObject, 'text'> {
export interface FormatterResultWithText extends FormatterResultObject {
/** Text to be displayed in the cell, basically the formatter output. */
text: string | HTMLElement;
}

export interface FormatterResultWithHtml extends FormatterResultObject {
/** Text to be displayed in the cell, basically the formatter output. */
html: HTMLElement;
}
4 changes: 2 additions & 2 deletions src/plugins/slick.crossgridrowmovemanager.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SlickEvent as SlickEvent_, SlickEventData as SlickEventData_, SlickEventHandler as SlickEventHandler_, Utils as Utils_ } from '../slick.core';
import type { Column, DOMEvent, DragRowMove, FormatterResultObject, CrossGridRowMoveManagerOption, UsabilityOverrideFn, FormatterHtmlResultObject } from '../models/index';
import type { Column, DOMEvent, DragRowMove, CrossGridRowMoveManagerOption, FormatterResultWithText, UsabilityOverrideFn } from '../models/index';
import type { SlickGrid } from '../slick.grid';

// for (iife) load Slick methods from global Slick object, or use imports for (esm)
Expand Down Expand Up @@ -256,7 +256,7 @@ export class SlickCrossGridRowMoveManager {
};
}

protected moveIconFormatter(row: number, _cell: number, _val: any, _column: Column, dataContext: any, grid: SlickGrid): FormatterResultObject | FormatterHtmlResultObject | string {
protected moveIconFormatter(row: number, _cell: number, _val: any, _column: Column, dataContext: any, grid: SlickGrid): FormatterResultWithText | string {
if (!this.checkUsabilityOverride(row, dataContext, grid)) {
return '';
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/slick.customtooltip.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { CancellablePromiseWrapper, Column, CustomTooltipOption, DOMEvent, Formatter, FormatterHtmlResultObject, FormatterResultObject, GridOption } from '../models/index';
import type { CancellablePromiseWrapper, Column, CustomTooltipOption, DOMEvent, Formatter, FormatterResultWithHtml, FormatterResultWithText, GridOption } from '../models/index';
import { SlickEventHandler as SlickEventHandler_, Utils as Utils_ } from '../slick.core';
import type { SlickDataView } from '../slick.dataview';
import type { SlickGrid } from '../slick.grid';
Expand Down Expand Up @@ -430,7 +430,7 @@ export class SlickCustomTooltip {
protected parseFormatterAndSanitize(formatterOrText: Formatter | string | undefined, cell: { row: number; cell: number; }, value: any, columnDef: Column, item: unknown): string {
if (typeof formatterOrText === 'function') {
const tooltipResult = formatterOrText(cell.row, cell.cell, value, columnDef, item, this._grid);
let formatterText = (Object.prototype.toString.call(tooltipResult) !== '[object Object]' ? tooltipResult : (tooltipResult as FormatterHtmlResultObject).html || (tooltipResult as FormatterResultObject).text);
let formatterText = (Object.prototype.toString.call(tooltipResult) !== '[object Object]' ? tooltipResult : (tooltipResult as FormatterResultWithHtml).html || (tooltipResult as FormatterResultWithText).text);
if (formatterText instanceof HTMLElement) {
formatterText = formatterText.outerHTML;
}
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/slick.rowdetailview.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SlickEvent as SlickEvent_, SlickEventHandler as SlickEventHandler_, Utils as Utils_ } from '../slick.core';
import type { Column, DOMEvent, FormatterHtmlResultObject, FormatterResultObject, GridOption, OnAfterRowDetailToggleArgs, OnBeforeRowDetailToggleArgs, OnRowBackToViewportRangeArgs, OnRowDetailAsyncEndUpdateArgs, OnRowDetailAsyncResponseArgs, OnRowOutOfViewportRangeArgs, RowDetailViewOption, UsabilityOverrideFn } from '../models/index';
import type { Column, DOMEvent, FormatterResultWithHtml, FormatterResultWithText, GridOption, OnAfterRowDetailToggleArgs, OnBeforeRowDetailToggleArgs, OnRowBackToViewportRangeArgs, OnRowDetailAsyncEndUpdateArgs, OnRowDetailAsyncResponseArgs, OnRowOutOfViewportRangeArgs, RowDetailViewOption, UsabilityOverrideFn } from '../models/index';
import type { SlickDataView } from '../slick.dataview';
import type { SlickGrid } from '../slick.grid';

Expand Down Expand Up @@ -630,7 +630,7 @@ export class SlickRowDetailView {
}

/** The cell Formatter that shows the icon that will be used to toggle the Row Detail */
protected detailSelectionFormatter(row: number, _cell: number, _val: any, _column: Column, dataContext: any, grid: SlickGrid): FormatterResultObject | FormatterHtmlResultObject | string {
protected detailSelectionFormatter(row: number, _cell: number, _val: any, _column: Column, dataContext: any, grid: SlickGrid): FormatterResultWithHtml | FormatterResultWithText | string {
if (!this.checkExpandableOverride(row, dataContext, grid)) {
return '';
} else {
Expand Down
8 changes: 5 additions & 3 deletions src/plugins/slick.rowmovemanager.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SlickEvent as SlickEvent_, SlickEventData as SlickEventData_, SlickEventHandler as SlickEventHandler_, Utils as Utils_ } from '../slick.core';
import type { Column, DOMEvent, DragRowMove, FormatterHtmlResultObject, FormatterResultObject, RowMoveManagerOption, UsabilityOverrideFn } from '../models/index';
import type { Column, DOMEvent, DragRowMove, FormatterResultWithHtml, RowMoveManagerOption, UsabilityOverrideFn } from '../models/index';
import type { SlickGrid } from '../slick.grid';

// for (iife) load Slick methods from global Slick object, or use imports for (esm)
Expand Down Expand Up @@ -247,13 +247,15 @@ export class SlickRowMoveManager {
};
}

protected moveIconFormatter(row: number, _cell: number, _val: any, _column: Column, dataContext: any, grid: SlickGrid): FormatterResultObject | FormatterHtmlResultObject | string {
protected moveIconFormatter(row: number, _cell: number, _val: any, _column: Column, dataContext: any, grid: SlickGrid): FormatterResultWithHtml | string {
if (!this.checkUsabilityOverride(row, dataContext, grid)) {
return '';
} else {
const iconElm = document.createElement('div');
iconElm.className = this._options.cssClass || '';
return {
addClasses: `cell-reorder dnd ${this._options.containerCssClass || ''}`,
text: `<div class="${this._options.cssClass}"></div>`
html: iconElm
};
}
}
Expand Down

0 comments on commit a683ab9

Please sign in to comment.