@pallasoft/ps-core-components 2.44.1 → 2.45.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-drag-overlay.js +8 -5
- package/dist/components/ps-draggable-grid.js +3 -1
- package/dist/components/ps-sortable-list.js +5 -5
- package/dist/constants/ps-drag-config.d.ts +3 -0
- package/dist/constants/ps-drag-config.js +10 -4
- package/dist/constants/ps-draggable-grid.d.ts +2 -0
- package/dist/esm/components/ps-drag-overlay.js +9 -6
- package/dist/esm/components/ps-draggable-grid.js +3 -1
- package/dist/esm/components/ps-sortable-list.js +6 -6
- package/dist/esm/constants/ps-drag-config.js +9 -3
- package/dist/esm/hooks/use-ps-drag-sensors.js +2 -2
- package/dist/esm/hooks/use-ps-drag-transition.js +10 -0
- package/dist/esm/hooks/use-ps-list-keys.js +17 -0
- package/dist/esm/index.js +5 -0
- package/dist/esm/interfaces/ps-list-keys-result.js +1 -0
- package/dist/esm/models/ps-drag-transition.js +1 -0
- package/dist/esm/services/ps-list-key-service.js +20 -0
- package/dist/hooks/use-ps-drag-sensors.d.ts +2 -2
- package/dist/hooks/use-ps-drag-sensors.js +2 -2
- package/dist/hooks/use-ps-drag-transition.d.ts +2 -0
- package/dist/hooks/use-ps-drag-transition.js +14 -0
- package/dist/hooks/use-ps-list-keys.d.ts +2 -0
- package/dist/hooks/use-ps-list-keys.js +21 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +5 -0
- package/dist/interfaces/ps-list-keys-result.d.ts +5 -0
- package/dist/interfaces/ps-list-keys-result.js +2 -0
- package/dist/models/ps-drag-transition.d.ts +4 -0
- package/dist/models/ps-drag-transition.js +2 -0
- package/dist/services/ps-list-key-service.d.ts +5 -0
- package/dist/services/ps-list-key-service.js +24 -0
- package/package.json +1 -1
|
@@ -4,8 +4,10 @@ exports.PsDragOverlay = void 0;
|
|
|
4
4
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
5
|
const react_1 = require("react");
|
|
6
6
|
const core_1 = require("@dnd-kit/core");
|
|
7
|
+
const ps_design_system_1 = require("@pallasoft/ps-design-system");
|
|
7
8
|
const react_dom_1 = require("react-dom");
|
|
8
9
|
const ps_drag_config_1 = require("../constants/ps-drag-config");
|
|
10
|
+
const use_ps_layer_z_index_1 = require("../hooks/use-ps-layer-z-index");
|
|
9
11
|
const use_ps_reduced_motion_1 = require("../hooks/use-ps-reduced-motion");
|
|
10
12
|
const dropAnimation = {
|
|
11
13
|
duration: ps_drag_config_1.PsDragConfig.dropDuration,
|
|
@@ -17,10 +19,9 @@ const dropAnimation = {
|
|
|
17
19
|
const PsDragOverlay = ({ children, className, frames, isDropAnimated, }) => {
|
|
18
20
|
const [isMounted, setIsMounted] = (0, react_1.useState)(false);
|
|
19
21
|
const isReduced = (0, use_ps_reduced_motion_1.usePsReducedMotion)();
|
|
22
|
+
const zIndex = (0, use_ps_layer_z_index_1.usePsLayerZIndex)(ps_design_system_1.PallasoftZIndex.Popover);
|
|
20
23
|
(0, react_1.useEffect)(() => setIsMounted(true), []);
|
|
21
|
-
|
|
22
|
-
return null;
|
|
23
|
-
const lift = (element) => {
|
|
24
|
+
const lift = (0, react_1.useCallback)((element) => {
|
|
24
25
|
if (element === null || isReduced || typeof element.animate !== 'function')
|
|
25
26
|
return;
|
|
26
27
|
element.animate(frames, {
|
|
@@ -28,7 +29,9 @@ const PsDragOverlay = ({ children, className, frames, isDropAnimated, }) => {
|
|
|
28
29
|
easing: ps_drag_config_1.PsDragConfig.liftEasing,
|
|
29
30
|
fill: 'forwards',
|
|
30
31
|
});
|
|
31
|
-
};
|
|
32
|
-
|
|
32
|
+
}, [frames, isReduced]);
|
|
33
|
+
if (!isMounted)
|
|
34
|
+
return null;
|
|
35
|
+
return (0, react_dom_1.createPortal)((0, jsx_runtime_1.jsx)(core_1.DragOverlay, { dropAnimation: isReduced || isDropAnimated === false ? null : dropAnimation, zIndex: zIndex, children: children === null ? null : ((0, jsx_runtime_1.jsx)("div", { className: className, ref: lift, children: children })) }), document.body);
|
|
33
36
|
};
|
|
34
37
|
exports.PsDragOverlay = PsDragOverlay;
|
|
@@ -9,11 +9,13 @@ const utilities_1 = require("@dnd-kit/utilities");
|
|
|
9
9
|
const ps_drag_config_1 = require("../constants/ps-drag-config");
|
|
10
10
|
const ps_draggable_grid_1 = require("../constants/ps-draggable-grid");
|
|
11
11
|
const use_ps_drag_sensors_1 = require("../hooks/use-ps-drag-sensors");
|
|
12
|
+
const use_ps_drag_transition_1 = require("../hooks/use-ps-drag-transition");
|
|
12
13
|
const ps_drag_grip_1 = require("./ps-drag-grip");
|
|
13
14
|
const ps_drag_overlay_1 = require("./ps-drag-overlay");
|
|
14
15
|
const PsDraggableGridHandle = ({ attributes, label, listeners, setActivatorNodeRef, }) => ((0, jsx_runtime_1.jsx)("button", { ...attributes, ...listeners, "aria-label": `Move ${label}`, className: ps_draggable_grid_1.PsDraggableGridClasses.handle, ref: setActivatorNodeRef, title: `Move ${label}`, type: 'button', children: (0, jsx_runtime_1.jsx)(ps_drag_grip_1.PsDragGrip, {}) }));
|
|
15
16
|
const PsSortableGridItem = ({ className, index, item, renderItem, }) => {
|
|
16
|
-
const
|
|
17
|
+
const dragTransition = (0, use_ps_drag_transition_1.usePsDragTransition)();
|
|
18
|
+
const { attributes, isDragging, listeners, setActivatorNodeRef, setNodeRef, transform, transition, } = (0, sortable_1.useSortable)({ id: item.id, transition: dragTransition });
|
|
17
19
|
const rendered = renderItem({
|
|
18
20
|
handle: ((0, jsx_runtime_1.jsx)(PsDraggableGridHandle, { attributes: attributes, label: item.label, listeners: listeners, setActivatorNodeRef: setActivatorNodeRef })),
|
|
19
21
|
index,
|
|
@@ -8,13 +8,13 @@ const sortable_1 = require("@dnd-kit/sortable");
|
|
|
8
8
|
const utilities_1 = require("@dnd-kit/utilities");
|
|
9
9
|
const ps_drag_config_1 = require("../constants/ps-drag-config");
|
|
10
10
|
const use_ps_drag_sensors_1 = require("../hooks/use-ps-drag-sensors");
|
|
11
|
-
const
|
|
11
|
+
const use_ps_drag_transition_1 = require("../hooks/use-ps-drag-transition");
|
|
12
12
|
const ps_drag_grip_1 = require("./ps-drag-grip");
|
|
13
13
|
const ps_drag_overlay_1 = require("./ps-drag-overlay");
|
|
14
14
|
const PsSortableListHandle = ({ attributes, className, icon, label, listeners, setActivatorNodeRef, }) => ((0, jsx_runtime_1.jsx)("button", { ...attributes, ...listeners, "aria-label": label, className: className === undefined ? ps_drag_config_1.PsDragClasses.handle : className, ref: setActivatorNodeRef, title: label, type: 'button', children: icon === undefined ? (0, jsx_runtime_1.jsx)(ps_drag_grip_1.PsDragGrip, {}) : icon }));
|
|
15
15
|
const PsSortableListRow = ({ className, handleClassName, handleIcon, getHandleLabel, index, isDisabled, item, renderItem, }) => {
|
|
16
|
-
const
|
|
17
|
-
const { attributes, isDragging, listeners, setActivatorNodeRef, setNodeRef, transform, transition, } = (0, sortable_1.useSortable)({ disabled: isDisabled, id: item.id });
|
|
16
|
+
const dragTransition = (0, use_ps_drag_transition_1.usePsDragTransition)();
|
|
17
|
+
const { attributes, isDragging, listeners, setActivatorNodeRef, setNodeRef, transform, transition, } = (0, sortable_1.useSortable)({ disabled: isDisabled, id: item.id, transition: dragTransition });
|
|
18
18
|
const rendered = renderItem({
|
|
19
19
|
handle: ((0, jsx_runtime_1.jsx)(PsSortableListHandle, { attributes: attributes, className: handleClassName, icon: handleIcon, label: getHandleLabel(item.label), listeners: listeners, setActivatorNodeRef: setActivatorNodeRef })),
|
|
20
20
|
index,
|
|
@@ -27,7 +27,7 @@ const PsSortableListRow = ({ className, handleClassName, handleIcon, getHandleLa
|
|
|
27
27
|
return ((0, jsx_runtime_1.jsx)("div", { className: `${ps_drag_config_1.PsDragClasses.listItem} ${className} ${isDragging ? ps_drag_config_1.PsDragClasses.placeholder : ''}`, ref: setNodeRef, style: {
|
|
28
28
|
opacity: isDragging ? ps_drag_config_1.PsDragConfig.placeholderOpacity : undefined,
|
|
29
29
|
transform: utilities_1.CSS.Translate.toString(transform),
|
|
30
|
-
transition
|
|
30
|
+
transition,
|
|
31
31
|
}, children: rendered }));
|
|
32
32
|
};
|
|
33
33
|
const PsSortableList = ({ announcements: texts, className, getHandleLabel, getItemClassName, handleClassName, handleIcon, instructions, isHorizontal = false, role, items, onMove, renderItem, }) => {
|
|
@@ -66,7 +66,7 @@ const PsSortableList = ({ announcements: texts, className, getHandleLabel, getIt
|
|
|
66
66
|
onMove(String(active.id), from, to);
|
|
67
67
|
};
|
|
68
68
|
const activeGroup = activeItem === null ? undefined : activeItem.groupKey;
|
|
69
|
-
return ((0, jsx_runtime_1.jsxs)(core_1.DndContext, { accessibility: { announcements, screenReaderInstructions: { draggable: instructions } }, collisionDetection: core_1.closestCenter, onDragCancel: () => setActiveId(null), onDragEnd: handleDragEnd, onDragStart: ({ active }) => setActiveId(String(active.id)), sensors: sensors, children: [(0, jsx_runtime_1.jsx)(sortable_1.SortableContext, { items: items.map((item) => item.id), strategy: isHorizontal ? sortable_1.horizontalListSortingStrategy : sortable_1.verticalListSortingStrategy, children: (0, jsx_runtime_1.jsx)("div", { className: className, role: role, children: items.map((item, index) => ((0, jsx_runtime_1.jsx)(PsSortableListRow, { className: itemClassName(item), getHandleLabel: getHandleLabel, handleClassName: handleClassName, handleIcon: handleIcon, index: index, isDisabled: activeItem !== null && item.groupKey !== activeGroup, item: item, renderItem: renderItem }, item.id))) }) }), (0, jsx_runtime_1.jsx)(ps_drag_overlay_1.PsDragOverlay, { className: ps_drag_config_1.PsDragClasses.lifted, frames: ps_drag_config_1.
|
|
69
|
+
return ((0, jsx_runtime_1.jsxs)(core_1.DndContext, { accessibility: { announcements, screenReaderInstructions: { draggable: instructions } }, collisionDetection: core_1.closestCenter, onDragCancel: () => setActiveId(null), onDragEnd: handleDragEnd, onDragStart: ({ active }) => setActiveId(String(active.id)), sensors: sensors, children: [(0, jsx_runtime_1.jsx)(sortable_1.SortableContext, { items: items.map((item) => item.id), strategy: isHorizontal ? sortable_1.horizontalListSortingStrategy : sortable_1.verticalListSortingStrategy, children: (0, jsx_runtime_1.jsx)("div", { className: className, role: role, children: items.map((item, index) => ((0, jsx_runtime_1.jsx)(PsSortableListRow, { className: itemClassName(item), getHandleLabel: getHandleLabel, handleClassName: handleClassName, handleIcon: handleIcon, index: index, isDisabled: activeItem !== null && item.groupKey !== activeGroup, item: item, renderItem: renderItem }, item.id))) }) }), (0, jsx_runtime_1.jsx)(ps_drag_overlay_1.PsDragOverlay, { className: ps_drag_config_1.PsDragClasses.lifted, frames: ps_drag_config_1.PsDragRowLiftFrames, children: activeItem !== null
|
|
70
70
|
? renderItem({
|
|
71
71
|
handle: ((0, jsx_runtime_1.jsx)(PsSortableListHandle, { className: handleClassName, icon: handleIcon, label: getHandleLabel(activeItem.label) })),
|
|
72
72
|
index: activeIndex,
|
|
@@ -5,6 +5,8 @@ export declare const PsDragConfig: {
|
|
|
5
5
|
readonly liftDuration: 200;
|
|
6
6
|
readonly liftEasing: "cubic-bezier(0.2, 0.9, 0.3, 1.2)";
|
|
7
7
|
readonly placeholderOpacity: "0.4";
|
|
8
|
+
readonly sortDuration: 250;
|
|
9
|
+
readonly sortEasing: "ease";
|
|
8
10
|
readonly touchDelay: 180;
|
|
9
11
|
readonly touchTolerance: 6;
|
|
10
12
|
};
|
|
@@ -15,4 +17,5 @@ export declare const PsDragClasses: {
|
|
|
15
17
|
readonly placeholder: "outline-dashed outline-2 outline-offset-[-2px] outline-primary/35";
|
|
16
18
|
};
|
|
17
19
|
export declare const PsDragLiftFrames: Keyframe[];
|
|
20
|
+
export declare const PsDragRowLiftFrames: Keyframe[];
|
|
18
21
|
export declare const PsDragListLiftFrames: Keyframe[];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PsDragListLiftFrames = exports.PsDragLiftFrames = exports.PsDragClasses = exports.PsDragConfig = void 0;
|
|
3
|
+
exports.PsDragListLiftFrames = exports.PsDragRowLiftFrames = exports.PsDragLiftFrames = exports.PsDragClasses = exports.PsDragConfig = void 0;
|
|
4
4
|
exports.PsDragConfig = {
|
|
5
5
|
activationDistance: 6,
|
|
6
6
|
dropDuration: 220,
|
|
@@ -8,6 +8,8 @@ exports.PsDragConfig = {
|
|
|
8
8
|
liftDuration: 200,
|
|
9
9
|
liftEasing: 'cubic-bezier(0.2, 0.9, 0.3, 1.2)',
|
|
10
10
|
placeholderOpacity: '0.4',
|
|
11
|
+
sortDuration: 250,
|
|
12
|
+
sortEasing: 'ease',
|
|
11
13
|
touchDelay: 180,
|
|
12
14
|
touchTolerance: 6,
|
|
13
15
|
};
|
|
@@ -24,7 +26,11 @@ exports.PsDragLiftFrames = [
|
|
|
24
26
|
transform: 'scale(1.035) rotate(-1.2deg)',
|
|
25
27
|
},
|
|
26
28
|
];
|
|
27
|
-
exports.
|
|
28
|
-
{ boxShadow: '0 0 0 0 rgb(15 23 42 / 0)', transform: 'scale(1)' },
|
|
29
|
-
{
|
|
29
|
+
exports.PsDragRowLiftFrames = [
|
|
30
|
+
{ boxShadow: '0 0 0 0 rgb(15 23 42 / 0)', transform: 'scale(1) rotate(0deg)' },
|
|
31
|
+
{
|
|
32
|
+
boxShadow: '0 28px 64px -18px rgb(15 23 42 / 0.5)',
|
|
33
|
+
transform: 'scale(1.035) rotate(-0.25deg)',
|
|
34
|
+
},
|
|
30
35
|
];
|
|
36
|
+
exports.PsDragListLiftFrames = exports.PsDragRowLiftFrames;
|
|
@@ -5,6 +5,8 @@ export declare const PsDraggableGridConfig: {
|
|
|
5
5
|
readonly liftDuration: 200;
|
|
6
6
|
readonly liftEasing: "cubic-bezier(0.2, 0.9, 0.3, 1.2)";
|
|
7
7
|
readonly placeholderOpacity: "0.4";
|
|
8
|
+
readonly sortDuration: 250;
|
|
9
|
+
readonly sortEasing: "ease";
|
|
8
10
|
readonly touchDelay: 180;
|
|
9
11
|
readonly touchTolerance: 6;
|
|
10
12
|
};
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { useEffect, useState } from 'react';
|
|
2
|
+
import { useCallback, useEffect, useState } from 'react';
|
|
3
3
|
import { DragOverlay, defaultDropAnimationSideEffects } from '@dnd-kit/core';
|
|
4
|
+
import { PallasoftZIndex } from '@pallasoft/ps-design-system';
|
|
4
5
|
import { createPortal } from 'react-dom';
|
|
5
6
|
import { PsDragConfig } from '../constants/ps-drag-config.js';
|
|
7
|
+
import { usePsLayerZIndex } from '../hooks/use-ps-layer-z-index.js';
|
|
6
8
|
import { usePsReducedMotion } from '../hooks/use-ps-reduced-motion.js';
|
|
7
9
|
const dropAnimation = {
|
|
8
10
|
duration: PsDragConfig.dropDuration,
|
|
@@ -14,10 +16,9 @@ const dropAnimation = {
|
|
|
14
16
|
export const PsDragOverlay = ({ children, className, frames, isDropAnimated, }) => {
|
|
15
17
|
const [isMounted, setIsMounted] = useState(false);
|
|
16
18
|
const isReduced = usePsReducedMotion();
|
|
19
|
+
const zIndex = usePsLayerZIndex(PallasoftZIndex.Popover);
|
|
17
20
|
useEffect(() => setIsMounted(true), []);
|
|
18
|
-
|
|
19
|
-
return null;
|
|
20
|
-
const lift = (element) => {
|
|
21
|
+
const lift = useCallback((element) => {
|
|
21
22
|
if (element === null || isReduced || typeof element.animate !== 'function')
|
|
22
23
|
return;
|
|
23
24
|
element.animate(frames, {
|
|
@@ -25,6 +26,8 @@ export const PsDragOverlay = ({ children, className, frames, isDropAnimated, })
|
|
|
25
26
|
easing: PsDragConfig.liftEasing,
|
|
26
27
|
fill: 'forwards',
|
|
27
28
|
});
|
|
28
|
-
};
|
|
29
|
-
|
|
29
|
+
}, [frames, isReduced]);
|
|
30
|
+
if (!isMounted)
|
|
31
|
+
return null;
|
|
32
|
+
return createPortal(_jsx(DragOverlay, { dropAnimation: isReduced || isDropAnimated === false ? null : dropAnimation, zIndex: zIndex, children: children === null ? null : (_jsx("div", { className: className, ref: lift, children: children })) }), document.body);
|
|
30
33
|
};
|
|
@@ -6,11 +6,13 @@ import { CSS } from '@dnd-kit/utilities';
|
|
|
6
6
|
import { PsDragConfig } from '../constants/ps-drag-config.js';
|
|
7
7
|
import { PsDraggableGridClasses, PsDraggableGridLiftFrames } from '../constants/ps-draggable-grid.js';
|
|
8
8
|
import { usePsDragSensors } from '../hooks/use-ps-drag-sensors.js';
|
|
9
|
+
import { usePsDragTransition } from '../hooks/use-ps-drag-transition.js';
|
|
9
10
|
import { PsDragGrip } from './ps-drag-grip.js';
|
|
10
11
|
import { PsDragOverlay } from './ps-drag-overlay.js';
|
|
11
12
|
const PsDraggableGridHandle = ({ attributes, label, listeners, setActivatorNodeRef, }) => (_jsx("button", { ...attributes, ...listeners, "aria-label": `Move ${label}`, className: PsDraggableGridClasses.handle, ref: setActivatorNodeRef, title: `Move ${label}`, type: 'button', children: _jsx(PsDragGrip, {}) }));
|
|
12
13
|
const PsSortableGridItem = ({ className, index, item, renderItem, }) => {
|
|
13
|
-
const
|
|
14
|
+
const dragTransition = usePsDragTransition();
|
|
15
|
+
const { attributes, isDragging, listeners, setActivatorNodeRef, setNodeRef, transform, transition, } = useSortable({ id: item.id, transition: dragTransition });
|
|
14
16
|
const rendered = renderItem({
|
|
15
17
|
handle: (_jsx(PsDraggableGridHandle, { attributes: attributes, label: item.label, listeners: listeners, setActivatorNodeRef: setActivatorNodeRef })),
|
|
16
18
|
index,
|
|
@@ -3,15 +3,15 @@ import { useState } from 'react';
|
|
|
3
3
|
import { DndContext, closestCenter, } from '@dnd-kit/core';
|
|
4
4
|
import { SortableContext, horizontalListSortingStrategy, useSortable, verticalListSortingStrategy, } from '@dnd-kit/sortable';
|
|
5
5
|
import { CSS } from '@dnd-kit/utilities';
|
|
6
|
-
import { PsDragClasses, PsDragConfig,
|
|
6
|
+
import { PsDragClasses, PsDragConfig, PsDragRowLiftFrames } from '../constants/ps-drag-config.js';
|
|
7
7
|
import { usePsDragSensors } from '../hooks/use-ps-drag-sensors.js';
|
|
8
|
-
import {
|
|
8
|
+
import { usePsDragTransition } from '../hooks/use-ps-drag-transition.js';
|
|
9
9
|
import { PsDragGrip } from './ps-drag-grip.js';
|
|
10
10
|
import { PsDragOverlay } from './ps-drag-overlay.js';
|
|
11
11
|
const PsSortableListHandle = ({ attributes, className, icon, label, listeners, setActivatorNodeRef, }) => (_jsx("button", { ...attributes, ...listeners, "aria-label": label, className: className === undefined ? PsDragClasses.handle : className, ref: setActivatorNodeRef, title: label, type: 'button', children: icon === undefined ? _jsx(PsDragGrip, {}) : icon }));
|
|
12
12
|
const PsSortableListRow = ({ className, handleClassName, handleIcon, getHandleLabel, index, isDisabled, item, renderItem, }) => {
|
|
13
|
-
const
|
|
14
|
-
const { attributes, isDragging, listeners, setActivatorNodeRef, setNodeRef, transform, transition, } = useSortable({ disabled: isDisabled, id: item.id });
|
|
13
|
+
const dragTransition = usePsDragTransition();
|
|
14
|
+
const { attributes, isDragging, listeners, setActivatorNodeRef, setNodeRef, transform, transition, } = useSortable({ disabled: isDisabled, id: item.id, transition: dragTransition });
|
|
15
15
|
const rendered = renderItem({
|
|
16
16
|
handle: (_jsx(PsSortableListHandle, { attributes: attributes, className: handleClassName, icon: handleIcon, label: getHandleLabel(item.label), listeners: listeners, setActivatorNodeRef: setActivatorNodeRef })),
|
|
17
17
|
index,
|
|
@@ -24,7 +24,7 @@ const PsSortableListRow = ({ className, handleClassName, handleIcon, getHandleLa
|
|
|
24
24
|
return (_jsx("div", { className: `${PsDragClasses.listItem} ${className} ${isDragging ? PsDragClasses.placeholder : ''}`, ref: setNodeRef, style: {
|
|
25
25
|
opacity: isDragging ? PsDragConfig.placeholderOpacity : undefined,
|
|
26
26
|
transform: CSS.Translate.toString(transform),
|
|
27
|
-
transition
|
|
27
|
+
transition,
|
|
28
28
|
}, children: rendered }));
|
|
29
29
|
};
|
|
30
30
|
export const PsSortableList = ({ announcements: texts, className, getHandleLabel, getItemClassName, handleClassName, handleIcon, instructions, isHorizontal = false, role, items, onMove, renderItem, }) => {
|
|
@@ -63,7 +63,7 @@ export const PsSortableList = ({ announcements: texts, className, getHandleLabel
|
|
|
63
63
|
onMove(String(active.id), from, to);
|
|
64
64
|
};
|
|
65
65
|
const activeGroup = activeItem === null ? undefined : activeItem.groupKey;
|
|
66
|
-
return (_jsxs(DndContext, { accessibility: { announcements, screenReaderInstructions: { draggable: instructions } }, collisionDetection: closestCenter, onDragCancel: () => setActiveId(null), onDragEnd: handleDragEnd, onDragStart: ({ active }) => setActiveId(String(active.id)), sensors: sensors, children: [_jsx(SortableContext, { items: items.map((item) => item.id), strategy: isHorizontal ? horizontalListSortingStrategy : verticalListSortingStrategy, children: _jsx("div", { className: className, role: role, children: items.map((item, index) => (_jsx(PsSortableListRow, { className: itemClassName(item), getHandleLabel: getHandleLabel, handleClassName: handleClassName, handleIcon: handleIcon, index: index, isDisabled: activeItem !== null && item.groupKey !== activeGroup, item: item, renderItem: renderItem }, item.id))) }) }), _jsx(PsDragOverlay, { className: PsDragClasses.lifted, frames:
|
|
66
|
+
return (_jsxs(DndContext, { accessibility: { announcements, screenReaderInstructions: { draggable: instructions } }, collisionDetection: closestCenter, onDragCancel: () => setActiveId(null), onDragEnd: handleDragEnd, onDragStart: ({ active }) => setActiveId(String(active.id)), sensors: sensors, children: [_jsx(SortableContext, { items: items.map((item) => item.id), strategy: isHorizontal ? horizontalListSortingStrategy : verticalListSortingStrategy, children: _jsx("div", { className: className, role: role, children: items.map((item, index) => (_jsx(PsSortableListRow, { className: itemClassName(item), getHandleLabel: getHandleLabel, handleClassName: handleClassName, handleIcon: handleIcon, index: index, isDisabled: activeItem !== null && item.groupKey !== activeGroup, item: item, renderItem: renderItem }, item.id))) }) }), _jsx(PsDragOverlay, { className: PsDragClasses.lifted, frames: PsDragRowLiftFrames, children: activeItem !== null
|
|
67
67
|
? renderItem({
|
|
68
68
|
handle: (_jsx(PsSortableListHandle, { className: handleClassName, icon: handleIcon, label: getHandleLabel(activeItem.label) })),
|
|
69
69
|
index: activeIndex,
|
|
@@ -5,6 +5,8 @@ export const PsDragConfig = {
|
|
|
5
5
|
liftDuration: 200,
|
|
6
6
|
liftEasing: 'cubic-bezier(0.2, 0.9, 0.3, 1.2)',
|
|
7
7
|
placeholderOpacity: '0.4',
|
|
8
|
+
sortDuration: 250,
|
|
9
|
+
sortEasing: 'ease',
|
|
8
10
|
touchDelay: 180,
|
|
9
11
|
touchTolerance: 6,
|
|
10
12
|
};
|
|
@@ -21,7 +23,11 @@ export const PsDragLiftFrames = [
|
|
|
21
23
|
transform: 'scale(1.035) rotate(-1.2deg)',
|
|
22
24
|
},
|
|
23
25
|
];
|
|
24
|
-
export const
|
|
25
|
-
{ boxShadow: '0 0 0 0 rgb(15 23 42 / 0)', transform: 'scale(1)' },
|
|
26
|
-
{
|
|
26
|
+
export const PsDragRowLiftFrames = [
|
|
27
|
+
{ boxShadow: '0 0 0 0 rgb(15 23 42 / 0)', transform: 'scale(1) rotate(0deg)' },
|
|
28
|
+
{
|
|
29
|
+
boxShadow: '0 28px 64px -18px rgb(15 23 42 / 0.5)',
|
|
30
|
+
transform: 'scale(1.035) rotate(-0.25deg)',
|
|
31
|
+
},
|
|
27
32
|
];
|
|
33
|
+
export const PsDragListLiftFrames = PsDragRowLiftFrames;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { KeyboardSensor, MouseSensor, TouchSensor, useSensor, useSensors, } from '@dnd-kit/core';
|
|
2
2
|
import { sortableKeyboardCoordinates } from '@dnd-kit/sortable';
|
|
3
3
|
import { PsDragConfig } from '../constants/ps-drag-config.js';
|
|
4
|
-
export const usePsDragSensors = () => useSensors(useSensor(MouseSensor, {
|
|
4
|
+
export const usePsDragSensors = (coordinateGetter = sortableKeyboardCoordinates) => useSensors(useSensor(MouseSensor, {
|
|
5
5
|
activationConstraint: { distance: PsDragConfig.activationDistance },
|
|
6
6
|
}), useSensor(TouchSensor, {
|
|
7
7
|
activationConstraint: {
|
|
8
8
|
delay: PsDragConfig.touchDelay,
|
|
9
9
|
tolerance: PsDragConfig.touchTolerance,
|
|
10
10
|
},
|
|
11
|
-
}), useSensor(KeyboardSensor, { coordinateGetter
|
|
11
|
+
}), useSensor(KeyboardSensor, { coordinateGetter }));
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { PsDragConfig } from '../constants/ps-drag-config.js';
|
|
2
|
+
import { usePsReducedMotion } from './use-ps-reduced-motion.js';
|
|
3
|
+
const transition = {
|
|
4
|
+
duration: PsDragConfig.sortDuration,
|
|
5
|
+
easing: PsDragConfig.sortEasing,
|
|
6
|
+
};
|
|
7
|
+
export const usePsDragTransition = () => {
|
|
8
|
+
const isReduced = usePsReducedMotion();
|
|
9
|
+
return isReduced ? null : transition;
|
|
10
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { useCallback, useId, useRef, useState } from 'react';
|
|
2
|
+
import { PsListKeyService } from '../services/ps-list-key-service.js';
|
|
3
|
+
export const usePsListKeys = (count) => {
|
|
4
|
+
const prefix = useId();
|
|
5
|
+
const created = useRef(0);
|
|
6
|
+
const create = useCallback(() => {
|
|
7
|
+
created.current += 1;
|
|
8
|
+
return `${prefix}-${created.current}`;
|
|
9
|
+
}, [prefix]);
|
|
10
|
+
const [keys, setKeys] = useState(() => PsListKeyService.fit([], count, create));
|
|
11
|
+
const fitted = PsListKeyService.fit(keys, count, create);
|
|
12
|
+
if (fitted !== keys)
|
|
13
|
+
setKeys(fitted);
|
|
14
|
+
const move = useCallback((from, to) => setKeys((current) => PsListKeyService.move(current, from, to)), []);
|
|
15
|
+
const remove = useCallback((index) => setKeys((current) => PsListKeyService.remove(current, index)), []);
|
|
16
|
+
return { keys: fitted, move, remove };
|
|
17
|
+
};
|
package/dist/esm/index.js
CHANGED
|
@@ -188,6 +188,11 @@ export * from './models/ps-summary-item.js';
|
|
|
188
188
|
export * from './components/ps-drag-grip.js';
|
|
189
189
|
export * from './components/ps-drag-overlay.js';
|
|
190
190
|
export * from './hooks/use-ps-drag-sensors.js';
|
|
191
|
+
export * from './hooks/use-ps-drag-transition.js';
|
|
192
|
+
export * from './models/ps-drag-transition.js';
|
|
193
|
+
export * from './hooks/use-ps-list-keys.js';
|
|
194
|
+
export * from './interfaces/ps-list-keys-result.js';
|
|
195
|
+
export * from './services/ps-list-key-service.js';
|
|
191
196
|
export * from './hooks/use-ps-reduced-motion.js';
|
|
192
197
|
export * from './components/ps-divider.js';
|
|
193
198
|
export * from './models/ps-divider-orientation.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export class PsListKeyService {
|
|
2
|
+
static fit(keys, count, create) {
|
|
3
|
+
if (keys.length === count)
|
|
4
|
+
return keys;
|
|
5
|
+
if (keys.length > count)
|
|
6
|
+
return keys.slice(0, count);
|
|
7
|
+
return [...keys, ...Array.from({ length: count - keys.length }, create)];
|
|
8
|
+
}
|
|
9
|
+
static move(keys, from, to) {
|
|
10
|
+
if (from === to || from < 0 || to < 0 || from >= keys.length || to >= keys.length)
|
|
11
|
+
return keys;
|
|
12
|
+
const next = [...keys];
|
|
13
|
+
const [moved] = next.splice(from, 1);
|
|
14
|
+
next.splice(to, 0, moved);
|
|
15
|
+
return next;
|
|
16
|
+
}
|
|
17
|
+
static remove(keys, index) {
|
|
18
|
+
return index < 0 || index >= keys.length ? keys : keys.filter((_key, at) => at !== index);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { type SensorDescriptor, type SensorOptions } from '@dnd-kit/core';
|
|
2
|
-
export declare const usePsDragSensors: () => SensorDescriptor<SensorOptions>[];
|
|
1
|
+
import { type KeyboardCoordinateGetter, type SensorDescriptor, type SensorOptions } from '@dnd-kit/core';
|
|
2
|
+
export declare const usePsDragSensors: (coordinateGetter?: KeyboardCoordinateGetter) => SensorDescriptor<SensorOptions>[];
|
|
@@ -4,12 +4,12 @@ exports.usePsDragSensors = void 0;
|
|
|
4
4
|
const core_1 = require("@dnd-kit/core");
|
|
5
5
|
const sortable_1 = require("@dnd-kit/sortable");
|
|
6
6
|
const ps_drag_config_1 = require("../constants/ps-drag-config");
|
|
7
|
-
const usePsDragSensors = () => (0, core_1.useSensors)((0, core_1.useSensor)(core_1.MouseSensor, {
|
|
7
|
+
const usePsDragSensors = (coordinateGetter = sortable_1.sortableKeyboardCoordinates) => (0, core_1.useSensors)((0, core_1.useSensor)(core_1.MouseSensor, {
|
|
8
8
|
activationConstraint: { distance: ps_drag_config_1.PsDragConfig.activationDistance },
|
|
9
9
|
}), (0, core_1.useSensor)(core_1.TouchSensor, {
|
|
10
10
|
activationConstraint: {
|
|
11
11
|
delay: ps_drag_config_1.PsDragConfig.touchDelay,
|
|
12
12
|
tolerance: ps_drag_config_1.PsDragConfig.touchTolerance,
|
|
13
13
|
},
|
|
14
|
-
}), (0, core_1.useSensor)(core_1.KeyboardSensor, { coordinateGetter
|
|
14
|
+
}), (0, core_1.useSensor)(core_1.KeyboardSensor, { coordinateGetter }));
|
|
15
15
|
exports.usePsDragSensors = usePsDragSensors;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.usePsDragTransition = void 0;
|
|
4
|
+
const ps_drag_config_1 = require("../constants/ps-drag-config");
|
|
5
|
+
const use_ps_reduced_motion_1 = require("./use-ps-reduced-motion");
|
|
6
|
+
const transition = {
|
|
7
|
+
duration: ps_drag_config_1.PsDragConfig.sortDuration,
|
|
8
|
+
easing: ps_drag_config_1.PsDragConfig.sortEasing,
|
|
9
|
+
};
|
|
10
|
+
const usePsDragTransition = () => {
|
|
11
|
+
const isReduced = (0, use_ps_reduced_motion_1.usePsReducedMotion)();
|
|
12
|
+
return isReduced ? null : transition;
|
|
13
|
+
};
|
|
14
|
+
exports.usePsDragTransition = usePsDragTransition;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.usePsListKeys = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const ps_list_key_service_1 = require("../services/ps-list-key-service");
|
|
6
|
+
const usePsListKeys = (count) => {
|
|
7
|
+
const prefix = (0, react_1.useId)();
|
|
8
|
+
const created = (0, react_1.useRef)(0);
|
|
9
|
+
const create = (0, react_1.useCallback)(() => {
|
|
10
|
+
created.current += 1;
|
|
11
|
+
return `${prefix}-${created.current}`;
|
|
12
|
+
}, [prefix]);
|
|
13
|
+
const [keys, setKeys] = (0, react_1.useState)(() => ps_list_key_service_1.PsListKeyService.fit([], count, create));
|
|
14
|
+
const fitted = ps_list_key_service_1.PsListKeyService.fit(keys, count, create);
|
|
15
|
+
if (fitted !== keys)
|
|
16
|
+
setKeys(fitted);
|
|
17
|
+
const move = (0, react_1.useCallback)((from, to) => setKeys((current) => ps_list_key_service_1.PsListKeyService.move(current, from, to)), []);
|
|
18
|
+
const remove = (0, react_1.useCallback)((index) => setKeys((current) => ps_list_key_service_1.PsListKeyService.remove(current, index)), []);
|
|
19
|
+
return { keys: fitted, move, remove };
|
|
20
|
+
};
|
|
21
|
+
exports.usePsListKeys = usePsListKeys;
|
package/dist/index.d.ts
CHANGED
|
@@ -188,6 +188,11 @@ export * from './models/ps-summary-item';
|
|
|
188
188
|
export * from './components/ps-drag-grip';
|
|
189
189
|
export * from './components/ps-drag-overlay';
|
|
190
190
|
export * from './hooks/use-ps-drag-sensors';
|
|
191
|
+
export * from './hooks/use-ps-drag-transition';
|
|
192
|
+
export * from './models/ps-drag-transition';
|
|
193
|
+
export * from './hooks/use-ps-list-keys';
|
|
194
|
+
export * from './interfaces/ps-list-keys-result';
|
|
195
|
+
export * from './services/ps-list-key-service';
|
|
191
196
|
export * from './hooks/use-ps-reduced-motion';
|
|
192
197
|
export * from './components/ps-divider';
|
|
193
198
|
export * from './models/ps-divider-orientation';
|
package/dist/index.js
CHANGED
|
@@ -204,6 +204,11 @@ __exportStar(require("./models/ps-summary-item"), exports);
|
|
|
204
204
|
__exportStar(require("./components/ps-drag-grip"), exports);
|
|
205
205
|
__exportStar(require("./components/ps-drag-overlay"), exports);
|
|
206
206
|
__exportStar(require("./hooks/use-ps-drag-sensors"), exports);
|
|
207
|
+
__exportStar(require("./hooks/use-ps-drag-transition"), exports);
|
|
208
|
+
__exportStar(require("./models/ps-drag-transition"), exports);
|
|
209
|
+
__exportStar(require("./hooks/use-ps-list-keys"), exports);
|
|
210
|
+
__exportStar(require("./interfaces/ps-list-keys-result"), exports);
|
|
211
|
+
__exportStar(require("./services/ps-list-key-service"), exports);
|
|
207
212
|
__exportStar(require("./hooks/use-ps-reduced-motion"), exports);
|
|
208
213
|
__exportStar(require("./components/ps-divider"), exports);
|
|
209
214
|
__exportStar(require("./models/ps-divider-orientation"), exports);
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PsListKeyService = void 0;
|
|
4
|
+
class PsListKeyService {
|
|
5
|
+
static fit(keys, count, create) {
|
|
6
|
+
if (keys.length === count)
|
|
7
|
+
return keys;
|
|
8
|
+
if (keys.length > count)
|
|
9
|
+
return keys.slice(0, count);
|
|
10
|
+
return [...keys, ...Array.from({ length: count - keys.length }, create)];
|
|
11
|
+
}
|
|
12
|
+
static move(keys, from, to) {
|
|
13
|
+
if (from === to || from < 0 || to < 0 || from >= keys.length || to >= keys.length)
|
|
14
|
+
return keys;
|
|
15
|
+
const next = [...keys];
|
|
16
|
+
const [moved] = next.splice(from, 1);
|
|
17
|
+
next.splice(to, 0, moved);
|
|
18
|
+
return next;
|
|
19
|
+
}
|
|
20
|
+
static remove(keys, index) {
|
|
21
|
+
return index < 0 || index >= keys.length ? keys : keys.filter((_key, at) => at !== index);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.PsListKeyService = PsListKeyService;
|