@cobre-npm/ds-v3 0.139.2 → 0.140.0

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,5 +1,6 @@
1
1
  import type { Table as TanStackTable, ColumnDef } from '@tanstack/vue-table';
2
2
  import type { RowAction } from '../../atoms/CobreRowActions/interfaces/CobreRowActions.interface';
3
+ import { type ColumnReorderMethod } from './useColumnReorder';
3
4
  /**
4
5
  * Configuration for the empty state display
5
6
  */
@@ -22,6 +23,7 @@ export interface EmptyStateProps {
22
23
  * - Loading skeleton state
23
24
  * - Custom empty state display
24
25
  * - Slot-based custom cell rendering
26
+ * - Column reordering via drag-and-drop or keyboard (opt-in, see enableColumnReorder)
25
27
  */
26
28
  export interface CobreTableProps<T> {
27
29
  /** TanStack Vue Table instance (created with useDataTable or useVueTable) */
@@ -42,9 +44,28 @@ export interface CobreTableProps<T> {
42
44
  onRowClick?: (row: T) => void;
43
45
  /** Configuration for empty state display (title, description, icon) */
44
46
  emptyStateProps?: EmptyStateProps;
47
+ /**
48
+ * Enable drag-and-drop and keyboard column reordering. Requires the table to also control
49
+ * columnOrder state (state: { columnOrder } + onColumnOrderChange) for the new order to
50
+ * take effect and persist — this prop only toggles the UI affordances (draggable headers,
51
+ * focus, keyboard handling).
52
+ */
53
+ enableColumnReorder?: boolean;
45
54
  }
46
55
  declare const _default: <T>(__VLS_props: NonNullable<Awaited<typeof __VLS_setup>>["props"], __VLS_ctx?: __VLS_PrettifyLocal<Pick<NonNullable<Awaited<typeof __VLS_setup>>, "attrs" | "emit" | "slots">>, __VLS_expose?: NonNullable<Awaited<typeof __VLS_setup>>["expose"], __VLS_setup?: Promise<{
47
- props: __VLS_PrettifyLocal<Pick<Partial<{}> & Omit<{} & import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, never>, never> & CobreTableProps<T> & Partial<{}>> & import("vue").PublicProps;
56
+ props: __VLS_PrettifyLocal<Pick<Partial<{}> & Omit<{
57
+ readonly "onColumn-reorder"?: ((payload: {
58
+ columnId: string;
59
+ fromIndex: number;
60
+ toIndex: number;
61
+ columnOrder: string[];
62
+ method: ColumnReorderMethod;
63
+ }) => any) | undefined;
64
+ readonly "onColumn-reorder-cancel"?: ((payload: {
65
+ columnId: string;
66
+ method: ColumnReorderMethod;
67
+ }) => any) | undefined;
68
+ } & import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, never>, "onColumn-reorder" | "onColumn-reorder-cancel"> & CobreTableProps<T> & Partial<{}>> & import("vue").PublicProps;
48
69
  expose(exposed: import("vue").ShallowUnwrapRef<{}>): void;
49
70
  attrs: any;
50
71
  slots: {
@@ -55,7 +76,16 @@ declare const _default: <T>(__VLS_props: NonNullable<Awaited<typeof __VLS_setup>
55
76
  } & {
56
77
  'empty-state'?: (props: {}) => any;
57
78
  };
58
- emit: {};
79
+ emit: ((evt: "column-reorder", payload: {
80
+ columnId: string;
81
+ fromIndex: number;
82
+ toIndex: number;
83
+ columnOrder: string[];
84
+ method: ColumnReorderMethod;
85
+ }) => void) & ((evt: "column-reorder-cancel", payload: {
86
+ columnId: string;
87
+ method: ColumnReorderMethod;
88
+ }) => void);
59
89
  }>) => import("vue").VNode & {
60
90
  __ctx?: Awaited<typeof __VLS_setup>;
61
91
  };
@@ -0,0 +1,32 @@
1
+ import { type ComputedRef, type ComponentPublicInstance } from 'vue';
2
+ import type { Table as TanStackTable, Header, HeaderGroup } from '@tanstack/vue-table';
3
+ /** Method used to trigger a column reorder */
4
+ export type ColumnReorderMethod = 'pointer' | 'keyboard';
5
+ export interface ColumnReorderEmits {
6
+ (event: 'column-reorder', payload: {
7
+ columnId: string;
8
+ fromIndex: number;
9
+ toIndex: number;
10
+ columnOrder: string[];
11
+ method: ColumnReorderMethod;
12
+ }): void;
13
+ (event: 'column-reorder-cancel', payload: {
14
+ columnId: string;
15
+ method: ColumnReorderMethod;
16
+ }): void;
17
+ }
18
+ /**
19
+ * Drag-and-drop and keyboard column reordering for CobreTable, wired to a TanStack table
20
+ * instance. Requires the table to control columnOrder state (state: { columnOrder } +
21
+ * onColumnOrderChange) for the new order to persist — this composable only mutates
22
+ * table.setColumnOrder(); persistence is the consumer's responsibility (e.g. useDataTable).
23
+ */
24
+ export declare function useColumnReorder<T>(table: TanStackTable<T>, isEnabled: ComputedRef<boolean>, emit: ColumnReorderEmits): {
25
+ orderedColumnIds: import("vue").Ref<string[], string[]>;
26
+ setHeaderRowEl: (el: Element | ComponentPublicInstance | null) => void;
27
+ setHeaderElRef: (columnId: string, el: Element | ComponentPublicInstance | null) => void;
28
+ isColumnIdDraggable: (columnId: string) => boolean;
29
+ getHeadersForColumn: (headerGroup: HeaderGroup<T>, columnId: string) => Header<T, unknown>[];
30
+ grabbedColumnId: import("vue").Ref<string | null, string | null>;
31
+ onHeaderKeydown: (event: KeyboardEvent, columnId: string) => void;
32
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cobre-npm/ds-v3",
3
- "version": "0.139.2",
3
+ "version": "0.140.0",
4
4
  "type": "module",
5
5
  "packageManager": "pnpm@11.0.4",
6
6
  "engines": {
@@ -28,6 +28,7 @@
28
28
  "test": "test-storybook"
29
29
  },
30
30
  "dependencies": {
31
+ "@formkit/drag-and-drop": "^0.6.1",
31
32
  "@popperjs/core": "^2.11.8",
32
33
  "@tanstack/vue-table": "^8.21.3",
33
34
  "@vueuse/components": "^10.11.0",