@pallasoft/ps-table-components 1.23.0 → 1.25.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.
- package/dist/components/ps-data-table.js +20 -7
- package/dist/components/ps-table-reorder-frame.js +2 -2
- package/dist/esm/components/ps-data-table.js +20 -7
- package/dist/esm/components/ps-table-reorder-frame.js +2 -2
- package/dist/esm/hooks/use-ps-table-reorder.js +8 -0
- package/dist/esm/services/ps-table-column-size-service.js +7 -0
- package/dist/hooks/use-ps-table-reorder.d.ts +1 -0
- package/dist/hooks/use-ps-table-reorder.js +8 -0
- package/dist/interfaces/table-column.d.ts +2 -0
- package/dist/interfaces/table-reorder-nesting-binding.d.ts +1 -0
- package/dist/interfaces/table-reorder-nesting.d.ts +1 -0
- package/dist/services/ps-table-column-size-service.d.ts +1 -0
- package/dist/services/ps-table-column-size-service.js +7 -0
- package/package.json +1 -1
|
@@ -74,9 +74,9 @@ const densityClassNames = {
|
|
|
74
74
|
head: 'px-5 py-3.5',
|
|
75
75
|
},
|
|
76
76
|
};
|
|
77
|
-
const columnStyle = (column) => ({
|
|
78
|
-
maxWidth: ps_table_column_size_service_1.PsTableColumnSizeService.maxWidthOf(column),
|
|
79
|
-
minWidth: ps_table_column_size_service_1.PsTableColumnSizeService.minWidthOf(column),
|
|
77
|
+
const columnStyle = (column, fittedMinWidth) => ({
|
|
78
|
+
maxWidth: column.measure === undefined ? ps_table_column_size_service_1.PsTableColumnSizeService.maxWidthOf(column) : undefined,
|
|
79
|
+
minWidth: fittedMinWidth === undefined ? ps_table_column_size_service_1.PsTableColumnSizeService.minWidthOf(column) : fittedMinWidth,
|
|
80
80
|
width: column.width,
|
|
81
81
|
});
|
|
82
82
|
const alignClassNames = {
|
|
@@ -95,6 +95,9 @@ const PsDataTable = ({ caption, className, columns, defaultSort, density = 'norm
|
|
|
95
95
|
const currentQuery = query ? query : uncontrolledQuery;
|
|
96
96
|
const { filters, hiddenColumnIds, search, sort } = currentQuery;
|
|
97
97
|
const visibleColumns = columns.filter((column) => !hiddenColumnIds.includes(column.id));
|
|
98
|
+
const fittedWidths = (0, react_1.useMemo)(() => new Map(columns
|
|
99
|
+
.filter((column) => column.measure !== undefined)
|
|
100
|
+
.map((column) => [column.id, ps_table_column_size_service_1.PsTableColumnSizeService.fittedMinWidthOf(column, rows)])), [columns, rows]);
|
|
98
101
|
const updateQuery = (patch) => {
|
|
99
102
|
const next = { ...currentQuery, ...patch };
|
|
100
103
|
if (!query)
|
|
@@ -198,6 +201,15 @@ const PsDataTable = ({ caption, className, columns, defaultSort, density = 'norm
|
|
|
198
201
|
const target = find(targetId);
|
|
199
202
|
return (active !== undefined && target !== undefined && nesting.canDrop(active, target, placement));
|
|
200
203
|
},
|
|
204
|
+
getBlockedReason: nesting.getBlockedReason === undefined
|
|
205
|
+
? undefined
|
|
206
|
+
: (activeId, targetId) => {
|
|
207
|
+
const active = find(activeId);
|
|
208
|
+
const target = find(targetId);
|
|
209
|
+
return active !== undefined && target !== undefined && nesting.getBlockedReason
|
|
210
|
+
? nesting.getBlockedReason(active, target)
|
|
211
|
+
: null;
|
|
212
|
+
},
|
|
201
213
|
onMove: (activeId, targetId, placement) => {
|
|
202
214
|
const active = find(activeId);
|
|
203
215
|
const target = find(targetId);
|
|
@@ -323,10 +335,11 @@ const PsDataTable = ({ caption, className, columns, defaultSort, density = 'norm
|
|
|
323
335
|
}
|
|
324
336
|
: undefined, style: motion && motion.delayMs !== undefined
|
|
325
337
|
? { animationDelay: `${motion.delayMs}ms` }
|
|
326
|
-
: undefined, tabIndex: onRowClick ? 0 : undefined, children: [reorder && !api.isActive ? ((0, jsx_runtime_1.jsx)("td", { className: ps_design_system_1.PallasoftClassNameService.merge('w-9 min-w-9 pl-3 pr-0', pins.reorder) })) : null, isSelectable ? ((0, jsx_runtime_1.jsx)("td", { className: ps_design_system_1.PallasoftClassNameService.merge('w-10 min-w-10 pl-4 pr-0', pins.select), onClick: (event) => event.stopPropagation(), onKeyDown: (event) => event.stopPropagation(), children: (0, jsx_runtime_1.jsx)(ps_input_components_1.PsCheckbox, { isSelected: selectedIdSet.has(rowId), label: `Select ${rowLabel}`, onChange: () => toggleRow(rowId) }) })) : null, visibleColumns.map((column, columnIndex) => ((0, jsx_runtime_1.jsx)("td", { className: ps_design_system_1.PallasoftClassNameService.merge(densityClassNames[density].cell, placementOf(column, columnIndex), alignClassNames[column.align !== null && column.align !== undefined ? column.align : 'left'], column.wrap ? '' : 'whitespace-nowrap',
|
|
327
|
-
|
|
338
|
+
: undefined, tabIndex: onRowClick ? 0 : undefined, children: [reorder && !api.isActive ? ((0, jsx_runtime_1.jsx)("td", { className: ps_design_system_1.PallasoftClassNameService.merge('w-9 min-w-9 pl-3 pr-0', pins.reorder) })) : null, isSelectable ? ((0, jsx_runtime_1.jsx)("td", { className: ps_design_system_1.PallasoftClassNameService.merge('w-10 min-w-10 pl-4 pr-0', pins.select), onClick: (event) => event.stopPropagation(), onKeyDown: (event) => event.stopPropagation(), children: (0, jsx_runtime_1.jsx)(ps_input_components_1.PsCheckbox, { isSelected: selectedIdSet.has(rowId), label: `Select ${rowLabel}`, onChange: () => toggleRow(rowId) }) })) : null, visibleColumns.map((column, columnIndex) => ((0, jsx_runtime_1.jsx)("td", { className: ps_design_system_1.PallasoftClassNameService.merge(densityClassNames[density].cell, placementOf(column, columnIndex), alignClassNames[column.align !== null && column.align !== undefined ? column.align : 'left'], column.wrap ? '' : 'whitespace-nowrap', column.measure === undefined &&
|
|
339
|
+
((layout === 'fixed' && !column.wrap) ||
|
|
340
|
+
ps_table_column_size_service_1.PsTableColumnSizeService.maxWidthOf(column) !== undefined)
|
|
328
341
|
? 'truncate'
|
|
329
|
-
: '', 'text-sm text-ink'), style: columnStyle(column), title: ps_table_cell_tooltip_service_1.PsTableCellTooltipService.forCell(column, row), children: column.render(row) }, column.id)))] }), renderExpandedRow ? ((0, jsx_runtime_1.jsx)("tr", { "aria-hidden": !isExpanded, className: isExpanded ? 'border-t-0' : 'border-0', children: (0, jsx_runtime_1.jsx)("td", { className: 'p-0', colSpan: columnCount, children: (0, jsx_runtime_1.jsx)(ps_motion_components_1.PsCollapse, { isOpen: isExpanded, children: (0, jsx_runtime_1.jsx)("div", { className: 'w-0 min-w-full border-l-2 border-primary bg-mist/40 px-4 py-4', children: renderExpandedRow(row) }) }) }) })) : null] }, rowId));
|
|
342
|
+
: '', 'text-sm text-ink'), style: columnStyle(column, fittedWidths.get(column.id)), title: ps_table_cell_tooltip_service_1.PsTableCellTooltipService.forCell(column, row), children: column.render(row) }, column.id)))] }), renderExpandedRow ? ((0, jsx_runtime_1.jsx)("tr", { "aria-hidden": !isExpanded, className: isExpanded ? 'border-t-0' : 'border-0', children: (0, jsx_runtime_1.jsx)("td", { className: 'p-0', colSpan: columnCount, children: (0, jsx_runtime_1.jsx)(ps_motion_components_1.PsCollapse, { isOpen: isExpanded, children: (0, jsx_runtime_1.jsx)("div", { className: 'w-0 min-w-full border-l-2 border-primary bg-mist/40 px-4 py-4', children: renderExpandedRow(row) }) }) }) })) : null] }, rowId));
|
|
330
343
|
};
|
|
331
344
|
const renderEntries = (api, entries) => reorder
|
|
332
345
|
? ps_table_reorder_service_1.PsTableReorderService.runs(entries, (entry) => reorderKey(entry.row), (entry) => getRowId(entry.row)).map((run) => api.run(run.id, run.items.map((entry) => getRowId(entry.row)), run.items.map((entry) => renderRow(api, entry.row, entry.motion, entry.virtualItem))))
|
|
@@ -355,7 +368,7 @@ const PsDataTable = ({ caption, className, columns, defaultSort, density = 'norm
|
|
|
355
368
|
? sort.direction
|
|
356
369
|
: column.sortValue && isQueryable
|
|
357
370
|
? 'none'
|
|
358
|
-
: undefined, className: ps_design_system_1.PallasoftClassNameService.merge(densityClassNames[density].head, alignClassNames[align], placementOf(column, columnIndex), 'whitespace-nowrap'), scope: 'col', style: columnStyle(column), children: column.sortValue && isQueryable ? ((0, jsx_runtime_1.jsx)(ps_table_sort_header_1.PsTableSortHeader, { align: align, columnId: column.id, label: column.label, onSort: updateSort, sort: sort })) : (column.label) }, column.id));
|
|
371
|
+
: undefined, className: ps_design_system_1.PallasoftClassNameService.merge(densityClassNames[density].head, alignClassNames[align], placementOf(column, columnIndex), 'whitespace-nowrap'), scope: 'col', style: columnStyle(column, fittedWidths.get(column.id)), children: column.sortValue && isQueryable ? ((0, jsx_runtime_1.jsx)(ps_table_sort_header_1.PsTableSortHeader, { align: align, columnId: column.id, label: column.label, onSort: updateSort, sort: sort })) : (column.label) }, column.id));
|
|
359
372
|
})] }) }), (0, jsx_runtime_1.jsxs)("tbody", { className: 'divide-y divide-line', ref: bodyRef, children: [visibleRows.length === 0 && isSearching ? ((0, jsx_runtime_1.jsx)("tr", { children: (0, jsx_runtime_1.jsx)("td", { className: 'p-0', colSpan: columnCount, children: (0, jsx_runtime_1.jsx)(ps_table_searching_state_1.PsTableSearchingState, { label: searchingLabel, skeletonRows: table_config_1.PsTableConfig.searchingSkeletonRows }) }) })) : null, visibleRows.length === 0 && isQueried && !isSearching ? ((0, jsx_runtime_1.jsx)("tr", { children: (0, jsx_runtime_1.jsxs)("td", { className: 'px-4 py-12 text-center', colSpan: columnCount, children: [(0, jsx_runtime_1.jsx)("p", { className: 'text-sm font-semibold text-ink', children: table_config_1.PsTableConfig.noMatchesTitle }), (0, jsx_runtime_1.jsx)("p", { className: 'mt-1 text-sm text-ink/55', children: table_config_1.PsTableConfig.noMatchesDescription }), (0, jsx_runtime_1.jsx)("button", { className: ps_design_system_1.PallasoftClassNameService.merge(ps_table_control_classes_1.PsTableControlClasses.textButton, 'mt-3 text-primary hover:underline'), onClick: clearFilters, type: 'button', children: "Clear search and filters" })] }) })) : null, grouping
|
|
360
373
|
? groups.map((group, groupIndex) => {
|
|
361
374
|
const isExpanded = isGroupExpanded(group.key, groupIndex);
|
|
@@ -9,7 +9,7 @@ const use_ps_table_reorder_1 = require("../hooks/use-ps-table-reorder");
|
|
|
9
9
|
const ps_table_reorder_service_1 = require("../services/ps-table-reorder-service");
|
|
10
10
|
const ps_table_sortable_row_1 = require("./ps-table-sortable-row");
|
|
11
11
|
const PsTableReorderFrame = ({ children, renderOverlay, ...input }) => {
|
|
12
|
-
const { activeId, activeRunId, contextProps, drop, placements } = (0, use_ps_table_reorder_1.usePsTableReorder)(input);
|
|
12
|
+
const { activeId, activeRunId, blockedReason, contextProps, drop, placements } = (0, use_ps_table_reorder_1.usePsTableReorder)(input);
|
|
13
13
|
const itemById = new Map(input.items.map((item) => [item.id, item]));
|
|
14
14
|
const { nesting } = input;
|
|
15
15
|
const api = {
|
|
@@ -38,6 +38,6 @@ const PsTableReorderFrame = ({ children, renderOverlay, ...input }) => {
|
|
|
38
38
|
},
|
|
39
39
|
run: (runId, ids, runChildren) => ((0, jsx_runtime_1.jsx)(sortable_1.SortableContext, { items: ids, strategy: nesting === undefined ? sortable_1.verticalListSortingStrategy : ps_table_reorder_service_1.PsTableReorderService.still, children: runChildren }, runId)),
|
|
40
40
|
};
|
|
41
|
-
return ((0, jsx_runtime_1.jsxs)(core_1.DndContext, { ...contextProps, children: [children(api), (0, jsx_runtime_1.jsx)(ps_core_components_1.PsDragOverlay, { className: ps_core_components_1.PsDragClasses.lifted, frames: ps_core_components_1.PsDragListLiftFrames, children: activeId === null ? null : renderOverlay(activeId) })] }));
|
|
41
|
+
return ((0, jsx_runtime_1.jsxs)(core_1.DndContext, { ...contextProps, children: [children(api), blockedReason === null ? null : ((0, jsx_runtime_1.jsx)("p", { className: 'pointer-events-none fixed bottom-6 left-1/2 z-50 max-w-sm -translate-x-1/2 rounded-ps-control bg-ink px-3 py-2 text-sm text-white shadow-lg', role: 'status', children: blockedReason })), (0, jsx_runtime_1.jsx)(ps_core_components_1.PsDragOverlay, { className: ps_core_components_1.PsDragClasses.lifted, frames: ps_core_components_1.PsDragListLiftFrames, children: activeId === null ? null : renderOverlay(activeId) })] }));
|
|
42
42
|
};
|
|
43
43
|
exports.PsTableReorderFrame = PsTableReorderFrame;
|
|
@@ -38,9 +38,9 @@ const densityClassNames = {
|
|
|
38
38
|
head: 'px-5 py-3.5',
|
|
39
39
|
},
|
|
40
40
|
};
|
|
41
|
-
const columnStyle = (column) => ({
|
|
42
|
-
maxWidth: PsTableColumnSizeService.maxWidthOf(column),
|
|
43
|
-
minWidth: PsTableColumnSizeService.minWidthOf(column),
|
|
41
|
+
const columnStyle = (column, fittedMinWidth) => ({
|
|
42
|
+
maxWidth: column.measure === undefined ? PsTableColumnSizeService.maxWidthOf(column) : undefined,
|
|
43
|
+
minWidth: fittedMinWidth === undefined ? PsTableColumnSizeService.minWidthOf(column) : fittedMinWidth,
|
|
44
44
|
width: column.width,
|
|
45
45
|
});
|
|
46
46
|
const alignClassNames = {
|
|
@@ -59,6 +59,9 @@ export const PsDataTable = ({ caption, className, columns, defaultSort, density
|
|
|
59
59
|
const currentQuery = query ? query : uncontrolledQuery;
|
|
60
60
|
const { filters, hiddenColumnIds, search, sort } = currentQuery;
|
|
61
61
|
const visibleColumns = columns.filter((column) => !hiddenColumnIds.includes(column.id));
|
|
62
|
+
const fittedWidths = useMemo(() => new Map(columns
|
|
63
|
+
.filter((column) => column.measure !== undefined)
|
|
64
|
+
.map((column) => [column.id, PsTableColumnSizeService.fittedMinWidthOf(column, rows)])), [columns, rows]);
|
|
62
65
|
const updateQuery = (patch) => {
|
|
63
66
|
const next = { ...currentQuery, ...patch };
|
|
64
67
|
if (!query)
|
|
@@ -162,6 +165,15 @@ export const PsDataTable = ({ caption, className, columns, defaultSort, density
|
|
|
162
165
|
const target = find(targetId);
|
|
163
166
|
return (active !== undefined && target !== undefined && nesting.canDrop(active, target, placement));
|
|
164
167
|
},
|
|
168
|
+
getBlockedReason: nesting.getBlockedReason === undefined
|
|
169
|
+
? undefined
|
|
170
|
+
: (activeId, targetId) => {
|
|
171
|
+
const active = find(activeId);
|
|
172
|
+
const target = find(targetId);
|
|
173
|
+
return active !== undefined && target !== undefined && nesting.getBlockedReason
|
|
174
|
+
? nesting.getBlockedReason(active, target)
|
|
175
|
+
: null;
|
|
176
|
+
},
|
|
165
177
|
onMove: (activeId, targetId, placement) => {
|
|
166
178
|
const active = find(activeId);
|
|
167
179
|
const target = find(targetId);
|
|
@@ -287,10 +299,11 @@ export const PsDataTable = ({ caption, className, columns, defaultSort, density
|
|
|
287
299
|
}
|
|
288
300
|
: undefined, style: motion && motion.delayMs !== undefined
|
|
289
301
|
? { animationDelay: `${motion.delayMs}ms` }
|
|
290
|
-
: undefined, tabIndex: onRowClick ? 0 : undefined, children: [reorder && !api.isActive ? (_jsx("td", { className: PallasoftClassNameService.merge('w-9 min-w-9 pl-3 pr-0', pins.reorder) })) : null, isSelectable ? (_jsx("td", { className: PallasoftClassNameService.merge('w-10 min-w-10 pl-4 pr-0', pins.select), onClick: (event) => event.stopPropagation(), onKeyDown: (event) => event.stopPropagation(), children: _jsx(PsCheckbox, { isSelected: selectedIdSet.has(rowId), label: `Select ${rowLabel}`, onChange: () => toggleRow(rowId) }) })) : null, visibleColumns.map((column, columnIndex) => (_jsx("td", { className: PallasoftClassNameService.merge(densityClassNames[density].cell, placementOf(column, columnIndex), alignClassNames[column.align !== null && column.align !== undefined ? column.align : 'left'], column.wrap ? '' : 'whitespace-nowrap',
|
|
291
|
-
|
|
302
|
+
: undefined, tabIndex: onRowClick ? 0 : undefined, children: [reorder && !api.isActive ? (_jsx("td", { className: PallasoftClassNameService.merge('w-9 min-w-9 pl-3 pr-0', pins.reorder) })) : null, isSelectable ? (_jsx("td", { className: PallasoftClassNameService.merge('w-10 min-w-10 pl-4 pr-0', pins.select), onClick: (event) => event.stopPropagation(), onKeyDown: (event) => event.stopPropagation(), children: _jsx(PsCheckbox, { isSelected: selectedIdSet.has(rowId), label: `Select ${rowLabel}`, onChange: () => toggleRow(rowId) }) })) : null, visibleColumns.map((column, columnIndex) => (_jsx("td", { className: PallasoftClassNameService.merge(densityClassNames[density].cell, placementOf(column, columnIndex), alignClassNames[column.align !== null && column.align !== undefined ? column.align : 'left'], column.wrap ? '' : 'whitespace-nowrap', column.measure === undefined &&
|
|
303
|
+
((layout === 'fixed' && !column.wrap) ||
|
|
304
|
+
PsTableColumnSizeService.maxWidthOf(column) !== undefined)
|
|
292
305
|
? 'truncate'
|
|
293
|
-
: '', 'text-sm text-ink'), style: columnStyle(column), title: PsTableCellTooltipService.forCell(column, row), children: column.render(row) }, column.id)))] }), renderExpandedRow ? (_jsx("tr", { "aria-hidden": !isExpanded, className: isExpanded ? 'border-t-0' : 'border-0', children: _jsx("td", { className: 'p-0', colSpan: columnCount, children: _jsx(PsCollapse, { isOpen: isExpanded, children: _jsx("div", { className: 'w-0 min-w-full border-l-2 border-primary bg-mist/40 px-4 py-4', children: renderExpandedRow(row) }) }) }) })) : null] }, rowId));
|
|
306
|
+
: '', 'text-sm text-ink'), style: columnStyle(column, fittedWidths.get(column.id)), title: PsTableCellTooltipService.forCell(column, row), children: column.render(row) }, column.id)))] }), renderExpandedRow ? (_jsx("tr", { "aria-hidden": !isExpanded, className: isExpanded ? 'border-t-0' : 'border-0', children: _jsx("td", { className: 'p-0', colSpan: columnCount, children: _jsx(PsCollapse, { isOpen: isExpanded, children: _jsx("div", { className: 'w-0 min-w-full border-l-2 border-primary bg-mist/40 px-4 py-4', children: renderExpandedRow(row) }) }) }) })) : null] }, rowId));
|
|
294
307
|
};
|
|
295
308
|
const renderEntries = (api, entries) => reorder
|
|
296
309
|
? PsTableReorderService.runs(entries, (entry) => reorderKey(entry.row), (entry) => getRowId(entry.row)).map((run) => api.run(run.id, run.items.map((entry) => getRowId(entry.row)), run.items.map((entry) => renderRow(api, entry.row, entry.motion, entry.virtualItem))))
|
|
@@ -319,7 +332,7 @@ export const PsDataTable = ({ caption, className, columns, defaultSort, density
|
|
|
319
332
|
? sort.direction
|
|
320
333
|
: column.sortValue && isQueryable
|
|
321
334
|
? 'none'
|
|
322
|
-
: undefined, className: PallasoftClassNameService.merge(densityClassNames[density].head, alignClassNames[align], placementOf(column, columnIndex), 'whitespace-nowrap'), scope: 'col', style: columnStyle(column), children: column.sortValue && isQueryable ? (_jsx(PsTableSortHeader, { align: align, columnId: column.id, label: column.label, onSort: updateSort, sort: sort })) : (column.label) }, column.id));
|
|
335
|
+
: undefined, className: PallasoftClassNameService.merge(densityClassNames[density].head, alignClassNames[align], placementOf(column, columnIndex), 'whitespace-nowrap'), scope: 'col', style: columnStyle(column, fittedWidths.get(column.id)), children: column.sortValue && isQueryable ? (_jsx(PsTableSortHeader, { align: align, columnId: column.id, label: column.label, onSort: updateSort, sort: sort })) : (column.label) }, column.id));
|
|
323
336
|
})] }) }), _jsxs("tbody", { className: 'divide-y divide-line', ref: bodyRef, children: [visibleRows.length === 0 && isSearching ? (_jsx("tr", { children: _jsx("td", { className: 'p-0', colSpan: columnCount, children: _jsx(PsTableSearchingState, { label: searchingLabel, skeletonRows: PsTableConfig.searchingSkeletonRows }) }) })) : null, visibleRows.length === 0 && isQueried && !isSearching ? (_jsx("tr", { children: _jsxs("td", { className: 'px-4 py-12 text-center', colSpan: columnCount, children: [_jsx("p", { className: 'text-sm font-semibold text-ink', children: PsTableConfig.noMatchesTitle }), _jsx("p", { className: 'mt-1 text-sm text-ink/55', children: PsTableConfig.noMatchesDescription }), _jsx("button", { className: PallasoftClassNameService.merge(PsTableControlClasses.textButton, 'mt-3 text-primary hover:underline'), onClick: clearFilters, type: 'button', children: "Clear search and filters" })] }) })) : null, grouping
|
|
324
337
|
? groups.map((group, groupIndex) => {
|
|
325
338
|
const isExpanded = isGroupExpanded(group.key, groupIndex);
|
|
@@ -6,7 +6,7 @@ import { usePsTableReorder } from '../hooks/use-ps-table-reorder';
|
|
|
6
6
|
import { PsTableReorderService } from '../services/ps-table-reorder-service';
|
|
7
7
|
import { PsTableSortableRow } from './ps-table-sortable-row';
|
|
8
8
|
export const PsTableReorderFrame = ({ children, renderOverlay, ...input }) => {
|
|
9
|
-
const { activeId, activeRunId, contextProps, drop, placements } = usePsTableReorder(input);
|
|
9
|
+
const { activeId, activeRunId, blockedReason, contextProps, drop, placements } = usePsTableReorder(input);
|
|
10
10
|
const itemById = new Map(input.items.map((item) => [item.id, item]));
|
|
11
11
|
const { nesting } = input;
|
|
12
12
|
const api = {
|
|
@@ -35,5 +35,5 @@ export const PsTableReorderFrame = ({ children, renderOverlay, ...input }) => {
|
|
|
35
35
|
},
|
|
36
36
|
run: (runId, ids, runChildren) => (_jsx(SortableContext, { items: ids, strategy: nesting === undefined ? verticalListSortingStrategy : PsTableReorderService.still, children: runChildren }, runId)),
|
|
37
37
|
};
|
|
38
|
-
return (_jsxs(DndContext, { ...contextProps, children: [children(api), _jsx(PsDragOverlay, { className: PsDragClasses.lifted, frames: PsDragListLiftFrames, children: activeId === null ? null : renderOverlay(activeId) })] }));
|
|
38
|
+
return (_jsxs(DndContext, { ...contextProps, children: [children(api), blockedReason === null ? null : (_jsx("p", { className: 'pointer-events-none fixed bottom-6 left-1/2 z-50 max-w-sm -translate-x-1/2 rounded-ps-control bg-ink px-3 py-2 text-sm text-white shadow-lg', role: 'status', children: blockedReason })), _jsx(PsDragOverlay, { className: PsDragClasses.lifted, frames: PsDragListLiftFrames, children: activeId === null ? null : renderOverlay(activeId) })] }));
|
|
39
39
|
};
|
|
@@ -10,6 +10,7 @@ const pointerThenCenter = (args) => {
|
|
|
10
10
|
export const usePsTableReorder = ({ announcements: texts, enabled, instructions, items, nesting, onReorder, }) => {
|
|
11
11
|
const [activeId, setActiveId] = useState(null);
|
|
12
12
|
const [drop, setDrop] = useState(null);
|
|
13
|
+
const [blockedReason, setBlockedReason] = useState(null);
|
|
13
14
|
const dropRef = useRef(null);
|
|
14
15
|
const sensors = usePsDragSensors();
|
|
15
16
|
const runs = useMemo(() => enabled
|
|
@@ -85,6 +86,10 @@ export const usePsTableReorder = ({ announcements: texts, enabled, instructions,
|
|
|
85
86
|
const handleDragMove = (event) => {
|
|
86
87
|
const next = resolveDrop(event);
|
|
87
88
|
dropRef.current = next;
|
|
89
|
+
const blocked = next === null && nesting !== undefined && nesting.getBlockedReason && event.over !== null
|
|
90
|
+
? nesting.getBlockedReason(String(event.active.id), String(event.over.id))
|
|
91
|
+
: null;
|
|
92
|
+
setBlockedReason(blocked);
|
|
88
93
|
setDrop((current) => current !== null &&
|
|
89
94
|
next !== null &&
|
|
90
95
|
current.overId === next.overId &&
|
|
@@ -97,6 +102,7 @@ export const usePsTableReorder = ({ announcements: texts, enabled, instructions,
|
|
|
97
102
|
const target = resolveDrop(event);
|
|
98
103
|
setActiveId(null);
|
|
99
104
|
setDrop(null);
|
|
105
|
+
setBlockedReason(null);
|
|
100
106
|
dropRef.current = null;
|
|
101
107
|
if (nesting !== undefined) {
|
|
102
108
|
if (target !== null)
|
|
@@ -116,6 +122,7 @@ export const usePsTableReorder = ({ announcements: texts, enabled, instructions,
|
|
|
116
122
|
};
|
|
117
123
|
return {
|
|
118
124
|
activeId,
|
|
125
|
+
blockedReason,
|
|
119
126
|
activeRunId: activePlacement === undefined ? null : activePlacement.runId,
|
|
120
127
|
contextProps: {
|
|
121
128
|
accessibility: { announcements, screenReaderInstructions: { draggable: instructions } },
|
|
@@ -124,6 +131,7 @@ export const usePsTableReorder = ({ announcements: texts, enabled, instructions,
|
|
|
124
131
|
onDragCancel: () => {
|
|
125
132
|
setActiveId(null);
|
|
126
133
|
setDrop(null);
|
|
134
|
+
setBlockedReason(null);
|
|
127
135
|
dropRef.current = null;
|
|
128
136
|
},
|
|
129
137
|
onDragEnd: handleDragEnd,
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import { PsTableColumnMaxWidths, PsTableColumnSize, PsTableColumnWidths, } from '../constants/table-column-size';
|
|
2
2
|
import { PsTableFilterKind } from '../constants/table-filter-kind';
|
|
3
3
|
export class PsTableColumnSizeService {
|
|
4
|
+
static fittedMinWidthOf(column, rows) {
|
|
5
|
+
const measure = column.measure;
|
|
6
|
+
if (measure === undefined)
|
|
7
|
+
return undefined;
|
|
8
|
+
const longest = rows.reduce((length, row) => Math.max(length, measure(row).length), 0);
|
|
9
|
+
return `max(${PsTableColumnSizeService.minWidthOf(column)}, calc(${(longest * 1.1).toFixed(1)}ch + 3rem))`;
|
|
10
|
+
}
|
|
4
11
|
static sizeOf(column) {
|
|
5
12
|
if (column.size !== undefined)
|
|
6
13
|
return column.size;
|
|
@@ -16,6 +16,7 @@ export interface PsTableReorderState {
|
|
|
16
16
|
activeId: string | null;
|
|
17
17
|
activeRunId: string | null;
|
|
18
18
|
contextProps: Omit<DndContextProps, 'children'>;
|
|
19
|
+
blockedReason: string | null;
|
|
19
20
|
drop: PsTableDrop | null;
|
|
20
21
|
placements: Map<string, PsTableReorderPlacement>;
|
|
21
22
|
}
|
|
@@ -13,6 +13,7 @@ const pointerThenCenter = (args) => {
|
|
|
13
13
|
const usePsTableReorder = ({ announcements: texts, enabled, instructions, items, nesting, onReorder, }) => {
|
|
14
14
|
const [activeId, setActiveId] = (0, react_1.useState)(null);
|
|
15
15
|
const [drop, setDrop] = (0, react_1.useState)(null);
|
|
16
|
+
const [blockedReason, setBlockedReason] = (0, react_1.useState)(null);
|
|
16
17
|
const dropRef = (0, react_1.useRef)(null);
|
|
17
18
|
const sensors = (0, ps_core_components_1.usePsDragSensors)();
|
|
18
19
|
const runs = (0, react_1.useMemo)(() => enabled
|
|
@@ -88,6 +89,10 @@ const usePsTableReorder = ({ announcements: texts, enabled, instructions, items,
|
|
|
88
89
|
const handleDragMove = (event) => {
|
|
89
90
|
const next = resolveDrop(event);
|
|
90
91
|
dropRef.current = next;
|
|
92
|
+
const blocked = next === null && nesting !== undefined && nesting.getBlockedReason && event.over !== null
|
|
93
|
+
? nesting.getBlockedReason(String(event.active.id), String(event.over.id))
|
|
94
|
+
: null;
|
|
95
|
+
setBlockedReason(blocked);
|
|
91
96
|
setDrop((current) => current !== null &&
|
|
92
97
|
next !== null &&
|
|
93
98
|
current.overId === next.overId &&
|
|
@@ -100,6 +105,7 @@ const usePsTableReorder = ({ announcements: texts, enabled, instructions, items,
|
|
|
100
105
|
const target = resolveDrop(event);
|
|
101
106
|
setActiveId(null);
|
|
102
107
|
setDrop(null);
|
|
108
|
+
setBlockedReason(null);
|
|
103
109
|
dropRef.current = null;
|
|
104
110
|
if (nesting !== undefined) {
|
|
105
111
|
if (target !== null)
|
|
@@ -119,6 +125,7 @@ const usePsTableReorder = ({ announcements: texts, enabled, instructions, items,
|
|
|
119
125
|
};
|
|
120
126
|
return {
|
|
121
127
|
activeId,
|
|
128
|
+
blockedReason,
|
|
122
129
|
activeRunId: activePlacement === undefined ? null : activePlacement.runId,
|
|
123
130
|
contextProps: {
|
|
124
131
|
accessibility: { announcements, screenReaderInstructions: { draggable: instructions } },
|
|
@@ -127,6 +134,7 @@ const usePsTableReorder = ({ announcements: texts, enabled, instructions, items,
|
|
|
127
134
|
onDragCancel: () => {
|
|
128
135
|
setActiveId(null);
|
|
129
136
|
setDrop(null);
|
|
137
|
+
setBlockedReason(null);
|
|
130
138
|
dropRef.current = null;
|
|
131
139
|
},
|
|
132
140
|
onDragEnd: handleDragEnd,
|
|
@@ -14,6 +14,8 @@ export interface PsTableColumn<RowData> {
|
|
|
14
14
|
hideOnCards?: boolean;
|
|
15
15
|
id: string;
|
|
16
16
|
label: string;
|
|
17
|
+
/** Formatted text of the cell (for example the money string). The column is widened to fit the longest value, so numbers never truncate. */
|
|
18
|
+
measure?: (row: RowData) => string;
|
|
17
19
|
minWidth?: string;
|
|
18
20
|
pinEnd?: boolean;
|
|
19
21
|
render: (row: RowData) => ReactNode;
|
|
@@ -3,6 +3,7 @@ import type { PsTableNestingAnnouncements } from './table-nesting-announcements'
|
|
|
3
3
|
export interface PsTableReorderNestingBinding {
|
|
4
4
|
announcements: PsTableNestingAnnouncements;
|
|
5
5
|
canDrag: (id: string) => boolean;
|
|
6
|
+
getBlockedReason?: (activeId: string, targetId: string) => string | null;
|
|
6
7
|
canDrop: (activeId: string, targetId: string, placement: PsTableDropPlacement) => boolean;
|
|
7
8
|
onMove: (activeId: string, targetId: string, placement: PsTableDropPlacement) => void;
|
|
8
9
|
}
|
|
@@ -3,6 +3,7 @@ import type { PsTableNestingAnnouncements } from './table-nesting-announcements'
|
|
|
3
3
|
export interface PsTableReorderNesting<RowData> {
|
|
4
4
|
announcements: PsTableNestingAnnouncements;
|
|
5
5
|
canDrag: (row: RowData) => boolean;
|
|
6
|
+
getBlockedReason?: (active: RowData, target: RowData) => string | null;
|
|
6
7
|
canDrop: (active: RowData, target: RowData, placement: PsTableDropPlacement) => boolean;
|
|
7
8
|
onMove: (active: RowData, target: RowData, placement: PsTableDropPlacement) => void;
|
|
8
9
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { PsTableColumnSize } from '../constants/table-column-size';
|
|
2
2
|
import type { PsTableColumn } from '../interfaces/table-column';
|
|
3
3
|
export declare class PsTableColumnSizeService {
|
|
4
|
+
static fittedMinWidthOf<RowData>(column: PsTableColumn<RowData>, rows: RowData[]): string | undefined;
|
|
4
5
|
static sizeOf<RowData>(column: PsTableColumn<RowData>): PsTableColumnSize;
|
|
5
6
|
static minWidthOf<RowData>(column: PsTableColumn<RowData>): string;
|
|
6
7
|
static maxWidthOf<RowData>(column: PsTableColumn<RowData>): string | undefined;
|
|
@@ -4,6 +4,13 @@ exports.PsTableColumnSizeService = void 0;
|
|
|
4
4
|
const table_column_size_1 = require("../constants/table-column-size");
|
|
5
5
|
const table_filter_kind_1 = require("../constants/table-filter-kind");
|
|
6
6
|
class PsTableColumnSizeService {
|
|
7
|
+
static fittedMinWidthOf(column, rows) {
|
|
8
|
+
const measure = column.measure;
|
|
9
|
+
if (measure === undefined)
|
|
10
|
+
return undefined;
|
|
11
|
+
const longest = rows.reduce((length, row) => Math.max(length, measure(row).length), 0);
|
|
12
|
+
return `max(${PsTableColumnSizeService.minWidthOf(column)}, calc(${(longest * 1.1).toFixed(1)}ch + 3rem))`;
|
|
13
|
+
}
|
|
7
14
|
static sizeOf(column) {
|
|
8
15
|
if (column.size !== undefined)
|
|
9
16
|
return column.size;
|