@lt-ui/tree-dnd 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/cjs/index.js +17 -0
- package/cjs/locale/messages.js +21 -0
- package/cjs/locale/use-locale.js +10 -0
- package/cjs/tree-dnd/drag-row.js +26 -0
- package/cjs/tree-dnd/index.js +5 -0
- package/cjs/tree-dnd/pointer.js +94 -0
- package/cjs/tree-dnd/styles.module.css +79 -0
- package/cjs/tree-dnd/tree-dnd.js +190 -0
- package/cjs/tree-dnd/types.js +2 -0
- package/cjs/tree-dnd/use-drop-target.js +121 -0
- package/cjs/tree-dnd/use-hover-expand.js +53 -0
- package/cjs/tree-dnd/use-overlay-fade.js +22 -0
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/locale/messages.d.ts +12 -0
- package/locale/messages.js +18 -0
- package/locale/use-locale.d.ts +9 -0
- package/locale/use-locale.js +7 -0
- package/package.json +30 -4
- package/tree-dnd/drag-row.d.ts +19 -0
- package/tree-dnd/drag-row.js +20 -0
- package/tree-dnd/index.d.ts +2 -0
- package/tree-dnd/index.js +1 -0
- package/tree-dnd/pointer.d.ts +26 -0
- package/tree-dnd/pointer.js +87 -0
- package/tree-dnd/styles.module.css +79 -0
- package/tree-dnd/tree-dnd.d.ts +13 -0
- package/tree-dnd/tree-dnd.js +151 -0
- package/tree-dnd/types.d.ts +61 -0
- package/tree-dnd/types.js +1 -0
- package/tree-dnd/use-drop-target.d.ts +21 -0
- package/tree-dnd/use-drop-target.js +118 -0
- package/tree-dnd/use-hover-expand.d.ts +21 -0
- package/tree-dnd/use-hover-expand.js +50 -0
- package/tree-dnd/use-overlay-fade.d.ts +7 -0
- package/tree-dnd/use-overlay-fade.js +19 -0
- package/README.md +0 -3
package/cjs/index.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./tree-dnd"), exports);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.en = exports.ru = void 0;
|
|
4
|
+
exports.ru = {
|
|
5
|
+
treeDnd: {
|
|
6
|
+
instructions: 'Чтобы переместить узел, зажмите его и перетащите на новое место в дереве',
|
|
7
|
+
start: 'Взят узел «{name}»',
|
|
8
|
+
over: 'Узел «{name}» над узлом «{target}»',
|
|
9
|
+
end: 'Узел «{name}» перемещён',
|
|
10
|
+
cancel: 'Перемещение узла «{name}» отменено',
|
|
11
|
+
},
|
|
12
|
+
};
|
|
13
|
+
exports.en = {
|
|
14
|
+
treeDnd: {
|
|
15
|
+
instructions: 'To move a node, press and hold it, then drag it to a new place in the tree',
|
|
16
|
+
start: 'Picked up “{name}”',
|
|
17
|
+
over: '“{name}” is over “{target}”',
|
|
18
|
+
end: '“{name}” was moved',
|
|
19
|
+
cancel: 'Moving “{name}” was cancelled',
|
|
20
|
+
},
|
|
21
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useLocale = void 0;
|
|
4
|
+
const i18n_1 = require("@lt-ui/i18n");
|
|
5
|
+
const messages_1 = require("./messages");
|
|
6
|
+
/**
|
|
7
|
+
* Язык и переводчик строк пакета: язык берётся у ближайшего `ThemeProvider` или `LocaleProvider`
|
|
8
|
+
* из `@lt-ui/uikit`, строки переопределяются в `messages` под своим ключом.
|
|
9
|
+
*/
|
|
10
|
+
exports.useLocale = (0, i18n_1.createUseLocale)({ en: messages_1.en, ru: messages_1.ru });
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
"use strict";
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.DragRow = DragRow;
|
|
8
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
9
|
+
const react_1 = __importDefault(require("react"));
|
|
10
|
+
const core_1 = require("@dnd-kit/core");
|
|
11
|
+
const clsx_1 = __importDefault(require("clsx"));
|
|
12
|
+
const styles_module_scss_1 = __importDefault(require("./styles.module.css"));
|
|
13
|
+
/**
|
|
14
|
+
* Строка дерева как источник перетаскивания. Из атрибутов dnd kit берём только слушатели указателя: роль и `tabindex`
|
|
15
|
+
* остаются у `treeitem`, иначе строка перестала бы быть элементом дерева для скринридеров.
|
|
16
|
+
*/
|
|
17
|
+
function DragRow({ context, locked, expanding, expandDelay, atOrigin }) {
|
|
18
|
+
const { listeners, setNodeRef, isDragging } = (0, core_1.useDraggable)({ id: context.id, disabled: locked });
|
|
19
|
+
return ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: context.render({
|
|
20
|
+
ref: setNodeRef,
|
|
21
|
+
className: (0, clsx_1.default)(!locked && styles_module_scss_1.default.draggable, isDragging && styles_module_scss_1.default.ghost, isDragging && atOrigin && styles_module_scss_1.default.ghostTarget, expanding && styles_module_scss_1.default.expanding),
|
|
22
|
+
style: expanding && expandDelay ? { '--tree-dnd-hover-delay': `${expandDelay}ms` } : undefined,
|
|
23
|
+
...(locked ? {} : listeners),
|
|
24
|
+
...(isDragging ? { 'data-dnd-ghost': '' } : {}),
|
|
25
|
+
}) }));
|
|
26
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.startOverlayFade = exports.DEFAULT_OVERLAY_FADE = exports.placeOverlay = exports.isOriginProjection = exports.getPointerY = void 0;
|
|
4
|
+
/** Вертикаль указателя в координатах окна: точка захвата + смещение (не зависит от сдвига копии модификаторами) */
|
|
5
|
+
const getPointerY = (activatorEvent, deltaY) => {
|
|
6
|
+
var _a, _b, _c;
|
|
7
|
+
if (!activatorEvent)
|
|
8
|
+
return null;
|
|
9
|
+
const touch = (_b = (_a = activatorEvent.touches) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : (_c = activatorEvent.changedTouches) === null || _c === void 0 ? void 0 : _c[0];
|
|
10
|
+
const startY = touch ? touch.clientY : activatorEvent.clientY;
|
|
11
|
+
return typeof startY === 'number' ? startY + deltaY : null;
|
|
12
|
+
};
|
|
13
|
+
exports.getPointerY = getPointerY;
|
|
14
|
+
/** Проекция совпадает с исходным положением узла (тот же родитель и позиция): отпускание равно отмене */
|
|
15
|
+
const isOriginProjection = (model, id, target) => {
|
|
16
|
+
var _a, _b;
|
|
17
|
+
const entry = id ? model.entries.get(id) : undefined;
|
|
18
|
+
if (!id || !entry || !target)
|
|
19
|
+
return false;
|
|
20
|
+
const siblings = entry.parentId ? ((_b = (_a = model.entries.get(entry.parentId)) === null || _a === void 0 ? void 0 : _a.childIds) !== null && _b !== void 0 ? _b : []) : model.rootIds;
|
|
21
|
+
return target.move.parentId === entry.parentId && target.move.index === siblings.indexOf(id);
|
|
22
|
+
};
|
|
23
|
+
exports.isOriginProjection = isOriginProjection;
|
|
24
|
+
/**
|
|
25
|
+
* Копия держится под указателем там, где узел схватили: по горизонтали — на том же расстоянии от левого края
|
|
26
|
+
* (но не дальше, чем копия шире), по вертикали — серединой. Копия уже и ниже строки, поэтому без поправки
|
|
27
|
+
* dnd kit оставлял её на месте строки и указатель оказывался вне её или у края.
|
|
28
|
+
*/
|
|
29
|
+
const placeOverlay = ({ transform, activatorEvent, draggingNodeRect, overlayNodeRect }) => {
|
|
30
|
+
var _a, _b, _c, _d, _e;
|
|
31
|
+
if (!activatorEvent || !draggingNodeRect)
|
|
32
|
+
return transform;
|
|
33
|
+
const touch = (_b = (_a = activatorEvent.touches) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : (_c = activatorEvent.changedTouches) === null || _c === void 0 ? void 0 : _c[0];
|
|
34
|
+
const start = touch !== null && touch !== void 0 ? touch : activatorEvent;
|
|
35
|
+
if (typeof start.clientX !== 'number' || typeof start.clientY !== 'number')
|
|
36
|
+
return transform;
|
|
37
|
+
const width = (_d = overlayNodeRect === null || overlayNodeRect === void 0 ? void 0 : overlayNodeRect.width) !== null && _d !== void 0 ? _d : draggingNodeRect.width;
|
|
38
|
+
const height = (_e = overlayNodeRect === null || overlayNodeRect === void 0 ? void 0 : overlayNodeRect.height) !== null && _e !== void 0 ? _e : draggingNodeRect.height;
|
|
39
|
+
const grabX = start.clientX - draggingNodeRect.left;
|
|
40
|
+
const grabY = start.clientY - draggingNodeRect.top;
|
|
41
|
+
return {
|
|
42
|
+
...transform,
|
|
43
|
+
x: transform.x + grabX - Math.min(grabX, Math.max(width - 16, 0), 24),
|
|
44
|
+
y: transform.y + grabY - height / 2,
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
exports.placeOverlay = placeOverlay;
|
|
48
|
+
/** Значения прозрачности копии по умолчанию (см. `overlayFade`) */
|
|
49
|
+
exports.DEFAULT_OVERLAY_FADE = { width: 28, alpha: 0.25, duration: 220 };
|
|
50
|
+
const easeInOut = (t) => (t < 0.5 ? 4 * t * t * t : 1 - (-2 * t + 2) ** 3 / 2);
|
|
51
|
+
/** Правый край иерархии у места вставки: колонки линий строки-заготовки или призрака */
|
|
52
|
+
const getHierarchyEdge = (tree) => {
|
|
53
|
+
const row = tree.querySelector('[data-testid="tree-placeholder"], [data-dnd-ghost]');
|
|
54
|
+
if (!row)
|
|
55
|
+
return null;
|
|
56
|
+
const guides = row.querySelectorAll('[class*="guide"]');
|
|
57
|
+
const last = guides[guides.length - 1];
|
|
58
|
+
return last ? last.getBoundingClientRect().right : row.getBoundingClientRect().left + 8;
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Копия налезает на отступ и линии места вставки: эта часть полупрозрачная, остальная — нет. Граница считается по
|
|
62
|
+
* реальному положению колонок линий каждый кадр (она всегда точная), а сама прозрачность включается и выключается
|
|
63
|
+
* анимацией по времени: налезание — «включить», ушла — «выключить», без зависимости от координаты указателя.
|
|
64
|
+
* Возвращает остановку.
|
|
65
|
+
*/
|
|
66
|
+
const startOverlayFade = (getTree, getOverlay, getConfig = () => ({})) => {
|
|
67
|
+
let frame = 0;
|
|
68
|
+
let strength = 0;
|
|
69
|
+
let last = null;
|
|
70
|
+
const tick = (now) => {
|
|
71
|
+
frame = requestAnimationFrame(tick);
|
|
72
|
+
const { width, alpha: minAlpha, duration } = { ...exports.DEFAULT_OVERLAY_FADE, ...getConfig() };
|
|
73
|
+
const step = last === null ? 0 : (now - last) / Math.max(1, duration);
|
|
74
|
+
last = now;
|
|
75
|
+
const tree = getTree();
|
|
76
|
+
const overlay = getOverlay();
|
|
77
|
+
if (!tree || !overlay)
|
|
78
|
+
return;
|
|
79
|
+
const edge = getHierarchyEdge(tree);
|
|
80
|
+
const solid = edge === null ? 0 : Math.max(0, edge - overlay.getBoundingClientRect().left);
|
|
81
|
+
strength = Math.min(1, Math.max(0, strength + (solid > 0 ? step : -step)));
|
|
82
|
+
const alpha = 1 - (1 - minAlpha) * easeInOut(strength);
|
|
83
|
+
let mask = '';
|
|
84
|
+
if (alpha < 0.995) {
|
|
85
|
+
const a = alpha.toFixed(3);
|
|
86
|
+
mask = `linear-gradient(to right, rgba(0,0,0,${a}) 0, rgba(0,0,0,${a}) ${solid.toFixed(1)}px, #000 ${(solid + width).toFixed(1)}px)`;
|
|
87
|
+
}
|
|
88
|
+
overlay.style.maskImage = mask;
|
|
89
|
+
overlay.style.setProperty('-webkit-mask-image', mask);
|
|
90
|
+
};
|
|
91
|
+
frame = requestAnimationFrame(tick);
|
|
92
|
+
return () => cancelAnimationFrame(frame);
|
|
93
|
+
};
|
|
94
|
+
exports.startOverlayFade = startOverlayFade;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
.wrapper {
|
|
2
|
+
position: relative;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
.draggable {
|
|
6
|
+
touch-action: manipulation;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
.overlay {
|
|
10
|
+
box-sizing: border-box;
|
|
11
|
+
max-width: 100%;
|
|
12
|
+
padding: 6px var(--space-12);
|
|
13
|
+
overflow: hidden;
|
|
14
|
+
text-overflow: ellipsis;
|
|
15
|
+
font-size: 16px;
|
|
16
|
+
line-height: 24px;
|
|
17
|
+
color: var(--text-primary);
|
|
18
|
+
white-space: nowrap;
|
|
19
|
+
cursor: grabbing;
|
|
20
|
+
background-color: var(--background-primary);
|
|
21
|
+
border: 1px solid var(--control-secondary);
|
|
22
|
+
border-radius: var(--rounding-l);
|
|
23
|
+
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.overlayFull {
|
|
27
|
+
box-sizing: border-box;
|
|
28
|
+
max-width: 100%;
|
|
29
|
+
cursor: grabbing;
|
|
30
|
+
opacity: 0.95;
|
|
31
|
+
filter: drop-shadow(0 4px 16px rgba(0, 0, 0, 0.16));
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.ghost {
|
|
35
|
+
color: var(--text-minor);
|
|
36
|
+
pointer-events: none;
|
|
37
|
+
outline: 1px dashed var(--control-secondary);
|
|
38
|
+
outline-offset: -1px;
|
|
39
|
+
background-color: transparent;
|
|
40
|
+
}
|
|
41
|
+
.ghost > * {
|
|
42
|
+
opacity: 0.5;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
.ghostTarget {
|
|
46
|
+
outline-color: var(--accent-primary);
|
|
47
|
+
background-color: var(--accent-light);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
.expanding {
|
|
51
|
+
outline: 1px dashed var(--accent-primary);
|
|
52
|
+
outline-offset: -1px;
|
|
53
|
+
isolation: isolate;
|
|
54
|
+
}
|
|
55
|
+
.expanding::before {
|
|
56
|
+
position: absolute;
|
|
57
|
+
inset: 0;
|
|
58
|
+
z-index: -1;
|
|
59
|
+
pointer-events: none;
|
|
60
|
+
content: "";
|
|
61
|
+
background-color: var(--accent-light);
|
|
62
|
+
border-radius: inherit;
|
|
63
|
+
transform-origin: left;
|
|
64
|
+
animation: expand-fill var(--tree-dnd-hover-delay, 600ms) linear forwards;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
@keyframes expand-fill {
|
|
68
|
+
from {
|
|
69
|
+
transform: scaleX(0);
|
|
70
|
+
}
|
|
71
|
+
to {
|
|
72
|
+
transform: scaleX(1);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
@media (prefers-reduced-motion: reduce) {
|
|
76
|
+
.expanding::before {
|
|
77
|
+
animation: none;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
"use strict";
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
o[k2] = m[k];
|
|
13
|
+
}));
|
|
14
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
+
}) : function(o, v) {
|
|
17
|
+
o["default"] = v;
|
|
18
|
+
});
|
|
19
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
20
|
+
var ownKeys = function(o) {
|
|
21
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
22
|
+
var ar = [];
|
|
23
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
24
|
+
return ar;
|
|
25
|
+
};
|
|
26
|
+
return ownKeys(o);
|
|
27
|
+
};
|
|
28
|
+
return function (mod) {
|
|
29
|
+
if (mod && mod.__esModule) return mod;
|
|
30
|
+
var result = {};
|
|
31
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
32
|
+
__setModuleDefault(result, mod);
|
|
33
|
+
return result;
|
|
34
|
+
};
|
|
35
|
+
})();
|
|
36
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
37
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
38
|
+
};
|
|
39
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
+
exports.TreeDnd = TreeDnd;
|
|
41
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
42
|
+
/* eslint-disable max-lines */
|
|
43
|
+
const react_1 = __importStar(require("react"));
|
|
44
|
+
const core_1 = require("@dnd-kit/core");
|
|
45
|
+
const uikit_1 = require("@lt-ui/uikit");
|
|
46
|
+
const use_locale_1 = require("../locale/use-locale");
|
|
47
|
+
const drag_row_1 = require("./drag-row");
|
|
48
|
+
const use_drop_target_1 = require("./use-drop-target");
|
|
49
|
+
const pointer_1 = require("./pointer");
|
|
50
|
+
const use_overlay_fade_1 = require("./use-overlay-fade");
|
|
51
|
+
const use_hover_expand_1 = require("./use-hover-expand");
|
|
52
|
+
const styles_module_scss_1 = __importDefault(require("./styles.module.css"));
|
|
53
|
+
const OVERLAY_MAX_RATIO = 0.5;
|
|
54
|
+
const nodeTitle = (node) => { var _a; return (_a = node.text) !== null && _a !== void 0 ? _a : node.label; };
|
|
55
|
+
/**
|
|
56
|
+
* `<TreeDnd />` — `Tree` с перетаскиванием узлов (dnd kit): мышь и касание.
|
|
57
|
+
* Схваченный узел «поднимается» копией шириной не больше половины дерева, на месте остаётся
|
|
58
|
+
* скрытым (раскрытая ветка сворачивается), а в дереве на месте вставки рисуется заготовка узла с отступом и
|
|
59
|
+
* линиями нужного уровня — уровень выбирается сдвигом указателя вправо/влево.
|
|
60
|
+
*
|
|
61
|
+
* @example ```tsx
|
|
62
|
+
* <TreeDnd aria-label="Каталог" nodes={nodes} onMove={move => setNodes(moveTreeNode(nodes, move))} />
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
function TreeDnd({ nodes, onMove, canDrag, canDrop, indent = 28, expandOnHoverDelay = 600, renderOverlay, overlay = 'compact', overlayFade, onDragStateChange, ...treeProps }) {
|
|
66
|
+
var _a, _b;
|
|
67
|
+
const { t } = (0, use_locale_1.useLocale)();
|
|
68
|
+
const model = (0, react_1.useMemo)(() => (0, uikit_1.buildTreeModel)(nodes), [nodes]);
|
|
69
|
+
const wrapperRef = (0, react_1.useRef)(null);
|
|
70
|
+
const treeRef = (0, react_1.useRef)(null);
|
|
71
|
+
const overlayRef = (0, react_1.useRef)(null);
|
|
72
|
+
const fade = (0, use_overlay_fade_1.useOverlayFade)(treeRef, overlayRef, overlayFade);
|
|
73
|
+
const [activeId, setActiveId] = (0, react_1.useState)(null);
|
|
74
|
+
const [overlayWidth, setOverlayWidth] = (0, react_1.useState)();
|
|
75
|
+
const sensors = (0, core_1.useSensors)((0, core_1.useSensor)(core_1.MouseSensor, { activationConstraint: { distance: 6 } }),
|
|
76
|
+
// На касании перетаскивание начинается после удержания, чтобы не мешать прокрутке
|
|
77
|
+
(0, core_1.useSensor)(core_1.TouchSensor, { activationConstraint: { delay: 250, tolerance: 6 } }));
|
|
78
|
+
// Раскрытием ведём сами: ветка раскрывается по удержанию, а состояние остаётся контролируемым снаружи
|
|
79
|
+
const [expandedState, setExpandedState] = (0, react_1.useState)(() => {
|
|
80
|
+
var _a;
|
|
81
|
+
return treeProps.defaultExpanded === 'all'
|
|
82
|
+
? Array.from(model.entries.values())
|
|
83
|
+
.filter(entry => entry.childIds.length)
|
|
84
|
+
.map(entry => entry.id)
|
|
85
|
+
: ((_a = treeProps.defaultExpanded) !== null && _a !== void 0 ? _a : []);
|
|
86
|
+
});
|
|
87
|
+
const expanded = (_a = treeProps.expanded) !== null && _a !== void 0 ? _a : expandedState;
|
|
88
|
+
const expandedRef = (0, react_1.useRef)(expanded);
|
|
89
|
+
expandedRef.current = expanded;
|
|
90
|
+
const { onExpandedChange } = treeProps;
|
|
91
|
+
const changeExpanded = (0, react_1.useCallback)((next, info) => {
|
|
92
|
+
if (treeProps.expanded === undefined)
|
|
93
|
+
setExpandedState(next);
|
|
94
|
+
onExpandedChange === null || onExpandedChange === void 0 ? void 0 : onExpandedChange(next, info);
|
|
95
|
+
}, [onExpandedChange, treeProps.expanded]);
|
|
96
|
+
const isLocked = (node) => Boolean(node.disabled) || (canDrag ? !canDrag(node) : false);
|
|
97
|
+
const dropTarget = (0, use_drop_target_1.useDropTarget)({
|
|
98
|
+
treeRef,
|
|
99
|
+
wrapperRef,
|
|
100
|
+
model,
|
|
101
|
+
indent,
|
|
102
|
+
canDrop: canDrop
|
|
103
|
+
? parentId => { var _a; return canDrop(parentId, (_a = model.entries.get(activeId !== null && activeId !== void 0 ? activeId : '')) === null || _a === void 0 ? void 0 : _a.node); }
|
|
104
|
+
: undefined,
|
|
105
|
+
});
|
|
106
|
+
const [expandingId, setExpandingId] = (0, react_1.useState)(null);
|
|
107
|
+
const lastPointer = (0, react_1.useRef)(null);
|
|
108
|
+
const hoverExpand = (0, use_hover_expand_1.useHoverExpand)({
|
|
109
|
+
treeRef,
|
|
110
|
+
model,
|
|
111
|
+
delay: expandOnHoverDelay,
|
|
112
|
+
onTarget: setExpandingId,
|
|
113
|
+
onExpand: id => {
|
|
114
|
+
if (expandedRef.current.includes(id))
|
|
115
|
+
return;
|
|
116
|
+
changeExpanded([...expandedRef.current, id], { id, expanded: true });
|
|
117
|
+
// Раскладка изменилась: заготовку убираем, место вставки пересчитается на следующем шаге
|
|
118
|
+
dropTarget.reset(true);
|
|
119
|
+
const last = lastPointer.current;
|
|
120
|
+
if (last)
|
|
121
|
+
setTimeout(() => dropTarget.update(last.id, last.y, last.x), 50);
|
|
122
|
+
},
|
|
123
|
+
});
|
|
124
|
+
const onDragStart = ({ active }) => {
|
|
125
|
+
var _a, _b, _c, _d;
|
|
126
|
+
fade.start();
|
|
127
|
+
const id = String(active.id);
|
|
128
|
+
setActiveId(id);
|
|
129
|
+
onDragStateChange === null || onDragStateChange === void 0 ? void 0 : onDragStateChange(id);
|
|
130
|
+
const treeWidth = (_b = (_a = treeRef.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect().width) !== null && _b !== void 0 ? _b : 0;
|
|
131
|
+
const rowWidth = (_d = (_c = active.rect.current.initial) === null || _c === void 0 ? void 0 : _c.width) !== null && _d !== void 0 ? _d : treeWidth;
|
|
132
|
+
setOverlayWidth(overlay === 'full' ? rowWidth : Math.min(rowWidth, treeWidth * OVERLAY_MAX_RATIO));
|
|
133
|
+
};
|
|
134
|
+
const onDragMove = ({ active, delta, activatorEvent }) => {
|
|
135
|
+
var _a;
|
|
136
|
+
const rect = active.rect.current.translated;
|
|
137
|
+
const pointerY = (_a = (0, pointer_1.getPointerY)(activatorEvent, delta.y)) !== null && _a !== void 0 ? _a : (rect ? rect.top + rect.height / 2 : null);
|
|
138
|
+
if (pointerY === null)
|
|
139
|
+
return;
|
|
140
|
+
lastPointer.current = { id: String(active.id), y: pointerY, x: delta.x };
|
|
141
|
+
const { centerId } = dropTarget.update(String(active.id), pointerY, delta.x);
|
|
142
|
+
hoverExpand.check(String(active.id), centerId);
|
|
143
|
+
};
|
|
144
|
+
const isOrigin = (id, target) => (0, pointer_1.isOriginProjection)(model, id, target);
|
|
145
|
+
const finish = (apply) => {
|
|
146
|
+
var _a;
|
|
147
|
+
const { projection } = dropTarget;
|
|
148
|
+
const id = activeId;
|
|
149
|
+
setActiveId(null);
|
|
150
|
+
onDragStateChange === null || onDragStateChange === void 0 ? void 0 : onDragStateChange(null);
|
|
151
|
+
hoverExpand.clear();
|
|
152
|
+
fade.stop();
|
|
153
|
+
lastPointer.current = null;
|
|
154
|
+
dropTarget.reset();
|
|
155
|
+
const node = id ? (_a = model.entries.get(id)) === null || _a === void 0 ? void 0 : _a.node : undefined;
|
|
156
|
+
// Узел вернули на прежнее место — как отмена (Escape): ничего не меняется
|
|
157
|
+
if (apply && projection && node && !isOrigin(id, projection))
|
|
158
|
+
onMove(projection.move, { node, projection });
|
|
159
|
+
};
|
|
160
|
+
const activeNode = activeId ? (_b = model.entries.get(activeId)) === null || _b === void 0 ? void 0 : _b.node : undefined;
|
|
161
|
+
const renderRow = (context) => ((0, jsx_runtime_1.jsx)(drag_row_1.DragRow, { context: context, locked: isLocked(context.node), expanding: context.id === expandingId, expandDelay: expandOnHoverDelay || undefined, atOrigin: atOrigin }));
|
|
162
|
+
// dnd kit по умолчанию объявляет перетаскивание по-английски: подставляем строки языка
|
|
163
|
+
const nameOf = (id) => {
|
|
164
|
+
const entry = model.entries.get(String(id));
|
|
165
|
+
const title = entry ? nodeTitle(entry.node) : undefined;
|
|
166
|
+
return typeof title === 'string' || typeof title === 'number' ? String(title) : String(id);
|
|
167
|
+
};
|
|
168
|
+
const accessibility = {
|
|
169
|
+
screenReaderInstructions: { draggable: t('treeDnd.instructions') },
|
|
170
|
+
announcements: {
|
|
171
|
+
onDragStart: ({ active }) => t('treeDnd.start', { name: nameOf(active.id) }),
|
|
172
|
+
onDragOver: ({ active, over, }) => over && over.id !== active.id
|
|
173
|
+
? t('treeDnd.over', { name: nameOf(active.id), target: nameOf(over.id) })
|
|
174
|
+
: undefined,
|
|
175
|
+
onDragEnd: ({ active }) => t('treeDnd.end', { name: nameOf(active.id) }),
|
|
176
|
+
onDragCancel: ({ active }) => t('treeDnd.cancel', { name: nameOf(active.id) }),
|
|
177
|
+
},
|
|
178
|
+
};
|
|
179
|
+
const { projection } = dropTarget;
|
|
180
|
+
// Место вставки совпало с прежним (или его пока нет): отдельная заготовка не нужна, ею служит исходная строка
|
|
181
|
+
const atOrigin = Boolean(activeId) && (!projection || isOrigin(activeId, projection));
|
|
182
|
+
const placeholder = projection && activeNode && !atOrigin
|
|
183
|
+
? {
|
|
184
|
+
afterId: projection.afterId,
|
|
185
|
+
guides: (0, uikit_1.getPlaceholderGuides)(model, projection.move),
|
|
186
|
+
node: activeNode,
|
|
187
|
+
}
|
|
188
|
+
: undefined;
|
|
189
|
+
return ((0, jsx_runtime_1.jsxs)(core_1.DndContext, { sensors: sensors, accessibility: accessibility, onDragStart: onDragStart, onDragMove: onDragMove, onDragEnd: () => finish(true), onDragCancel: () => finish(false), children: [(0, jsx_runtime_1.jsx)("div", { ref: wrapperRef, className: styles_module_scss_1.default.wrapper, "data-dragging": activeId ? '' : undefined, children: (0, jsx_runtime_1.jsx)(uikit_1.Tree, { ...treeProps, ref: treeRef, nodes: nodes, renderRow: renderRow, expanded: expanded, onExpandedChange: changeExpanded, pauseMotion: Boolean(activeId), forceCollapsed: activeId ? [activeId] : undefined, placeholder: placeholder }) }), (0, jsx_runtime_1.jsx)(core_1.DragOverlay, { dropAnimation: null, modifiers: [pointer_1.placeOverlay], children: activeNode ? ((0, jsx_runtime_1.jsx)("div", { ref: overlayRef, className: overlay === 'full' ? styles_module_scss_1.default.overlayFull : styles_module_scss_1.default.overlay, style: { width: overlayWidth }, "data-testid": "tree-dnd-overlay", children: renderOverlay ? renderOverlay(activeNode) : nodeTitle(activeNode) })) : null })] }));
|
|
190
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.useDropTarget = useDropTarget;
|
|
5
|
+
const react_1 = require("react");
|
|
6
|
+
const uikit_1 = require("@lt-ui/uikit");
|
|
7
|
+
/**
|
|
8
|
+
* Центральная часть строки (доля высоты): указатель в ней не двигает место вставки, чтобы заготовка не прыгала между
|
|
9
|
+
* соседями. Там идёт раскрытие свёрнутой ветки; над раскрытой веткой узел кладётся первым потомком.
|
|
10
|
+
*/
|
|
11
|
+
const CENTER_ZONE = [0.15, 0.85];
|
|
12
|
+
const isCenter = (fraction) => fraction >= CENTER_ZONE[0] && fraction <= CENTER_ZONE[1];
|
|
13
|
+
/** Строки в том виде, в каком их видит пользователь: порядок и уровень берём из DOM, состояние раскрытия не дублируем */
|
|
14
|
+
function measure(root, origin) {
|
|
15
|
+
var _a;
|
|
16
|
+
// Заготовка сдвигает строки под собой; считаем так, будто её нет, иначе место вставки дребезжало бы
|
|
17
|
+
const ghostRect = (_a = root.querySelector('[data-testid="tree-placeholder"]')) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect();
|
|
18
|
+
const ghost = ghostRect ? { top: ghostRect.top - origin, bottom: ghostRect.bottom - origin } : null;
|
|
19
|
+
const shift = (value) => ghost && value >= ghost.bottom - 0.5 ? value - (ghost.bottom - ghost.top) : value;
|
|
20
|
+
const items = Array.from(root.querySelectorAll('[role="treeitem"][data-tree-id]'))
|
|
21
|
+
// Сворачиваемая ветка ещё может быть в DOM (`inert`), но пользователь её уже не видит
|
|
22
|
+
.filter(element => !element.closest('[inert]'))
|
|
23
|
+
.map(element => {
|
|
24
|
+
const rect = element.getBoundingClientRect();
|
|
25
|
+
return {
|
|
26
|
+
id: element.dataset.treeId,
|
|
27
|
+
level: Number(element.getAttribute('aria-level')),
|
|
28
|
+
expanded: element.getAttribute('aria-expanded') === 'true',
|
|
29
|
+
top: shift(rect.top - origin),
|
|
30
|
+
bottom: shift(rect.bottom - origin),
|
|
31
|
+
};
|
|
32
|
+
});
|
|
33
|
+
return { items, ghost };
|
|
34
|
+
}
|
|
35
|
+
/** Вычисляет место вставки по положению указателя над строками дерева */
|
|
36
|
+
function useDropTarget({ treeRef, wrapperRef, model, indent, canDrop }) {
|
|
37
|
+
const [projection, setProjection] = (0, react_1.useState)(null);
|
|
38
|
+
const lastProjection = (0, react_1.useRef)(null);
|
|
39
|
+
// Уровень отсчитывается от последнего достигнутого, а не от точки захвата: упёршись в допустимый предел,
|
|
40
|
+
// движение в обратную сторону сразу меняет уровень, без «мёртвой зоны» накопленного смещения
|
|
41
|
+
const anchor = (0, react_1.useRef)(null);
|
|
42
|
+
const lastSlot = (0, react_1.useRef)(null);
|
|
43
|
+
const lastOver = (0, react_1.useRef)(false);
|
|
44
|
+
const update = (0, react_1.useCallback)((activeId, pointerY, offsetX) => {
|
|
45
|
+
const tree = treeRef.current;
|
|
46
|
+
const wrapper = wrapperRef.current;
|
|
47
|
+
if (!tree || !wrapper)
|
|
48
|
+
return { projection: null, centerId: null };
|
|
49
|
+
const wrapperRect = wrapper.getBoundingClientRect();
|
|
50
|
+
const active = model.entries.get(activeId);
|
|
51
|
+
if (!anchor.current && active)
|
|
52
|
+
anchor.current = { level: active.level, x: 0 };
|
|
53
|
+
const { items, ghost } = measure(tree, wrapperRect.top);
|
|
54
|
+
const y = pointerY - wrapperRect.top;
|
|
55
|
+
const rows = items.map(item => ({ id: item.id, level: item.level }));
|
|
56
|
+
const others = items.filter(item => item.id !== activeId);
|
|
57
|
+
/** Проекция для места `slot`: уровень = последний достигнутый + сдвиг указателя с тех пор */
|
|
58
|
+
// Указатель над самой исходной строкой (её призраком): место и уровень прежние, а не «прилипание» к строке выше
|
|
59
|
+
const activeItem = items.find(item => item.id === activeId);
|
|
60
|
+
const overActive = Boolean(activeItem && y >= activeItem.top && y < activeItem.bottom);
|
|
61
|
+
const project = (slot, forcedLevel) => {
|
|
62
|
+
var _a, _b, _c, _d, _e, _f;
|
|
63
|
+
// Указатель перешёл к другому месту: «прилипаем» к уровню строки выше (её сосед), а дальше уровень меняется
|
|
64
|
+
// сдвигом указателя вправо или влево от этой точки — независимо от того, за какую часть и где схвачен узел
|
|
65
|
+
if (slot !== lastSlot.current || overActive !== lastOver.current) {
|
|
66
|
+
anchor.current = {
|
|
67
|
+
level: overActive ? ((_a = active === null || active === void 0 ? void 0 : active.level) !== null && _a !== void 0 ? _a : 1) : ((_c = (_b = others[slot - 1]) === null || _b === void 0 ? void 0 : _b.level) !== null && _c !== void 0 ? _c : 1),
|
|
68
|
+
x: offsetX,
|
|
69
|
+
};
|
|
70
|
+
lastSlot.current = slot;
|
|
71
|
+
lastOver.current = overActive;
|
|
72
|
+
}
|
|
73
|
+
const from = (_d = anchor.current) !== null && _d !== void 0 ? _d : { level: (_e = active === null || active === void 0 ? void 0 : active.level) !== null && _e !== void 0 ? _e : 1, x: 0 };
|
|
74
|
+
const level = forcedLevel !== null && forcedLevel !== void 0 ? forcedLevel : from.level + Math.round((offsetX - from.x) / indent);
|
|
75
|
+
const result = (0, uikit_1.getDropProjection)({
|
|
76
|
+
model,
|
|
77
|
+
rows,
|
|
78
|
+
activeId,
|
|
79
|
+
slot,
|
|
80
|
+
offsetX: (level - ((_f = active === null || active === void 0 ? void 0 : active.level) !== null && _f !== void 0 ? _f : 1)) * indent,
|
|
81
|
+
indent,
|
|
82
|
+
canDrop,
|
|
83
|
+
});
|
|
84
|
+
// Уровень упёрся в предел или задан принудительно: дальше отсчитываем от него и от текущей позиции указателя
|
|
85
|
+
if (result && result.level !== level)
|
|
86
|
+
anchor.current = { level: result.level, x: offsetX };
|
|
87
|
+
lastProjection.current = result;
|
|
88
|
+
setProjection(result);
|
|
89
|
+
return result;
|
|
90
|
+
};
|
|
91
|
+
// Указатель над заготовкой или в центре свёрнутой строки: место не меняется, но уровень следует за указателем
|
|
92
|
+
const keepSlot = () => {
|
|
93
|
+
const last = lastProjection.current;
|
|
94
|
+
return last ? project(last.slot) : null;
|
|
95
|
+
};
|
|
96
|
+
if (ghost && y >= ghost.top && y < ghost.bottom)
|
|
97
|
+
return { projection: keepSlot(), centerId: null };
|
|
98
|
+
let slot = others.filter(item => (item.top + item.bottom) / 2 < y).length;
|
|
99
|
+
const hit = others.find(item => y >= item.top && y < item.bottom);
|
|
100
|
+
if (hit && isCenter((y - hit.top) / (hit.bottom - hit.top))) {
|
|
101
|
+
// Центр строки: место вставки не прыгает. Над раскрытой веткой узел кладём первым потомком, над остальными —
|
|
102
|
+
// ничего не меняем (свёрнутая ветка раскроется по удержанию)
|
|
103
|
+
if (!hit.expanded)
|
|
104
|
+
return { projection: keepSlot(), centerId: hit.id };
|
|
105
|
+
slot = others.indexOf(hit) + 1;
|
|
106
|
+
return { projection: project(slot, hit.level + 1), centerId: hit.id };
|
|
107
|
+
}
|
|
108
|
+
return { projection: project(slot), centerId: null };
|
|
109
|
+
}, [canDrop, indent, model, treeRef, wrapperRef]);
|
|
110
|
+
/** `keepLevel` — только убрать заготовку (раскладка изменилась), не теряя достигнутый уровень */
|
|
111
|
+
const reset = (0, react_1.useCallback)((keepLevel = false) => {
|
|
112
|
+
lastProjection.current = null;
|
|
113
|
+
if (!keepLevel) {
|
|
114
|
+
anchor.current = null;
|
|
115
|
+
lastSlot.current = null;
|
|
116
|
+
lastOver.current = false;
|
|
117
|
+
}
|
|
118
|
+
setProjection(null);
|
|
119
|
+
}, []);
|
|
120
|
+
return { projection, update, reset };
|
|
121
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.useHoverExpand = useHoverExpand;
|
|
5
|
+
const react_1 = require("react");
|
|
6
|
+
/**
|
|
7
|
+
* Раскрытие ветки по удержанию: указатель задержался в центральной зоне свёрнутой ветки — она раскрывается,
|
|
8
|
+
* чтобы можно было положить узел внутрь. Над листом и уже раскрытой веткой ничего не происходит. Уход в другую
|
|
9
|
+
* строку (или на границу строк) сбрасывает отсчёт.
|
|
10
|
+
*/
|
|
11
|
+
function useHoverExpand({ treeRef, model, delay, onExpand, onTarget }) {
|
|
12
|
+
const timer = (0, react_1.useRef)(undefined);
|
|
13
|
+
const current = (0, react_1.useRef)(null);
|
|
14
|
+
const callbacks = (0, react_1.useRef)({ onExpand, onTarget });
|
|
15
|
+
callbacks.current = { onExpand, onTarget };
|
|
16
|
+
const clear = (0, react_1.useCallback)(() => {
|
|
17
|
+
clearTimeout(timer.current);
|
|
18
|
+
timer.current = undefined;
|
|
19
|
+
if (current.current !== null)
|
|
20
|
+
callbacks.current.onTarget(null);
|
|
21
|
+
current.current = null;
|
|
22
|
+
}, []);
|
|
23
|
+
(0, react_1.useEffect)(() => clear, [clear]);
|
|
24
|
+
/** `centerId` — строка, в центральной зоне которой указатель (из `useDropTarget`) */
|
|
25
|
+
const check = (0, react_1.useCallback)((activeId, centerId) => {
|
|
26
|
+
var _a;
|
|
27
|
+
if (delay === false)
|
|
28
|
+
return;
|
|
29
|
+
if (centerId === current.current)
|
|
30
|
+
return;
|
|
31
|
+
clearTimeout(timer.current);
|
|
32
|
+
timer.current = undefined;
|
|
33
|
+
const hadTarget = current.current !== null;
|
|
34
|
+
current.current = centerId;
|
|
35
|
+
if (hadTarget)
|
|
36
|
+
callbacks.current.onTarget(null);
|
|
37
|
+
if (!centerId || centerId === activeId)
|
|
38
|
+
return;
|
|
39
|
+
const row = (_a = treeRef.current) === null || _a === void 0 ? void 0 : _a.querySelector(`[role="treeitem"][data-tree-id="${CSS.escape(centerId)}"]`);
|
|
40
|
+
const entry = model.entries.get(centerId);
|
|
41
|
+
const collapsed = (row === null || row === void 0 ? void 0 : row.getAttribute('aria-expanded')) === 'false';
|
|
42
|
+
if (!entry || !entry.childIds.length || !collapsed || entry.node.disabled)
|
|
43
|
+
return;
|
|
44
|
+
callbacks.current.onTarget(centerId);
|
|
45
|
+
timer.current = setTimeout(() => {
|
|
46
|
+
timer.current = undefined;
|
|
47
|
+
current.current = null;
|
|
48
|
+
callbacks.current.onTarget(null);
|
|
49
|
+
callbacks.current.onExpand(centerId);
|
|
50
|
+
}, delay);
|
|
51
|
+
}, [delay, model, treeRef]);
|
|
52
|
+
return { check, clear };
|
|
53
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.useOverlayFade = useOverlayFade;
|
|
5
|
+
const react_1 = require("react");
|
|
6
|
+
const pointer_1 = require("./pointer");
|
|
7
|
+
/** Плавная прозрачность копии над отступом и линиями места вставки на время перетаскивания */
|
|
8
|
+
function useOverlayFade(treeRef, overlayRef, config = {}) {
|
|
9
|
+
const stopRef = (0, react_1.useRef)(null);
|
|
10
|
+
// Актуальные значения читаются каждый кадр: менять `overlayFade` можно и во время перетаскивания
|
|
11
|
+
const configRef = (0, react_1.useRef)(config);
|
|
12
|
+
configRef.current = config;
|
|
13
|
+
const stop = (0, react_1.useCallback)(() => { var _a; return (_a = stopRef.current) === null || _a === void 0 ? void 0 : _a.call(stopRef); }, []);
|
|
14
|
+
const start = (0, react_1.useCallback)(() => {
|
|
15
|
+
stop();
|
|
16
|
+
if (configRef.current === false)
|
|
17
|
+
return;
|
|
18
|
+
stopRef.current = (0, pointer_1.startOverlayFade)(() => treeRef.current, () => overlayRef.current, () => (configRef.current === false ? { alpha: 1 } : configRef.current));
|
|
19
|
+
}, [overlayRef, stop, treeRef]);
|
|
20
|
+
(0, react_1.useEffect)(() => stop, [stop]);
|
|
21
|
+
return { start, stop };
|
|
22
|
+
}
|