summaryrefslogtreecommitdiff
path: root/packages/frontend/src/components/grid/row.ts
blob: 42da22193f823d78e02fc478acdefc8fe8e6624e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
 * SPDX-FileCopyrightText: syuilo and misskey-project
 * SPDX-License-Identifier: AGPL-3.0-only
 */

import type { AdditionalStyle } from '@/components/grid/grid.js';
import type { GridCell } from '@/components/grid/cell.js';
import type { GridColumn } from '@/components/grid/column.js';
import type { MenuItem } from '@/types/menu.js';
import type { GridContext } from '@/components/grid/grid-event.js';

export const defaultGridRowSetting: Required<GridRowSetting> = {
	showNumber: true,
	selectable: true,
	minimumDefinitionCount: 100,
	styleRules: [],
	contextMenuFactory: () => [],
	events: {},
};

export type GridRowStyleRuleConditionParams = {
	row: GridRow,
	targetCols: GridColumn[],
	cells: GridCell[]
};

export type GridRowStyleRule = {
	condition: (params: GridRowStyleRuleConditionParams) => boolean;
	applyStyle: AdditionalStyle;
};

export type GridRowContextMenuFactory = (row: GridRow, context: GridContext) => MenuItem[];

export type GridRowSetting = {
	showNumber?: boolean;
	selectable?: boolean;
	minimumDefinitionCount?: number;
	styleRules?: GridRowStyleRule[];
	contextMenuFactory?: GridRowContextMenuFactory;
	events?: {
		delete?: (rows: GridRow[]) => void;
	}
};

export type GridRow = {
	index: number;
	ranged: boolean;
	using: boolean;
	setting: GridRowSetting;
	additionalStyles: AdditionalStyle[];
};

export function createRow(index: number, using: boolean, setting: GridRowSetting): GridRow {
	return {
		index,
		ranged: false,
		using: using,
		setting,
		additionalStyles: [],
	};
}

export function resetRow(row: GridRow): void {
	row.ranged = false;
	row.using = false;
	row.additionalStyles = [];
}