@illinois-grad/grad-vue 2.3.2 → 2.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -48,7 +48,7 @@ declare const __VLS_export: <T extends TableRow, C extends TableColumn<T>>(__VLS
48
48
  selectedRows?: string[];
49
49
  }) & {
50
50
  "onRow-click"?: ((link: string) => any) | undefined;
51
- "onCell-change"?: ((payload: CellChangePayload<T>) => any) | undefined;
51
+ "onCell-change"?: ((payload: CellChangePayload<T, Extract<keyof T, string>>) => any) | undefined;
52
52
  "onUpdate:sortField"?: ((value: keyof T | undefined) => any) | undefined;
53
53
  "onUpdate:sortOrder"?: ((value: 1 | -1 | undefined) => any) | undefined;
54
54
  "onUpdate:filter"?: ((value: Partial<Record<keyof T, any>>) => any) | undefined;
@@ -52,7 +52,8 @@ export interface EditableColumnConfig {
52
52
  */
53
53
  labelKey?: string;
54
54
  }
55
- export interface TableColumn<T extends TableRow, K = keyof T> {
55
+ type ColumnKey<T> = Extract<keyof T, string>;
56
+ export interface TableColumn<T extends TableRow, K extends ColumnKey<T> = ColumnKey<T>> {
56
57
  key: K;
57
58
  label: string;
58
59
  sortable?: boolean;
@@ -74,3 +75,4 @@ export interface TableColumn<T extends TableRow, K = keyof T> {
74
75
  export interface TableRow extends Record<string, any> {
75
76
  key: string;
76
77
  }
78
+ export {};
@@ -1,35 +1,46 @@
1
+ import { ComputedRef } from "vue";
1
2
  import { TableColumn, TableRow } from "../components/table/TableColumn.ts";
2
3
  import { EventHookOn } from "@vueuse/core";
4
+ export type ColumnKey<R extends TableRow> = Extract<keyof R, string>;
3
5
  /**
4
6
  * Represents a single cell change in the table
5
7
  */
6
- export interface CellChange<T = any, K extends TableRow = TableRow> {
8
+ export interface CellChange<R extends TableRow = TableRow, K extends ColumnKey<R> = ColumnKey<R>> {
7
9
  rowKey: string;
8
- columnKey: keyof K;
10
+ columnKey: K;
11
+ row: R;
9
12
  /**
10
13
  * Represents the original value before user changes.
11
14
  */
12
- previousValue: T;
15
+ previousValue: R[K];
13
16
  /**
14
17
  * New value from the change. This will be null in events
15
18
  * if the new value is the same as the original.
16
19
  */
17
- newValue: T;
20
+ newValue: R[K];
21
+ error?: string;
22
+ }
23
+ export interface CellChangeEvent<R extends TableRow = TableRow, K extends ColumnKey<R> = ColumnKey<R>> {
24
+ rowKey: string;
25
+ columnKey: K;
26
+ row: R;
27
+ previousValue: R[K];
28
+ newValue: R[K] | null;
18
29
  error?: string;
19
30
  }
20
31
  /**
21
32
  * Payload for the `trackChange` function
22
33
  */
23
- export interface CellChangePayload<T extends TableRow = TableRow> {
34
+ export interface CellChangePayload<T extends TableRow = TableRow, K extends ColumnKey<T> = ColumnKey<T>> {
24
35
  row: T;
25
- column: TableColumn<T>;
26
- value: any;
27
- previousValue: any;
36
+ column: TableColumn<T, K>;
37
+ value: T[K];
38
+ previousValue: T[K];
28
39
  }
29
40
  /**
30
41
  * Map of changes organized by row key and column key
31
42
  */
32
- export type ChangeMap = Map<string, Map<string, CellChange>>;
43
+ export type ChangeMap<T extends TableRow> = Map<string, Map<ColumnKey<T>, CellChange<T>>>;
33
44
  /**
34
45
  * Return type for the useTableChanges composable
35
46
  */
@@ -37,27 +48,27 @@ export interface UseTableChangesReturn<T extends TableRow> {
37
48
  /**
38
49
  * Track a change to a cell
39
50
  */
40
- trackChange: (payload: CellChangePayload<any>) => void;
51
+ trackChange: <K extends ColumnKey<T>>(payload: CellChangePayload<T, K>) => void;
41
52
  /**
42
- * Get all changes as an array
53
+ * Reactive array of all current changes
43
54
  */
44
- getChanges: () => CellChange[];
55
+ changes: ComputedRef<CellChange<T>[]>;
45
56
  /**
46
57
  * Get changes organized by row
47
58
  */
48
59
  getChangesByRow: () => Map<string, Partial<T>>;
49
60
  /**
50
- * Check if there are any changes
61
+ * Reactive flag indicating whether there are any changes
51
62
  */
52
- hasChanges: () => boolean;
63
+ hasChanges: ComputedRef<boolean>;
53
64
  /**
54
65
  * Check if a specific cell has changes
55
66
  */
56
- hasChange: (rowKey: string, columnKey: keyof T) => boolean;
67
+ hasChange: <K extends ColumnKey<T>>(rowKey: string, columnKey: K) => boolean;
57
68
  /**
58
69
  * Get the changed value for a specific cell, or undefined if no change
59
70
  */
60
- getChange: (rowKey: string, columnKey: keyof T) => any | undefined;
71
+ getChange: <K extends ColumnKey<T>>(rowKey: string, columnKey: K) => T[K] | undefined;
61
72
  /**
62
73
  * Clear all tracked changes
63
74
  */
@@ -71,31 +82,35 @@ export interface UseTableChangesReturn<T extends TableRow> {
71
82
  */
72
83
  applyChangesToData: (data: T[]) => T[];
73
84
  /**
74
- * Get count of changed cells
85
+ * Reactive count of changed cells
86
+ */
87
+ changeCount: ComputedRef<number>;
88
+ /**
89
+ * Reactive flag indicating whether any cell has an error
75
90
  */
76
- changeCount: () => number;
91
+ hasErrors: ComputedRef<boolean>;
77
92
  /**
78
93
  * Set an error message for a specific cell
79
94
  */
80
- setError: (rowKey: string, columnKey: keyof T, error: string) => void;
95
+ setError: <K extends ColumnKey<T>>(rowKey: string, columnKey: K, error: string) => void;
81
96
  /**
82
97
  * Clear the error for a specific cell
83
98
  */
84
- clearError: (rowKey: string, columnKey: keyof T) => void;
99
+ clearError: <K extends ColumnKey<T>>(rowKey: string, columnKey: K) => void;
85
100
  /**
86
101
  * Get the error message for a specific cell, or undefined if no error
87
102
  */
88
- getError: (rowKey: string, columnKey: keyof T) => string | undefined;
103
+ getError: <K extends ColumnKey<T>>(rowKey: string, columnKey: K) => string | undefined;
89
104
  /**
90
105
  * Check if a specific cell has an error
91
106
  */
92
- hasError: (rowKey: string, columnKey: keyof T) => boolean;
107
+ hasError: <K extends ColumnKey<T>>(rowKey: string, columnKey: K) => boolean;
93
108
  /**
94
109
  * Event emitted when a cell changes.
95
110
  *
96
111
  * `newValue` will be null if the cell's value is the same as the original.
97
112
  */
98
- onChange: EventHookOn<CellChange<any, T>>;
113
+ onChange: EventHookOn<CellChangeEvent<T>>;
99
114
  }
100
115
  /**
101
116
  * Composable for tracking changes to table data
@@ -112,11 +127,16 @@ export interface UseTableChangesReturn<T extends TableRow> {
112
127
  *
113
128
  * // Track a change when user edits a cell
114
129
  * function handleCellChange(row, column, newValue) {
115
- * changes.trackChange(row.key, column.key, newValue, row[column.key]);
130
+ * changes.trackChange({
131
+ * row,
132
+ * column,
133
+ * value: newValue,
134
+ * previousValue: row[column.key],
135
+ * });
116
136
  * }
117
137
  *
118
138
  * // Get all changes to submit
119
- * const changedData = changes.getChanges();
139
+ * const changedData = changes.changes.value;
120
140
  * await api.updateProducts(changedData);
121
141
  *
122
142
  * // Apply user changes to fresh data from server