@pallasoft/ps-table-components 1.24.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.
@@ -201,6 +201,15 @@ const PsDataTable = ({ caption, className, columns, defaultSort, density = 'norm
201
201
  const target = find(targetId);
202
202
  return (active !== undefined && target !== undefined && nesting.canDrop(active, target, placement));
203
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
+ },
204
213
  onMove: (activeId, targetId, placement) => {
205
214
  const active = find(activeId);
206
215
  const target = find(targetId);
@@ -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;
@@ -165,6 +165,15 @@ export const PsDataTable = ({ caption, className, columns, defaultSort, density
165
165
  const target = find(targetId);
166
166
  return (active !== undefined && target !== undefined && nesting.canDrop(active, target, placement));
167
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
+ },
168
177
  onMove: (activeId, targetId, placement) => {
169
178
  const active = find(activeId);
170
179
  const target = find(targetId);
@@ -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,
@@ -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,
@@ -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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pallasoft/ps-table-components",
3
- "version": "1.24.0",
3
+ "version": "1.25.0",
4
4
  "private": false,
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/esm/index.js",