@lt-ui/table 0.0.0-stage → 0.0.2
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.
- package/cells/cells.module.css +481 -0
- package/cells/field-cells.d.ts +118 -0
- package/cells/field-cells.js +48 -0
- package/cells/index.d.ts +29 -0
- package/cells/index.js +15 -0
- package/cells/square-select.d.ts +19 -0
- package/cells/square-select.js +37 -0
- package/cells/square.d.ts +16 -0
- package/cells/square.js +78 -0
- package/cells/table-cell-actions.d.ts +32 -0
- package/cells/table-cell-actions.js +36 -0
- package/cells/table-cell-checkbox.d.ts +13 -0
- package/cells/table-cell-checkbox.js +13 -0
- package/cells/table-cell-copy.d.ts +18 -0
- package/cells/table-cell-copy.js +32 -0
- package/cells/table-cell-date.d.ts +20 -0
- package/cells/table-cell-date.js +15 -0
- package/cells/table-cell-expand.d.ts +18 -0
- package/cells/table-cell-expand.js +17 -0
- package/cells/table-cell-file-upload.d.ts +27 -0
- package/cells/table-cell-file-upload.js +22 -0
- package/cells/table-cell-file.d.ts +27 -0
- package/cells/table-cell-file.js +29 -0
- package/cells/table-cell-image.d.ts +22 -0
- package/cells/table-cell-image.js +12 -0
- package/cells/table-cell-input.d.ts +22 -0
- package/cells/table-cell-input.js +22 -0
- package/cells/table-cell-link.d.ts +14 -0
- package/cells/table-cell-link.js +28 -0
- package/cells/table-cell-select.d.ts +44 -0
- package/cells/table-cell-select.js +30 -0
- package/cells/table-cell-switch.d.ts +8 -0
- package/cells/table-cell-switch.js +5 -0
- package/cells/table-cell-textarea.d.ts +22 -0
- package/cells/table-cell-textarea.js +68 -0
- package/cjs/cells/cells.module.css +481 -0
- package/cjs/cells/field-cells.js +87 -0
- package/cjs/cells/index.js +36 -0
- package/cjs/cells/square-select.js +77 -0
- package/cjs/cells/square.js +117 -0
- package/cjs/cells/table-cell-actions.js +75 -0
- package/cjs/cells/table-cell-checkbox.js +19 -0
- package/cjs/cells/table-cell-copy.js +71 -0
- package/cjs/cells/table-cell-date.js +22 -0
- package/cjs/cells/table-cell-expand.js +23 -0
- package/cjs/cells/table-cell-file-upload.js +61 -0
- package/cjs/cells/table-cell-file.js +38 -0
- package/cjs/cells/table-cell-image.js +18 -0
- package/cjs/cells/table-cell-input.js +61 -0
- package/cjs/cells/table-cell-link.js +34 -0
- package/cjs/cells/table-cell-select.js +36 -0
- package/cjs/cells/table-cell-switch.js +12 -0
- package/cjs/cells/table-cell-textarea.js +107 -0
- package/cjs/column-settings.js +128 -0
- package/cjs/columns.js +67 -0
- package/cjs/context.js +14 -0
- package/cjs/corner-settings.js +24 -0
- package/cjs/empty-function.js +8 -0
- package/cjs/features.js +40 -0
- package/cjs/header-filter.js +93 -0
- package/cjs/index.js +44 -0
- package/cjs/layout.js +34 -0
- package/cjs/locale/index.js +8 -0
- package/cjs/locale/messages.js +63 -0
- package/cjs/locale/use-locale.js +10 -0
- package/cjs/row-loading-border.js +79 -0
- package/cjs/selection.js +34 -0
- package/cjs/sort-icon.js +18 -0
- package/cjs/styles.module.css +678 -0
- package/cjs/table-head.js +45 -0
- package/cjs/table-pagination.js +25 -0
- package/cjs/table-row.js +62 -0
- package/cjs/table-search.js +74 -0
- package/cjs/table-toolbar.js +22 -0
- package/cjs/table.js +95 -0
- package/cjs/tanstack.js +2 -0
- package/cjs/types.js +2 -0
- package/cjs/use-pointer-sort.js +116 -0
- package/cjs/use-table.js +23 -0
- package/column-settings.d.ts +59 -0
- package/column-settings.js +88 -0
- package/columns.d.ts +18 -0
- package/columns.js +59 -0
- package/context.d.ts +7 -0
- package/context.js +10 -0
- package/corner-settings.d.ts +11 -0
- package/corner-settings.js +16 -0
- package/empty-function.d.ts +1 -0
- package/empty-function.js +4 -0
- package/features.d.ts +38 -0
- package/features.js +37 -0
- package/header-filter.d.ts +29 -0
- package/header-filter.js +54 -0
- package/index.d.ts +22 -0
- package/index.js +12 -0
- package/layout.d.ts +5 -0
- package/layout.js +27 -0
- package/locale/index.d.ts +3 -0
- package/locale/index.js +2 -0
- package/locale/messages.d.ts +40 -0
- package/locale/messages.js +60 -0
- package/locale/use-locale.d.ts +9 -0
- package/locale/use-locale.js +7 -0
- package/package.json +33 -4
- package/row-loading-border.d.ts +7 -0
- package/row-loading-border.js +40 -0
- package/selection.d.ts +8 -0
- package/selection.js +31 -0
- package/sort-icon.d.ts +8 -0
- package/sort-icon.js +10 -0
- package/styles.module.css +678 -0
- package/table-head.d.ts +6 -0
- package/table-head.js +39 -0
- package/table-pagination.d.ts +16 -0
- package/table-pagination.js +19 -0
- package/table-row.d.ts +21 -0
- package/table-row.js +56 -0
- package/table-search.d.ts +28 -0
- package/table-search.js +38 -0
- package/table-toolbar.d.ts +18 -0
- package/table-toolbar.js +16 -0
- package/table.d.ts +15 -0
- package/table.js +56 -0
- package/tanstack.d.ts +9 -0
- package/tanstack.js +1 -0
- package/types.d.ts +161 -0
- package/types.js +1 -0
- package/use-pointer-sort.d.ts +32 -0
- package/use-pointer-sort.js +113 -0
- package/use-table.d.ts +46 -0
- package/use-table.js +19 -0
- package/README.md +0 -3
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
3
|
+
const move = (list, from, to) => {
|
|
4
|
+
const next = [...list];
|
|
5
|
+
next.splice(to, 0, next.splice(from, 1)[0]);
|
|
6
|
+
return next;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Лёгкая сортировка списка по вертикали без сторонних библиотек: тянем за ручку, остальные элементы
|
|
10
|
+
* сдвигаются на освободившееся место, порядок применяется при отпускании. Ручка работает и с клавиатуры
|
|
11
|
+
* (стрелки вверх и вниз), Escape отменяет перетаскивание.
|
|
12
|
+
*
|
|
13
|
+
* Элементам нужен `getItemProps(id)`, ручкам — `getHandleProps(id)`; элементы списка одной высоты по шагу.
|
|
14
|
+
*/
|
|
15
|
+
export function usePointerSort({ ids, onSort }) {
|
|
16
|
+
var _a;
|
|
17
|
+
const [drag, setDrag] = useState(null);
|
|
18
|
+
const start = useRef(null);
|
|
19
|
+
const root = useRef(null);
|
|
20
|
+
const latest = useRef({ ids, onSort });
|
|
21
|
+
latest.current = { ids, onSort };
|
|
22
|
+
const cancel = useCallback(() => {
|
|
23
|
+
start.current = null;
|
|
24
|
+
setDrag(null);
|
|
25
|
+
}, []);
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
if (!drag)
|
|
28
|
+
return undefined;
|
|
29
|
+
const onKey = (event) => event.key === 'Escape' && cancel();
|
|
30
|
+
document.addEventListener('keydown', onKey);
|
|
31
|
+
return () => document.removeEventListener('keydown', onKey);
|
|
32
|
+
}, [drag, cancel]);
|
|
33
|
+
const getHandleProps = (id) => ({
|
|
34
|
+
style: { touchAction: 'none', cursor: drag ? 'grabbing' : 'grab' },
|
|
35
|
+
'aria-keyshortcuts': 'ArrowUp ArrowDown',
|
|
36
|
+
onPointerDown: (event) => {
|
|
37
|
+
var _a, _b;
|
|
38
|
+
if (event.button !== 0)
|
|
39
|
+
return;
|
|
40
|
+
const item = event.currentTarget.closest('[data-sort-id]');
|
|
41
|
+
const list = item === null || item === void 0 ? void 0 : item.parentElement;
|
|
42
|
+
if (!item || !list)
|
|
43
|
+
return;
|
|
44
|
+
const nodes = [...list.querySelectorAll(':scope > [data-sort-id]')];
|
|
45
|
+
const rects = nodes.map(node => node.getBoundingClientRect());
|
|
46
|
+
const from = nodes.indexOf(item);
|
|
47
|
+
const pitch = rects.length > 1
|
|
48
|
+
? (rects[rects.length - 1].top - rects[0].top) / (rects.length - 1)
|
|
49
|
+
: rects[0].height;
|
|
50
|
+
root.current = list;
|
|
51
|
+
start.current = { y: event.clientY, middles: rects.map(rect => rect.top + rect.height / 2) };
|
|
52
|
+
(_b = (_a = event.currentTarget).setPointerCapture) === null || _b === void 0 ? void 0 : _b.call(_a, event.pointerId);
|
|
53
|
+
setDrag({ id, from, to: from, dy: 0, pitch });
|
|
54
|
+
},
|
|
55
|
+
onPointerMove: (event) => {
|
|
56
|
+
const origin = start.current;
|
|
57
|
+
if (!origin || !drag)
|
|
58
|
+
return;
|
|
59
|
+
const dy = event.clientY - origin.y;
|
|
60
|
+
const center = origin.middles[drag.from] + dy;
|
|
61
|
+
let to = drag.from;
|
|
62
|
+
origin.middles.forEach((middle, index) => {
|
|
63
|
+
if (index < drag.from && center < middle)
|
|
64
|
+
to = Math.min(to, index);
|
|
65
|
+
if (index > drag.from && center > middle)
|
|
66
|
+
to = Math.max(to, index);
|
|
67
|
+
});
|
|
68
|
+
setDrag({ ...drag, dy, to });
|
|
69
|
+
},
|
|
70
|
+
onPointerUp: () => {
|
|
71
|
+
if (!drag)
|
|
72
|
+
return;
|
|
73
|
+
const { ids: current, onSort: commit } = latest.current;
|
|
74
|
+
cancel();
|
|
75
|
+
if (drag.to !== drag.from)
|
|
76
|
+
commit(move(current, drag.from, drag.to));
|
|
77
|
+
},
|
|
78
|
+
onPointerCancel: cancel,
|
|
79
|
+
onKeyDown: (event) => {
|
|
80
|
+
const delta = { ArrowUp: -1, ArrowDown: 1 }[event.key];
|
|
81
|
+
if (!delta)
|
|
82
|
+
return;
|
|
83
|
+
event.preventDefault();
|
|
84
|
+
const from = ids.indexOf(id);
|
|
85
|
+
const to = from + delta;
|
|
86
|
+
if (to >= 0 && to < ids.length)
|
|
87
|
+
onSort(move(ids, from, to));
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
const getItemProps = (id) => {
|
|
91
|
+
const index = ids.indexOf(id);
|
|
92
|
+
let offset = 0;
|
|
93
|
+
if (drag) {
|
|
94
|
+
if (drag.id === id)
|
|
95
|
+
offset = drag.dy;
|
|
96
|
+
else if (drag.to > drag.from && index > drag.from && index <= drag.to)
|
|
97
|
+
offset = -drag.pitch;
|
|
98
|
+
else if (drag.to < drag.from && index >= drag.to && index < drag.from)
|
|
99
|
+
offset = drag.pitch;
|
|
100
|
+
}
|
|
101
|
+
return {
|
|
102
|
+
'data-sort-id': id,
|
|
103
|
+
'data-dragging': (drag === null || drag === void 0 ? void 0 : drag.id) === id || undefined,
|
|
104
|
+
style: {
|
|
105
|
+
transform: offset ? `translateY(${offset}px)` : undefined,
|
|
106
|
+
transition: drag && drag.id !== id ? 'transform 150ms ease' : undefined,
|
|
107
|
+
position: (drag === null || drag === void 0 ? void 0 : drag.id) === id ? 'relative' : undefined,
|
|
108
|
+
zIndex: (drag === null || drag === void 0 ? void 0 : drag.id) === id ? 1 : undefined,
|
|
109
|
+
},
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
return { dragging: (_a = drag === null || drag === void 0 ? void 0 : drag.id) !== null && _a !== void 0 ? _a : null, getItemProps, getHandleProps };
|
|
113
|
+
}
|
package/use-table.d.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { ColumnDef, RowData, TableOptions } from './tanstack';
|
|
2
|
+
import { defaultTableFeatures } from './features';
|
|
3
|
+
/** Columns without a size fit their content; sorting is enabled explicitly per column. */
|
|
4
|
+
export declare const tableDefaultColumn: Partial<ColumnDef<RowData>>;
|
|
5
|
+
export type UseTableOptions<T extends RowData> = Omit<TableOptions<T>, 'features'> & {
|
|
6
|
+
features?: typeof defaultTableFeatures;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* TanStack Table 9 with the features used by LT UI, content-sized columns and opt-in client pagination.
|
|
10
|
+
* Pass manualPagination: false to paginate on the client, or supply rowCount/pageCount for server pagination.
|
|
11
|
+
*/
|
|
12
|
+
export declare function useTable<T extends RowData>(options: UseTableOptions<T>): import("@tanstack/react-table").ReactTable<{
|
|
13
|
+
columnFilteringFeature: import("@tanstack/table-core").TableFeature;
|
|
14
|
+
columnOrderingFeature: import("@tanstack/table-core").TableFeature;
|
|
15
|
+
columnPinningFeature: import("@tanstack/table-core").TableFeature;
|
|
16
|
+
columnResizingFeature: import("@tanstack/table-core").TableFeature;
|
|
17
|
+
columnSizingFeature: import("@tanstack/table-core").TableFeature;
|
|
18
|
+
columnVisibilityFeature: import("@tanstack/table-core").TableFeature;
|
|
19
|
+
globalFilteringFeature: import("@tanstack/table-core").TableFeature;
|
|
20
|
+
rowExpandingFeature: import("@tanstack/table-core").TableFeature;
|
|
21
|
+
rowPaginationFeature: import("@tanstack/table-core").TableFeature;
|
|
22
|
+
rowSelectionFeature: import("@tanstack/table-core").TableFeature;
|
|
23
|
+
rowSortingFeature: import("@tanstack/table-core").TableFeature;
|
|
24
|
+
filteredRowModel: (table: import("@tanstack/table-core").Table<any, any>) => () => import("@tanstack/table-core").RowModel<any, any>;
|
|
25
|
+
sortedRowModel: (table: import("@tanstack/table-core").Table<any, any>) => () => import("@tanstack/table-core").RowModel<any, any>;
|
|
26
|
+
expandedRowModel: (table: import("@tanstack/table-core").Table<any, any>) => () => import("@tanstack/table-core").RowModel<any, any>;
|
|
27
|
+
paginatedRowModel: (table: import("@tanstack/table-core").Table<any, any>) => () => import("@tanstack/table-core").RowModel<any, any>;
|
|
28
|
+
filterFns: {
|
|
29
|
+
includesString: import("@tanstack/table-core").CreatedFilterFn<any, any>;
|
|
30
|
+
includesStringSensitive: import("@tanstack/table-core").CreatedFilterFn<any, any>;
|
|
31
|
+
equalsString: import("@tanstack/table-core").CreatedFilterFn<any, any>;
|
|
32
|
+
arrIncludes: import("@tanstack/table-core").CreatedFilterFn<any, any>;
|
|
33
|
+
equals: import("@tanstack/table-core").CreatedFilterFn<any, any>;
|
|
34
|
+
weakEquals: import("@tanstack/table-core").CreatedFilterFn<any, any>;
|
|
35
|
+
inNumberRange: import("@tanstack/table-core").CreatedFilterFn<any, any>;
|
|
36
|
+
};
|
|
37
|
+
sortFns: {
|
|
38
|
+
alphanumeric: import("@tanstack/table-core").CreatedSortFn<any, any>;
|
|
39
|
+
alphanumericCaseSensitive: import("@tanstack/table-core").CreatedSortFn<any, any>;
|
|
40
|
+
basic: import("@tanstack/table-core").CreatedSortFn<any, any>;
|
|
41
|
+
datetime: import("@tanstack/table-core").CreatedSortFn<any, any>;
|
|
42
|
+
text: import("@tanstack/table-core").CreatedSortFn<any, any>;
|
|
43
|
+
textCaseSensitive: import("@tanstack/table-core").CreatedSortFn<any, any>;
|
|
44
|
+
};
|
|
45
|
+
columnMeta: import("./types").TableColumnMeta;
|
|
46
|
+
}, T, import("@tanstack/table-core").TableState_ColumnFiltering & import("@tanstack/table-core").TableState_ColumnOrdering & import("@tanstack/table-core").TableState_ColumnPinning & import("@tanstack/table-core").TableState_ColumnResizing & import("@tanstack/table-core").TableState_ColumnSizing & import("@tanstack/table-core").TableState_ColumnVisibility & import("@tanstack/table-core").TableState_GlobalFiltering & import("@tanstack/table-core").TableState_RowExpanding & import("@tanstack/table-core").TableState_RowPagination & import("@tanstack/table-core").TableState_RowSelection & import("@tanstack/table-core").TableState_RowSorting>;
|
package/use-table.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useTable as useTanstackTable } from '@tanstack/react-table';
|
|
3
|
+
import { defaultTableFeatures } from './features';
|
|
4
|
+
/** Columns without a size fit their content; sorting is enabled explicitly per column. */
|
|
5
|
+
export const tableDefaultColumn = { size: 0, minSize: 0, enableSorting: false };
|
|
6
|
+
/**
|
|
7
|
+
* TanStack Table 9 with the features used by LT UI, content-sized columns and opt-in client pagination.
|
|
8
|
+
* Pass manualPagination: false to paginate on the client, or supply rowCount/pageCount for server pagination.
|
|
9
|
+
*/
|
|
10
|
+
export function useTable(options) {
|
|
11
|
+
return useTanstackTable({
|
|
12
|
+
features: defaultTableFeatures,
|
|
13
|
+
manualPagination: true,
|
|
14
|
+
autoResetExpanded: false,
|
|
15
|
+
autoResetPageIndex: false,
|
|
16
|
+
...options,
|
|
17
|
+
defaultColumn: { ...tableDefaultColumn, ...options.defaultColumn },
|
|
18
|
+
});
|
|
19
|
+
}
|
package/README.md
DELETED