@cobre-npm/ds-v3 0.139.2 → 0.141.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,52 @@ 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;
54
+ /**
55
+ * Enable pinning columns to the left or right edge of the table, staying visible during
56
+ * horizontal scroll. Requires the table to also control columnPinning state
57
+ * (state: { columnPinning } + onColumnPinningChange) for the pin to persist — this prop only
58
+ * toggles the sticky rendering/affordances.
59
+ */
60
+ enableColumnPinning?: boolean;
61
+ /**
62
+ * Labels for the pin/unpin actions in each column's kebab menu (shown when
63
+ * enableColumnPinning is on). Defaults to Spanish, matching this component's other
64
+ * built-in text (e.g. emptyStateProps) — pass overrides to localize.
65
+ */
66
+ pinMenuLabels?: {
67
+ pinLeft?: string;
68
+ pinRight?: string;
69
+ unpin?: string;
70
+ };
45
71
  }
46
72
  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;
73
+ props: __VLS_PrettifyLocal<Pick<Partial<{}> & Omit<{
74
+ readonly "onColumn-reorder"?: ((payload: {
75
+ columnId: string;
76
+ fromIndex: number;
77
+ toIndex: number;
78
+ columnOrder: string[];
79
+ method: ColumnReorderMethod;
80
+ }) => any) | undefined;
81
+ readonly "onColumn-reorder-cancel"?: ((payload: {
82
+ columnId: string;
83
+ method: ColumnReorderMethod;
84
+ }) => any) | undefined;
85
+ readonly "onColumn-pin"?: ((payload: {
86
+ columnId: string;
87
+ side: "left" | "right";
88
+ }) => any) | undefined;
89
+ readonly "onColumn-unpin"?: ((payload: {
90
+ columnId: string;
91
+ }) => any) | undefined;
92
+ } & import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, never>, "onColumn-reorder" | "onColumn-reorder-cancel" | "onColumn-pin" | "onColumn-unpin"> & CobreTableProps<T> & Partial<{}>> & import("vue").PublicProps;
48
93
  expose(exposed: import("vue").ShallowUnwrapRef<{}>): void;
49
94
  attrs: any;
50
95
  slots: {
@@ -55,7 +100,21 @@ declare const _default: <T>(__VLS_props: NonNullable<Awaited<typeof __VLS_setup>
55
100
  } & {
56
101
  'empty-state'?: (props: {}) => any;
57
102
  };
58
- emit: {};
103
+ emit: ((evt: "column-reorder", payload: {
104
+ columnId: string;
105
+ fromIndex: number;
106
+ toIndex: number;
107
+ columnOrder: string[];
108
+ method: ColumnReorderMethod;
109
+ }) => void) & ((evt: "column-reorder-cancel", payload: {
110
+ columnId: string;
111
+ method: ColumnReorderMethod;
112
+ }) => void) & ((evt: "column-pin", payload: {
113
+ columnId: string;
114
+ side: "left" | "right";
115
+ }) => void) & ((evt: "column-unpin", payload: {
116
+ columnId: string;
117
+ }) => void);
59
118
  }>) => import("vue").VNode & {
60
119
  __ctx?: Awaited<typeof __VLS_setup>;
61
120
  };
@@ -0,0 +1,27 @@
1
+ import type { ComputedRef, CSSProperties, Ref } from 'vue';
2
+ import type { Column, Table as TanStackTable, ColumnPinningPosition } from '@tanstack/vue-table';
3
+ export interface ColumnPinningEmits {
4
+ (event: 'column-pin', payload: {
5
+ columnId: string;
6
+ side: 'left' | 'right';
7
+ }): void;
8
+ (event: 'column-unpin', payload: {
9
+ columnId: string;
10
+ }): void;
11
+ }
12
+ /**
13
+ * Column pinning for CobreTable, wired to a TanStack table instance. Requires the table to
14
+ * control columnPinning state (state: { columnPinning } + onColumnPinningChange) for pin
15
+ * changes to persist — this composable only mutates table.setColumnPinning(); persistence
16
+ * is the consumer's responsibility (e.g. useDataTable).
17
+ *
18
+ * Sticky offsets come straight from TanStack's own column.getStart/getAfter — no hand-rolled
19
+ * offset math needed. The one thing this composable owns is repartitioning `orderedColumnIds`
20
+ * on pin/unpin so pinned columns render at the table edges.
21
+ */
22
+ export declare function useColumnPinning<T>(table: TanStackTable<T>, isEnabled: ComputedRef<boolean>, orderedColumnIds: Ref<string[]>, emit: ColumnPinningEmits): {
23
+ getIsPinned: (columnId: string) => ColumnPinningPosition;
24
+ isColumnIdPinned: (columnId: string) => boolean;
25
+ pinColumn: (columnId: string, side: ColumnPinningPosition) => void;
26
+ pinnedStyleFor: (column: Column<T>, baseLeftOffsetPx?: number) => CSSProperties;
27
+ };
@@ -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>, isPinningEnabled: 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.141.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",