-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathcanvas-schema-vlatest.model.ts
More file actions
86 lines (76 loc) · 2.07 KB
/
canvas-schema-vlatest.model.ts
File metadata and controls
86 lines (76 loc) · 2.07 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import { Coords, FieldType, GUID, Size } from '@/core/model';
export interface TableVm {
id: string;
fields: FieldVm[];
tableName: string;
x: number; // Canvas X Position
y: number; // Canvas Y Position
}
export interface FieldVm {
id: GUID;
PK: boolean;
name: string;
type: FieldType;
children?: FieldVm[];
isCollapsed?: boolean;
isArray?: boolean;
isNN?: boolean;
}
export type RelationType = '1:1' | '1:M' | 'M:1';
export interface RelationVm {
id: GUID;
fromTableId: string;
toTableId: string;
fromFieldId: string;
toFieldId: string;
type: RelationType;
}
export type Versions = '0.1';
export interface DatabaseSchemaVm {
version: Versions;
tables: TableVm[];
relations: RelationVm[];
selectedElementId: GUID | null;
isPristine?: boolean;
}
export const createDefaultDatabaseSchemaVm = (): DatabaseSchemaVm => ({
version: '0.1',
tables: [],
relations: [],
selectedElementId: null,
isPristine: true,
});
export interface UpdatePositionItemInfo {
id: string;
position: Coords;
totalHeight: number;
canvasSize: Size;
}
export type UpdatePositionFn = (
itemInfo: UpdatePositionItemInfo,
isDragFinished: boolean
) => void;
export interface CanvasSchemaContextVm {
canvasSchema: DatabaseSchemaVm;
setCanvasSchema: (schema: DatabaseSchemaVm) => void;
loadSchema: (schema: DatabaseSchemaVm) => void;
createEmptySchema: () => void;
updateTablePosition: UpdatePositionFn;
doFieldToggleCollapse: (tableId: string, fieldId: GUID) => void;
updateFullTable: (table: TableVm) => void;
addTable: (table: TableVm) => void;
addRelation: (relation: RelationVm) => void;
doSelectElement: (id: GUID | null) => void;
canUndo: () => boolean;
canRedo: () => boolean;
doUndo: () => void;
doRedo: () => void;
updateFullRelation: (relation: RelationVm) => void;
deleteSelectedItem: (selectedElementId: GUID) => void;
switchIsPristine: (isPristine: boolean) => void;
duplicateSelectedTable: () => void;
copySelectedTable: () => void;
pasteTable: () => void;
hasClipboardContent: boolean;
clearClipboard: () => void;
}