@inf-monkeys-tech/monkeys-design 0.4.41 → 0.4.43
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/data-explorer/index.js +147 -70
- package/dist/components/data-explorer/index.js.map +1 -1
- package/dist/components/data-explorer/index.mjs +149 -72
- package/dist/components/data-explorer/index.mjs.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -0
- package/dist/index.mjs.map +1 -1
- package/dist/theme-system/index.js +1 -0
- package/dist/theme-system/index.js.map +1 -1
- package/dist/theme-system/index.mjs +1 -0
- package/dist/theme-system/index.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import * as DropdownMenu3 from '@radix-ui/react-dropdown-menu';
|
|
2
|
-
import { forwardRef, useState, useEffect, useMemo,
|
|
2
|
+
import { forwardRef, useState, useRef, useEffect, useMemo, useCallback, Fragment as Fragment$1, useLayoutEffect } from 'react';
|
|
3
3
|
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
|
4
|
-
import { useSensors, useSensor, PointerSensor, KeyboardSensor, DndContext, closestCenter
|
|
4
|
+
import { useSensors, useSensor, PointerSensor, KeyboardSensor, DndContext, closestCenter } from '@dnd-kit/core';
|
|
5
5
|
import { sortableKeyboardCoordinates, SortableContext, verticalListSortingStrategy, useSortable, defaultAnimateLayoutChanges } from '@dnd-kit/sortable';
|
|
6
6
|
import { CSS } from '@dnd-kit/utilities';
|
|
7
|
+
import { createPortal } from 'react-dom';
|
|
7
8
|
|
|
8
9
|
// src/components/data-explorer/DataExplorerToolbarActions.tsx
|
|
9
10
|
|
|
@@ -1696,6 +1697,19 @@ function resolveTreeItemBorderRadius(itemRadius, appearanceRadius) {
|
|
|
1696
1697
|
if (!radius) return void 0;
|
|
1697
1698
|
return treeItemRadiusValues[radius] ?? radius;
|
|
1698
1699
|
}
|
|
1700
|
+
function getEventClientPoint(event) {
|
|
1701
|
+
if (!event) return void 0;
|
|
1702
|
+
if ("clientX" in event && "clientY" in event) {
|
|
1703
|
+
return {
|
|
1704
|
+
x: Number(event.clientX),
|
|
1705
|
+
y: Number(event.clientY)
|
|
1706
|
+
};
|
|
1707
|
+
}
|
|
1708
|
+
const touchEvent = event;
|
|
1709
|
+
const touch = touchEvent.touches?.[0] ?? touchEvent.changedTouches?.[0];
|
|
1710
|
+
if (!touch) return void 0;
|
|
1711
|
+
return { x: touch.clientX, y: touch.clientY };
|
|
1712
|
+
}
|
|
1699
1713
|
function ChevronIcon({ expanded }) {
|
|
1700
1714
|
return /* @__PURE__ */ jsx(
|
|
1701
1715
|
"svg",
|
|
@@ -1782,10 +1796,11 @@ function DraggableTreeItem({
|
|
|
1782
1796
|
renderNodeActions,
|
|
1783
1797
|
renderNodeChildren,
|
|
1784
1798
|
onSelect,
|
|
1785
|
-
onToggle
|
|
1799
|
+
onToggle,
|
|
1800
|
+
registerNodeElement
|
|
1786
1801
|
}) {
|
|
1787
1802
|
const { node, depth } = entry;
|
|
1788
|
-
const hasChildren = Boolean(node.children?.length);
|
|
1803
|
+
const hasChildren = node.collapsible === true || Boolean(node.children?.length);
|
|
1789
1804
|
const disabled = Boolean(node.disabled);
|
|
1790
1805
|
const selectable = node.selectable !== false && !disabled;
|
|
1791
1806
|
const draggable = node.draggable !== false && !disabled;
|
|
@@ -1793,6 +1808,7 @@ function DraggableTreeItem({
|
|
|
1793
1808
|
attributes,
|
|
1794
1809
|
listeners,
|
|
1795
1810
|
setNodeRef,
|
|
1811
|
+
setActivatorNodeRef,
|
|
1796
1812
|
transform,
|
|
1797
1813
|
transition,
|
|
1798
1814
|
isDragging
|
|
@@ -1823,10 +1839,16 @@ function DraggableTreeItem({
|
|
|
1823
1839
|
transform: CSS.Transform.toString(transform),
|
|
1824
1840
|
transition
|
|
1825
1841
|
};
|
|
1842
|
+
const setRowRef = useCallback(
|
|
1843
|
+
(element) => {
|
|
1844
|
+
setNodeRef(element);
|
|
1845
|
+
registerNodeElement?.(node.id, element);
|
|
1846
|
+
},
|
|
1847
|
+
[node.id, registerNodeElement, setNodeRef]
|
|
1848
|
+
);
|
|
1826
1849
|
return /* @__PURE__ */ jsxs(
|
|
1827
1850
|
"div",
|
|
1828
1851
|
{
|
|
1829
|
-
ref: setNodeRef,
|
|
1830
1852
|
style,
|
|
1831
1853
|
className: cn(
|
|
1832
1854
|
"min-w-0",
|
|
@@ -1863,6 +1885,8 @@ function DraggableTreeItem({
|
|
|
1863
1885
|
handleListeners,
|
|
1864
1886
|
renderNodeActions,
|
|
1865
1887
|
renderContext,
|
|
1888
|
+
rowRef: setRowRef,
|
|
1889
|
+
dragHandleRef: activationMode === "handle" ? setActivatorNodeRef : void 0,
|
|
1866
1890
|
onSelect: () => onSelect?.(node),
|
|
1867
1891
|
onToggle: () => onToggle(node.id)
|
|
1868
1892
|
}
|
|
@@ -1907,12 +1931,15 @@ function TreeItemRow({
|
|
|
1907
1931
|
handleListeners,
|
|
1908
1932
|
renderNodeActions,
|
|
1909
1933
|
renderContext,
|
|
1934
|
+
rowRef,
|
|
1935
|
+
dragHandleRef,
|
|
1910
1936
|
onSelect,
|
|
1911
1937
|
onToggle
|
|
1912
1938
|
}) {
|
|
1913
1939
|
return /* @__PURE__ */ jsxs(
|
|
1914
1940
|
"div",
|
|
1915
1941
|
{
|
|
1942
|
+
ref: rowRef,
|
|
1916
1943
|
"data-data-explorer-draggable-tree-item": true,
|
|
1917
1944
|
className: cn(
|
|
1918
1945
|
themeSlots.treeNodeButton,
|
|
@@ -1953,6 +1980,7 @@ function TreeItemRow({
|
|
|
1953
1980
|
draggable ? /* @__PURE__ */ jsx(
|
|
1954
1981
|
"span",
|
|
1955
1982
|
{
|
|
1983
|
+
ref: dragHandleRef,
|
|
1956
1984
|
className: cn(
|
|
1957
1985
|
themeSlots.treeNodeDragHandle,
|
|
1958
1986
|
"opacity-100",
|
|
@@ -2035,12 +2063,14 @@ function DataExplorerDraggableTree({
|
|
|
2035
2063
|
() => buildDefaultExpandedNodeIds(nodes, defaultExpandedNodeIds)
|
|
2036
2064
|
);
|
|
2037
2065
|
const [activeNodeId, setActiveNodeId] = useState();
|
|
2038
|
-
const [
|
|
2066
|
+
const [dragPreviewLayout, setDragPreviewLayout] = useState();
|
|
2039
2067
|
const [overNodeId, setOverNodeId] = useState();
|
|
2068
|
+
const nodeElementsRef = useRef(/* @__PURE__ */ new Map());
|
|
2040
2069
|
const itemBorderRadius = resolveTreeItemBorderRadius(itemRadius, theme.radius);
|
|
2041
2070
|
const itemStyle = itemBorderRadius ? { borderRadius: itemBorderRadius } : void 0;
|
|
2042
2071
|
const overlayStyle = {
|
|
2043
|
-
width:
|
|
2072
|
+
width: dragPreviewLayout?.width,
|
|
2073
|
+
height: dragPreviewLayout?.height,
|
|
2044
2074
|
borderRadius: itemBorderRadius
|
|
2045
2075
|
};
|
|
2046
2076
|
const sensors = useSensors(
|
|
@@ -2064,6 +2094,21 @@ function DataExplorerDraggableTree({
|
|
|
2064
2094
|
}, [flattenedNodes]);
|
|
2065
2095
|
const activeEntry = activeNodeId ? flattenedNodeMap.get(activeNodeId) : void 0;
|
|
2066
2096
|
const sortableIds = flattenedNodes.map((entry) => entry.node.id);
|
|
2097
|
+
const registerNodeElement = useCallback(
|
|
2098
|
+
(nodeId, element) => {
|
|
2099
|
+
if (element) {
|
|
2100
|
+
nodeElementsRef.current.set(nodeId, element);
|
|
2101
|
+
} else {
|
|
2102
|
+
nodeElementsRef.current.delete(nodeId);
|
|
2103
|
+
}
|
|
2104
|
+
},
|
|
2105
|
+
[]
|
|
2106
|
+
);
|
|
2107
|
+
const clearDragState = useCallback(() => {
|
|
2108
|
+
setActiveNodeId(void 0);
|
|
2109
|
+
setDragPreviewLayout(void 0);
|
|
2110
|
+
setOverNodeId(void 0);
|
|
2111
|
+
}, []);
|
|
2067
2112
|
const setNodeExpanded = (nodeId, expanded) => {
|
|
2068
2113
|
const next = new Set(resolvedExpandedNodeIds);
|
|
2069
2114
|
if (expanded) {
|
|
@@ -2076,16 +2121,48 @@ function DataExplorerDraggableTree({
|
|
|
2076
2121
|
}
|
|
2077
2122
|
onExpandedNodeIdsChange?.([...next]);
|
|
2078
2123
|
};
|
|
2124
|
+
const handleDragStart = (event) => {
|
|
2125
|
+
const activeId = String(event.active.id || "");
|
|
2126
|
+
setActiveNodeId(activeId);
|
|
2127
|
+
const elementRect = activeId ? nodeElementsRef.current.get(activeId)?.getBoundingClientRect() : void 0;
|
|
2128
|
+
const initialRect = event.active.rect.current.initial;
|
|
2129
|
+
const rect = elementRect ?? initialRect;
|
|
2130
|
+
const point = getEventClientPoint(event.activatorEvent);
|
|
2131
|
+
const width = rect?.width;
|
|
2132
|
+
const height = rect?.height;
|
|
2133
|
+
const left = rect?.left ?? (point ? point.x - (width ?? 0) / 2 : 0);
|
|
2134
|
+
const top = rect?.top ?? (point ? point.y - (height ?? 0) / 2 : 0);
|
|
2135
|
+
setDragPreviewLayout({
|
|
2136
|
+
initialLeft: left,
|
|
2137
|
+
initialTop: top,
|
|
2138
|
+
left,
|
|
2139
|
+
top,
|
|
2140
|
+
width,
|
|
2141
|
+
height
|
|
2142
|
+
});
|
|
2143
|
+
};
|
|
2144
|
+
const handleDragMove = (event) => {
|
|
2145
|
+
setDragPreviewLayout(
|
|
2146
|
+
(layout) => layout ? {
|
|
2147
|
+
...layout,
|
|
2148
|
+
left: layout.initialLeft + event.delta.x,
|
|
2149
|
+
top: layout.initialTop + event.delta.y
|
|
2150
|
+
} : layout
|
|
2151
|
+
);
|
|
2152
|
+
};
|
|
2079
2153
|
const handleDragEnd = (event) => {
|
|
2080
2154
|
const activeId = String(event.active.id || "");
|
|
2081
2155
|
const overId = event.over ? String(event.over.id || "") : "";
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2156
|
+
if (!activeId || !overId || activeId === overId || !onDragEnd) {
|
|
2157
|
+
clearDragState();
|
|
2158
|
+
return;
|
|
2159
|
+
}
|
|
2086
2160
|
const activeEntry2 = flattenedNodeMap.get(activeId);
|
|
2087
2161
|
const overEntry = flattenedNodeMap.get(overId);
|
|
2088
|
-
if (!activeEntry2 || !overEntry)
|
|
2162
|
+
if (!activeEntry2 || !overEntry) {
|
|
2163
|
+
clearDragState();
|
|
2164
|
+
return;
|
|
2165
|
+
}
|
|
2089
2166
|
const payload = {
|
|
2090
2167
|
activeNode: activeEntry2.node,
|
|
2091
2168
|
overNode: overEntry.node,
|
|
@@ -2097,7 +2174,61 @@ function DataExplorerDraggableTree({
|
|
|
2097
2174
|
context
|
|
2098
2175
|
};
|
|
2099
2176
|
void onDragEnd(payload);
|
|
2177
|
+
clearDragState();
|
|
2100
2178
|
};
|
|
2179
|
+
const dragOverlay = activeEntry && dragPreviewLayout ? /* @__PURE__ */ jsx(
|
|
2180
|
+
"div",
|
|
2181
|
+
{
|
|
2182
|
+
"aria-hidden": "true",
|
|
2183
|
+
className: "pointer-events-none fixed z-[1000] min-w-0",
|
|
2184
|
+
style: {
|
|
2185
|
+
left: dragPreviewLayout.left,
|
|
2186
|
+
top: dragPreviewLayout.top,
|
|
2187
|
+
...overlayStyle
|
|
2188
|
+
},
|
|
2189
|
+
children: /* @__PURE__ */ jsx(
|
|
2190
|
+
"div",
|
|
2191
|
+
{
|
|
2192
|
+
className: cn("min-w-0 overflow-hidden shadow-lg", classNames?.overlay),
|
|
2193
|
+
style: overlayStyle,
|
|
2194
|
+
children: /* @__PURE__ */ jsx(
|
|
2195
|
+
TreeItemRow,
|
|
2196
|
+
{
|
|
2197
|
+
node: activeEntry.node,
|
|
2198
|
+
depth: activeEntry.depth,
|
|
2199
|
+
indentSize,
|
|
2200
|
+
selected: selectedNodeId === activeEntry.node.id,
|
|
2201
|
+
expanded: activeEntry.node.collapsible === false || resolvedExpandedNodeIds.has(activeEntry.node.id),
|
|
2202
|
+
active: true,
|
|
2203
|
+
over: false,
|
|
2204
|
+
hasChildren: activeEntry.node.collapsible === true || Boolean(activeEntry.node.children?.length),
|
|
2205
|
+
disabled: Boolean(activeEntry.node.disabled),
|
|
2206
|
+
selectable: activeEntry.node.selectable !== false,
|
|
2207
|
+
draggable: activeEntry.node.draggable !== false,
|
|
2208
|
+
activationMode,
|
|
2209
|
+
dragHandleLabel: labels?.dragHandle ?? "Drag",
|
|
2210
|
+
expandLabel: labels?.expand ?? "Expand",
|
|
2211
|
+
collapseLabel: labels?.collapse ?? "Collapse",
|
|
2212
|
+
themeSlots: theme.slots,
|
|
2213
|
+
classNames,
|
|
2214
|
+
itemClassName: activeEntry.node.itemClassName,
|
|
2215
|
+
itemStyle,
|
|
2216
|
+
renderNodeActions,
|
|
2217
|
+
renderContext: {
|
|
2218
|
+
node: activeEntry.node,
|
|
2219
|
+
depth: activeEntry.depth,
|
|
2220
|
+
expanded: activeEntry.node.collapsible === false || resolvedExpandedNodeIds.has(activeEntry.node.id),
|
|
2221
|
+
selected: selectedNodeId === activeEntry.node.id,
|
|
2222
|
+
dragging: true,
|
|
2223
|
+
disabled: Boolean(activeEntry.node.disabled),
|
|
2224
|
+
context: activeEntry.node.context ?? context
|
|
2225
|
+
}
|
|
2226
|
+
}
|
|
2227
|
+
)
|
|
2228
|
+
}
|
|
2229
|
+
)
|
|
2230
|
+
}
|
|
2231
|
+
) : null;
|
|
2101
2232
|
if (loading) {
|
|
2102
2233
|
return /* @__PURE__ */ jsx("div", { className: cn(theme.slots.treeRoot, classNames?.root, className), children: /* @__PURE__ */ jsx("div", { className: cn(theme.slots.treeLoading, classNames?.loading), children: labels?.loading ?? "Loading..." }) });
|
|
2103
2234
|
}
|
|
@@ -2109,19 +2240,13 @@ function DataExplorerDraggableTree({
|
|
|
2109
2240
|
{
|
|
2110
2241
|
sensors,
|
|
2111
2242
|
collisionDetection: closestCenter,
|
|
2112
|
-
onDragStart:
|
|
2113
|
-
|
|
2114
|
-
setActiveNodeWidth(event.active.rect.current.initial?.width);
|
|
2115
|
-
},
|
|
2243
|
+
onDragStart: handleDragStart,
|
|
2244
|
+
onDragMove: handleDragMove,
|
|
2116
2245
|
onDragOver: (event) => {
|
|
2117
2246
|
setOverNodeId(event.over ? String(event.over.id || "") : void 0);
|
|
2118
2247
|
},
|
|
2119
2248
|
onDragEnd: handleDragEnd,
|
|
2120
|
-
onDragCancel:
|
|
2121
|
-
setActiveNodeId(void 0);
|
|
2122
|
-
setActiveNodeWidth(void 0);
|
|
2123
|
-
setOverNodeId(void 0);
|
|
2124
|
-
},
|
|
2249
|
+
onDragCancel: clearDragState,
|
|
2125
2250
|
children: [
|
|
2126
2251
|
/* @__PURE__ */ jsx(SortableContext, { items: sortableIds, strategy: verticalListSortingStrategy, children: /* @__PURE__ */ jsx(
|
|
2127
2252
|
"div",
|
|
@@ -2156,63 +2281,15 @@ function DataExplorerDraggableTree({
|
|
|
2156
2281
|
renderNodeActions,
|
|
2157
2282
|
renderNodeChildren,
|
|
2158
2283
|
onSelect: (nextNode) => onSelectNode?.(nextNode, context),
|
|
2159
|
-
onToggle: (nodeId) => setNodeExpanded(nodeId, !expanded)
|
|
2284
|
+
onToggle: (nodeId) => setNodeExpanded(nodeId, !expanded),
|
|
2285
|
+
registerNodeElement
|
|
2160
2286
|
},
|
|
2161
2287
|
node.id
|
|
2162
2288
|
);
|
|
2163
2289
|
}) })
|
|
2164
2290
|
}
|
|
2165
2291
|
) }),
|
|
2166
|
-
|
|
2167
|
-
DragOverlay,
|
|
2168
|
-
{
|
|
2169
|
-
dropAnimation: {
|
|
2170
|
-
duration: treeItemDropTransition.duration,
|
|
2171
|
-
easing: treeItemDropTransition.easing
|
|
2172
|
-
},
|
|
2173
|
-
children: activeEntry ? /* @__PURE__ */ jsx(
|
|
2174
|
-
"div",
|
|
2175
|
-
{
|
|
2176
|
-
className: cn("min-w-0 overflow-hidden shadow-lg", classNames?.overlay),
|
|
2177
|
-
style: overlayStyle,
|
|
2178
|
-
children: /* @__PURE__ */ jsx(
|
|
2179
|
-
TreeItemRow,
|
|
2180
|
-
{
|
|
2181
|
-
node: activeEntry.node,
|
|
2182
|
-
depth: activeEntry.depth,
|
|
2183
|
-
indentSize,
|
|
2184
|
-
selected: selectedNodeId === activeEntry.node.id,
|
|
2185
|
-
expanded: activeEntry.node.collapsible === false || resolvedExpandedNodeIds.has(activeEntry.node.id),
|
|
2186
|
-
active: true,
|
|
2187
|
-
over: false,
|
|
2188
|
-
hasChildren: Boolean(activeEntry.node.children?.length),
|
|
2189
|
-
disabled: Boolean(activeEntry.node.disabled),
|
|
2190
|
-
selectable: activeEntry.node.selectable !== false,
|
|
2191
|
-
draggable: activeEntry.node.draggable !== false,
|
|
2192
|
-
activationMode,
|
|
2193
|
-
dragHandleLabel: labels?.dragHandle ?? "Drag",
|
|
2194
|
-
expandLabel: labels?.expand ?? "Expand",
|
|
2195
|
-
collapseLabel: labels?.collapse ?? "Collapse",
|
|
2196
|
-
themeSlots: theme.slots,
|
|
2197
|
-
classNames,
|
|
2198
|
-
itemClassName: activeEntry.node.itemClassName,
|
|
2199
|
-
itemStyle,
|
|
2200
|
-
renderNodeActions,
|
|
2201
|
-
renderContext: {
|
|
2202
|
-
node: activeEntry.node,
|
|
2203
|
-
depth: activeEntry.depth,
|
|
2204
|
-
expanded: activeEntry.node.collapsible === false || resolvedExpandedNodeIds.has(activeEntry.node.id),
|
|
2205
|
-
selected: selectedNodeId === activeEntry.node.id,
|
|
2206
|
-
dragging: true,
|
|
2207
|
-
disabled: Boolean(activeEntry.node.disabled),
|
|
2208
|
-
context: activeEntry.node.context ?? context
|
|
2209
|
-
}
|
|
2210
|
-
}
|
|
2211
|
-
)
|
|
2212
|
-
}
|
|
2213
|
-
) : null
|
|
2214
|
-
}
|
|
2215
|
-
)
|
|
2292
|
+
typeof document === "undefined" ? dragOverlay : dragOverlay ? createPortal(dragOverlay, document.body) : null
|
|
2216
2293
|
]
|
|
2217
2294
|
}
|
|
2218
2295
|
);
|