@illinois-grad/grad-vue 2.0.2 → 2.1.1

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.
@@ -1,6 +1,7 @@
1
1
  import { TableColumn, TableRow } from "./table/TableColumn.ts";
2
2
  import { VNode } from "vue";
3
3
  import { UseFilteringReturn } from "../compose/useFiltering.ts";
4
+ import { CellChangePayload, UseTableChangesReturn } from "../compose/useTableChanges.ts";
4
5
  export interface BulkAction {
5
6
  /**
6
7
  * Action identifier
@@ -35,6 +36,11 @@ declare const __VLS_export: <T extends TableRow, C extends TableColumn<T>>(__VLS
35
36
  */
36
37
  bulkSelectionEnabled?: boolean;
37
38
  bulkActions?: BulkAction[];
39
+ /**
40
+ * Optional change tracker for editable tables
41
+ * Pass a composable from useTableChanges() to track user edits
42
+ */
43
+ changeTracker?: UseTableChangesReturn<T>;
38
44
  } & {
39
45
  sortField?: keyof T;
40
46
  sortOrder?: 1 | -1;
@@ -42,6 +48,7 @@ declare const __VLS_export: <T extends TableRow, C extends TableColumn<T>>(__VLS
42
48
  selectedRows?: string[];
43
49
  }) & {
44
50
  "onRow-click"?: ((link: string) => any) | undefined;
51
+ "onCell-change"?: ((payload: CellChangePayload<T>) => any) | undefined;
45
52
  "onUpdate:sortField"?: ((value: keyof T | undefined) => any) | undefined;
46
53
  "onUpdate:sortOrder"?: ((value: 1 | -1 | undefined) => any) | undefined;
47
54
  "onUpdate:filter"?: ((value: Partial<Record<keyof T, any>>) => any) | undefined;
@@ -58,6 +65,7 @@ declare const __VLS_export: <T extends TableRow, C extends TableColumn<T>>(__VLS
58
65
  emit: {
59
66
  (e: "row-click", link: string): void;
60
67
  (e: "bulk-action", actionId: string, selectedKeys: string[]): void;
68
+ (e: "cell-change", payload: CellChangePayload<T>): void;
61
69
  } & (((event: "update:sortField", value: keyof T | undefined) => void) & ((event: "update:sortOrder", value: 1 | -1 | undefined) => void) & ((event: "update:filter", value: Partial<Record<keyof T, any>>) => void) & ((event: "update:selectedRows", value: string[]) => void));
62
70
  }>) => import("vue").VNode & {
63
71
  __ctx?: Awaited<typeof __VLS_setup>;
@@ -0,0 +1,41 @@
1
+ interface Props {
2
+ /**
3
+ * Title for the popover.
4
+ */
5
+ title?: string;
6
+ /**
7
+ * Label for year select.
8
+ */
9
+ yearLabel?: string;
10
+ /**
11
+ * Label for period select.
12
+ */
13
+ periodLabel?: string;
14
+ termYears?: string[];
15
+ termNames?: string[];
16
+ }
17
+ type __VLS_Props = Props;
18
+ type __VLS_ModelProps = {
19
+ modelValue?: {
20
+ year: string;
21
+ name: string;
22
+ };
23
+ };
24
+ type __VLS_PublicProps = __VLS_Props & __VLS_ModelProps;
25
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_PublicProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
26
+ "update:modelValue": (value: {
27
+ year: string;
28
+ name: string;
29
+ }) => any;
30
+ }, string, import("vue").PublicProps, Readonly<__VLS_PublicProps> & Readonly<{
31
+ "onUpdate:modelValue"?: ((value: {
32
+ year: string;
33
+ name: string;
34
+ }) => any) | undefined;
35
+ }>, {
36
+ title: string;
37
+ termYears: string[];
38
+ termNames: string[];
39
+ }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
40
+ declare const _default: typeof __VLS_export;
41
+ export default _default;
@@ -1,5 +1,6 @@
1
1
  import { type VNode } from "vue";
2
2
  import { TableColumn, TableRow } from "./TableColumn.ts";
