@apexcura/ui-components 0.0.16-Beta1309 → 0.0.16-Beta1310

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.
@@ -194,7 +194,30 @@ export type ElementType = {
194
194
  fixed?: string | boolean | undefined;
195
195
  disabled?: boolean;
196
196
  clickable?: boolean;
197
+ /** columnReorder tables: false = this column cannot be dragged to a new place, nor dropped on */
198
+ reorderable?: boolean;
197
199
  }[];
200
+ /**
201
+ * Tables (`table`, `table-element`): let the user move a column by dragging
202
+ * its header onto another column's header. Off unless true, so a table that
203
+ * does not ask for it renders and behaves exactly as before. Columns with
204
+ * `fixed`, `required: true` or `reorderable: false` stay where they are.
205
+ * See hooks/useColumnReorder.ts.
206
+ */
207
+ columnReorder?: boolean;
208
+ /**
209
+ * columnReorder tables: called when a header is dropped, with the `name` of
210
+ * every thead column in the order the user asked for. The table does not
211
+ * reorder itself — pass back a `thead` in that order. When no handler is
212
+ * given the order is sent through `onChange` instead, as a `columnOrder`
213
+ * entry.
214
+ */
215
+ onColumnReorder?: (order: string[], info: {
216
+ from: string;
217
+ to: string;
218
+ fromIndex: number;
219
+ toIndex: number;
220
+ }) => void;
198
221
  childHead?: {
199
222
  _id?: string;
200
223
  name?: string;
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Column drag-reorder for the schema tables (TableCopyComponent, TableElement).
3
+ *
4
+ * OPT-IN. A table gets it only when its field carries `columnReorder: true`.
5
+ * Without that flag this hook hands back nothing — no header props, no wrapper
6
+ * props — so the table's columns and its DOM are exactly what they were
7
+ * before the feature existed.
8
+ *
9
+ * What it does when on: the header cell of a column can be dragged onto the
10
+ * header cell of another column to move the column there. While dragging, the
11
+ * edge of the target header that the column will land on is marked, and the
12
+ * table scrolls sideways when the pointer nears either end of it.
13
+ *
14
+ * The table never reorders anything itself. It keeps rendering `thead` in the
15
+ * order it is given and only REPORTS the order the user asked for (onReorder).
16
+ * The caller decides what to do with it — save it, typically — and hands back
17
+ * a reordered `thead`. That keeps one owner of the column order.
18
+ *
19
+ * Which columns move: every thead column except those with `fixed` (pinned to
20
+ * an edge), `required: true` (the column that identifies the row) or
21
+ * `reorderable: false`. Those can be neither dragged nor dropped on. The
22
+ * serial-number column and the row-selection column are not thead columns and
23
+ * never move.
24
+ *
25
+ * Built on the browser's native drag and drop through antd's `onHeaderCell`,
26
+ * so it adds no dependency and no wrapper elements around the header cells.
27
+ * Native drag and drop does not fire on touch screens; there the table simply
28
+ * behaves as it does with the feature off.
29
+ */
30
+ import { DragEvent, HTMLAttributes } from 'react';
31
+ /** What the user did: which column was dragged, and onto which. */
32
+ export interface ColumnReorderInfo {
33
+ /** `name` of the dragged column */
34
+ from: string;
35
+ /** `name` of the column it was dropped on */
36
+ to: string;
37
+ /** their positions in `thead` before the move */
38
+ fromIndex: number;
39
+ toIndex: number;
40
+ }
41
+ /** Receives the `name` of every thead column, in the order the user asked for. */
42
+ export type ColumnReorderHandler = (order: string[], info: ColumnReorderInfo) => void;
43
+ /** The parts of a thead column this hook reads. */
44
+ export interface ReorderableColumn {
45
+ name?: string;
46
+ fixed?: string | boolean;
47
+ required?: boolean;
48
+ reorderable?: boolean;
49
+ }
50
+ interface UseColumnReorderOptions {
51
+ /** the table's `columnReorder` flag */
52
+ enabled: boolean;
53
+ /** the table's `thead`, in the order it is rendered */
54
+ columns: ReorderableColumn[] | undefined;
55
+ onReorder: ColumnReorderHandler;
56
+ }
57
+ /** A column the user may drag, and drop other columns on. */
58
+ export declare const isReorderableColumn: (col: ReorderableColumn | null | undefined) => boolean;
59
+ /** `list` with the item at `from` moved to `to`; the input is not changed. */
60
+ export declare const moveItem: <T>(list: T[], from: number, to: number) => T[];
61
+ export declare const useColumnReorder: ({ enabled, columns, onReorder, }: UseColumnReorderOptions) => {
62
+ columnProps: (col: ReorderableColumn) => {
63
+ onHeaderCell?: () => HTMLAttributes<HTMLTableCellElement>;
64
+ };
65
+ wrapperProps: {
66
+ onDragOver?: (event: DragEvent<HTMLDivElement>) => void;
67
+ };
68
+ };
69
+ export {};