3
+ import { UseTableChangesReturn } from "../../compose/useTableChanges.ts";
3
4
  declare const __VLS_export: <T extends TableRow, C extends TableColumn<T>>(__VLS_props: NonNullable<Awaited<typeof __VLS_setup>>["props"], __VLS_ctx?: __VLS_PrettifyLocal<Pick<NonNullable<Awaited<typeof __VLS_setup>>, "attrs" | "emit" | "slots">>, __VLS_exposed?: NonNullable<Awaited<typeof __VLS_setup>>["expose"], __VLS_setup?: Promise<{
4
5
  props: import("vue").PublicProps & __VLS_PrettifyLocal<{
5
6
  data: T[];
@@ -11,9 +12,16 @@ declare const __VLS_export: <T extends TableRow, C extends TableColumn<T>>(__VLS
11
12
  startIndex: number;
12
13
  bulkSelectionEnabled?: boolean;
13
14
  selectedRows?: string[];
15
+ tableId: string;
16
+ changeTracker?: UseTableChangesReturn<T>;
14
17
  } & {
15
- "onToggle-row"?: ((rowKey: string, shiftKey: boolean) => any) | undefined;
16
18
  "onRow-click"?: ((link: string) => any) | undefined;
19
+ "onCell-change"?: ((payload: {
20
+ row: T;
21
+ column: C;
22
+ value: any;
23
+ }) => any) | undefined;
24
+ "onToggle-row"?: ((rowKey: string, shiftKey: boolean) => any) | undefined;
17
25
  }> & (typeof globalThis extends {
18
26
  __VLS_PROPS_FALLBACK: infer P;
19
27
  } ? P : {});
@@ -23,6 +31,11 @@ declare const __VLS_export: <T extends TableRow, C extends TableColumn<T>>(__VLS
23
31
  emit: {
24
32
  (e: "row-click", link: string): void;
25
33
  (e: "toggle-row", rowKey: string, shiftKey: boolean): void;
34
+ (e: "cell-change", payload: {
35
+ row: T;
36
+ column: C;
37
+ value: any;
38
+ }): void;
26
39
  };
27
40
  }>) => import("vue").VNode & {
28
41
  __ctx?: Awaited<typeof __VLS_setup>;
@@ -21,14 +21,55 @@ export interface ToggleColumnFilter {
21
21
  label: string;
22
22
  description?: string;
23
23
  }
24
+ export interface EditableColumnConfig {
25
+ /**
26
+ * Type of editable control. Defaults to "input".
27
+ */
28
+ type?: "input" | "select";
29
+ /**
30
+ * Attributes to apply to the input element (type, pattern, step, min, max, etc.)
31
+ * Only applies when type is "input" or undefined.
32
+ */
33
+ inputAttributes?: Record<string, any>;
34
+ /**
35
+ * Options for select dropdown. Required when type is "select".
36
+ */
37
+ options?: Array<{
38
+ label: string;
39
+ value: any;
40
+ }>;
41
+ /**
42
+ * Text to display before the input (e.g., "$" for currency)
43
+ */
44
+ prefix?: string;
45
+ /**
46
+ * Text to display after the input (e.g., "kg" for weight)
47
+ */
48
+ suffix?: string;
49
+ /**
50
+ * Key of the column to use as the identifying label for the input's aria-labelledby.
51
+ * If not provided, the input will only be labeled by its column header.
52
+ */
53
+ labelKey?: string;
54
+ }
24
55
  export interface TableColumn<T extends TableRow, K = keyof T> {
25
56
  key: K;
26
57
  label: string;
27
58
  sortable?: boolean;
28
59
  filter?: TableColumnFilter;
60
+ /**
61
+ * Custom render function for the column data.
62
+ * Cannot be used with `editable`.
63
+ */
29
64
  display?: (row: T) => string | VNode;
30
65
  tdClass?: string | ((row: T) => string);
31
66
  trClass?: string | ((row: T) => string);
67
+ /**
68
+ * Configuration for editable columns.
69
+ * When set, the column will render as an input element.
70
+ * Cannot be used with `display`.
71
+ */
72
+ editable?: EditableColumnConfig;
32
73
  }
33
74
  export interface TableRow extends Record<string, any> {
34
75
  key: string;
@@ -0,0 +1,44 @@
1
+ interface Props {
2
+ /**
3
+ * List of possible term years. Defaults to ["2026"].
4
+ */
5
+ termYears?: string[];
6
+ /**
7
+ * List of possible term names. Defaults to ["Spring", "Summer", "Fall"].
8
+ */
9
+ termNames?: string[];
10
+ /**
11
+ * Label for year select. Defaults to "Select Year".
12
+ */
13
+ yearLabel?: string;
14
+ /**
15
+ * Label for period select. Defaults to "Term".
16
+ */
17
+ periodLabel?: string;
18
+ }
19
+ type __VLS_Props = Props;
20
+ type __VLS_ModelProps = {
21
+ modelValue?: {
22
+ year: string;
23
+ name: string;
24
+ };
25
+ };
26
+ type __VLS_PublicProps = __VLS_Props & __VLS_ModelProps;
27
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_PublicProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
28
+ "update:modelValue": (value: {
29
+ year: string;
30
+ name: string;
31
+ }) => any;
32
+ }, string, import("vue").PublicProps, Readonly<__VLS_PublicProps> & Readonly<{
33
+ "onUpdate:modelValue"?: ((value: {
34
+ year: string;
35
+ name: string;
36
+ }) => any) | undefined;
37
+ }>, {
38
+ termYears: string[];
39
+ termNames: string[];
40
+ yearLabel: string;
41
+ periodLabel: string;
42
+ }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
43
+ declare const _default: typeof __VLS_export;
44
+ export default _default;
@@ -0,0 +1,96 @@
1
+ import { TableColumn, TableRow } from "../components/table/TableColumn.ts";
2
+ /**
3
+ * Represents a single cell change in the table
4
+ */
5
+ export interface CellChange<T = any> {
6
+ rowKey: string;
7
+ columnKey: string;
8
+ previousValue: T;
9
+ newValue: T;
10
+ }
11
+ /**
12
+ * Payload for the `trackChange` function
13
+ */
14
+ export interface CellChangePayload<T extends TableRow = TableRow> {
15
+ row: T;
16
+ column: TableColumn<T>;
17
+ value: any;
18
+ previousValue: any;
19
+ }
20
+ /**
21
+ * Map of changes organized by row key and column key
22
+ */
23
+ export type ChangeMap = Map<string, Map<string, CellChange>>;
24
+ /**
25
+ * Return type for the useTableChanges composable
26
+ */
27
+ export interface UseTableChangesReturn<T extends Record<string, any>> {
28
+ /**
29
+ * Track a change to a cell
30
+ */
31
+ trackChange: (payload: CellChangePayload<any>) => void;
32
+ /**
33
+ * Get all changes as an array
34
+ */
35
+ getChanges: () => CellChange[];
36
+ /**
37
+ * Get changes organized by row
38
+ */
39
+ getChangesByRow: () => Map<string, Partial<T>>;
40
+ /**
41
+ * Check if there are any changes
42
+ */
43
+ hasChanges: () => boolean;
44
+ /**
45
+ * Check if a specific cell has changes
46
+ */
47
+ hasChange: (rowKey: string, columnKey: keyof T) => boolean;
48
+ /**
49
+ * Get the changed value for a specific cell, or undefined if no change
50
+ */
51
+ getChange: (rowKey: string, columnKey: keyof T) => any | undefined;
52
+ /**
53
+ * Clear all tracked changes
54
+ */
55
+ clearChanges: () => void;
56
+ /**
57
+ * Clear changes for a specific row
58
+ */
59
+ clearRowChanges: (rowKey: string) => void;
60
+ /**
61
+ * Apply tracked changes to a new dataset (for merging with updated data)
62
+ */
63
+ applyChangesToData: (data: T[]) => T[];
64
+ /**
65
+ * Get count of changed cells
66
+ */
67
+ changeCount: () => number;
68
+ }
69
+ /**
70
+ * Composable for tracking changes to table data
71
+ *
72
+ * This composable helps manage user edits to table data by:
73
+ * - Tracking which cells have been modified
74
+ * - Storing both old and new values
75
+ * - Providing methods to retrieve just the changes (not full data)
76
+ * - Allowing changes to be applied to updated data for real-time syncing
77
+ *
78
+ * @example
79
+ * ```typescript
80
+ * const changes = useTableChanges<ProductRow>();
81
+ *
82
+ * // Track a change when user edits a cell
83
+ * function handleCellChange(row, column, newValue) {
84
+ * changes.trackChange(row.key, column.key, newValue, row[column.key]);
85
+ * }
86
+ *
87
+ * // Get all changes to submit
88
+ * const changedData = changes.getChanges();
89
+ * await api.updateProducts(changedData);
90
+ *
91
+ * // Apply user changes to fresh data from server
92
+ * const freshData = await api.getProducts();
93
+ * const mergedData = changes.applyChangesToData(freshData);
94
+ * ```
95
+ */
96
+ export declare function useTableChanges<T extends Record<string, any> = Record<string, any>>(): UseTableChangesReturn<T>;