@inf-monkeys-tech/monkeys-design 0.4.42 → 0.4.44

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.
@@ -6,6 +6,7 @@ var jsxRuntime = require('react/jsx-runtime');
6
6
  var core = require('@dnd-kit/core');
7
7
  var sortable = require('@dnd-kit/sortable');
8
8
  var utilities = require('@dnd-kit/utilities');
9
+ var reactDom = require('react-dom');
9
10
 
10
11
  function _interopNamespace(e) {
11
12
  if (e && e.__esModule) return e;
@@ -1718,6 +1719,19 @@ function resolveTreeItemBorderRadius(itemRadius, appearanceRadius) {
1718
1719
  if (!radius) return void 0;
1719
1720
  return treeItemRadiusValues[radius] ?? radius;
1720
1721
  }
1722
+ function getEventClientPoint(event) {
1723
+ if (!event) return void 0;
1724
+ if ("clientX" in event && "clientY" in event) {
1725
+ return {
1726
+ x: Number(event.clientX),
1727
+ y: Number(event.clientY)
1728
+ };
1729
+ }
1730
+ const touchEvent = event;
1731
+ const touch = touchEvent.touches?.[0] ?? touchEvent.changedTouches?.[0];
1732
+ if (!touch) return void 0;
1733
+ return { x: touch.clientX, y: touch.clientY };
1734
+ }
1721
1735
  function ChevronIcon({ expanded }) {
1722
1736
  return /* @__PURE__ */ jsxRuntime.jsx(
1723
1737
  "svg",
@@ -1804,7 +1818,8 @@ function DraggableTreeItem({
1804
1818
  renderNodeActions,
1805
1819
  renderNodeChildren,
1806
1820
  onSelect,
1807
- onToggle
1821
+ onToggle,
1822
+ registerNodeElement
1808
1823
  }) {
1809
1824
  const { node, depth } = entry;
1810
1825
  const hasChildren = node.collapsible === true || Boolean(node.children?.length);
@@ -1815,6 +1830,7 @@ function DraggableTreeItem({
1815
1830
  attributes,
1816
1831
  listeners,
1817
1832
  setNodeRef,
1833
+ setActivatorNodeRef,
1818
1834
  transform,
1819
1835
  transition,
1820
1836
  isDragging
@@ -1845,10 +1861,16 @@ function DraggableTreeItem({
1845
1861
  transform: utilities.CSS.Transform.toString(transform),
1846
1862
  transition
1847
1863
  };
1864
+ const setRowRef = react.useCallback(
1865
+ (element) => {
1866
+ setNodeRef(element);
1867
+ registerNodeElement?.(node.id, element);
1868
+ },
1869
+ [node.id, registerNodeElement, setNodeRef]
1870
+ );
1848
1871
  return /* @__PURE__ */ jsxRuntime.jsxs(
1849
1872
  "div",
1850
1873
  {
1851
- ref: setNodeRef,
1852
1874
  style,
1853
1875
  className: cn(
1854
1876
  "min-w-0",
@@ -1885,6 +1907,8 @@ function DraggableTreeItem({
1885
1907
  handleListeners,
1886
1908
  renderNodeActions,
1887
1909
  renderContext,
1910
+ rowRef: setRowRef,
1911
+ dragHandleRef: activationMode === "handle" ? setActivatorNodeRef : void 0,
1888
1912
  onSelect: () => onSelect?.(node),
1889
1913
  onToggle: () => onToggle(node.id)
1890
1914
  }
@@ -1929,12 +1953,15 @@ function TreeItemRow({
1929
1953
  handleListeners,
1930
1954
  renderNodeActions,
1931
1955
  renderContext,
1956
+ rowRef,
1957
+ dragHandleRef,
1932
1958
  onSelect,
1933
1959
  onToggle
1934
1960
  }) {
1935
1961
  return /* @__PURE__ */ jsxRuntime.jsxs(
1936
1962
  "div",
1937
1963
  {
1964
+ ref: rowRef,
1938
1965
  "data-data-explorer-draggable-tree-item": true,
1939
1966
  className: cn(
1940
1967
  themeSlots.treeNodeButton,
@@ -1975,6 +2002,7 @@ function TreeItemRow({
1975
2002
  draggable ? /* @__PURE__ */ jsxRuntime.jsx(
1976
2003
  "span",
1977
2004
  {
2005
+ ref: dragHandleRef,
1978
2006
  className: cn(
1979
2007
  themeSlots.treeNodeDragHandle,
1980
2008
  "opacity-100",
@@ -2057,12 +2085,14 @@ function DataExplorerDraggableTree({
2057
2085
  () => buildDefaultExpandedNodeIds(nodes, defaultExpandedNodeIds)
2058
2086
  );
2059
2087
  const [activeNodeId, setActiveNodeId] = react.useState();
2060
- const [activeNodeWidth, setActiveNodeWidth] = react.useState();
2088
+ const [dragPreviewLayout, setDragPreviewLayout] = react.useState();
2061
2089
  const [overNodeId, setOverNodeId] = react.useState();
2090
+ const nodeElementsRef = react.useRef(/* @__PURE__ */ new Map());
2062
2091
  const itemBorderRadius = resolveTreeItemBorderRadius(itemRadius, theme.radius);
2063
2092
  const itemStyle = itemBorderRadius ? { borderRadius: itemBorderRadius } : void 0;
2064
2093
  const overlayStyle = {
2065
- width: activeNodeWidth,
2094
+ width: dragPreviewLayout?.width,
2095
+ height: dragPreviewLayout?.height,
2066
2096
  borderRadius: itemBorderRadius
2067
2097
  };
2068
2098
  const sensors = core.useSensors(
@@ -2086,6 +2116,21 @@ function DataExplorerDraggableTree({
2086
2116
  }, [flattenedNodes]);
2087
2117
  const activeEntry = activeNodeId ? flattenedNodeMap.get(activeNodeId) : void 0;
2088
2118
  const sortableIds = flattenedNodes.map((entry) => entry.node.id);
2119
+ const registerNodeElement = react.useCallback(
2120
+ (nodeId, element) => {
2121
+ if (element) {
2122
+ nodeElementsRef.current.set(nodeId, element);
2123
+ } else {
2124
+ nodeElementsRef.current.delete(nodeId);
2125
+ }
2126
+ },
2127
+ []
2128
+ );
2129
+ const clearDragState = react.useCallback(() => {
2130
+ setActiveNodeId(void 0);
2131
+ setDragPreviewLayout(void 0);
2132
+ setOverNodeId(void 0);
2133
+ }, []);
2089
2134
  const setNodeExpanded = (nodeId, expanded) => {
2090
2135
  const next = new Set(resolvedExpandedNodeIds);
2091
2136
  if (expanded) {
@@ -2098,16 +2143,48 @@ function DataExplorerDraggableTree({
2098
2143
  }
2099
2144
  onExpandedNodeIdsChange?.([...next]);
2100
2145
  };
2146
+ const handleDragStart = (event) => {
2147
+ const activeId = String(event.active.id || "");
2148
+ setActiveNodeId(activeId);
2149
+ const elementRect = activeId ? nodeElementsRef.current.get(activeId)?.getBoundingClientRect() : void 0;
2150
+ const initialRect = event.active.rect.current.initial;
2151
+ const rect = elementRect ?? initialRect;
2152
+ const point = getEventClientPoint(event.activatorEvent);
2153
+ const width = rect?.width;
2154
+ const height = rect?.height;
2155
+ const left = rect?.left ?? (point ? point.x - (width ?? 0) / 2 : 0);
2156
+ const top = rect?.top ?? (point ? point.y - (height ?? 0) / 2 : 0);
2157
+ setDragPreviewLayout({
2158
+ initialLeft: left,
2159
+ initialTop: top,
2160
+ left,
2161
+ top,
2162
+ width,
2163
+ height
2164
+ });
2165
+ };
2166
+ const handleDragMove = (event) => {
2167
+ setDragPreviewLayout(
2168
+ (layout) => layout ? {
2169
+ ...layout,
2170
+ left: layout.initialLeft + event.delta.x,
2171
+ top: layout.initialTop + event.delta.y
2172
+ } : layout
2173
+ );
2174
+ };
2101
2175
  const handleDragEnd = (event) => {
2102
2176
  const activeId = String(event.active.id || "");
2103
2177
  const overId = event.over ? String(event.over.id || "") : "";
2104
- setActiveNodeId(void 0);
2105
- setActiveNodeWidth(void 0);
2106
- setOverNodeId(void 0);
2107
- if (!activeId || !overId || activeId === overId || !onDragEnd) return;
2178
+ if (!activeId || !overId || activeId === overId || !onDragEnd) {
2179
+ clearDragState();
2180
+ return;
2181
+ }
2108
2182
  const activeEntry2 = flattenedNodeMap.get(activeId);
2109
2183
  const overEntry = flattenedNodeMap.get(overId);
2110
- if (!activeEntry2 || !overEntry) return;
2184
+ if (!activeEntry2 || !overEntry) {
2185
+ clearDragState();
2186
+ return;
2187
+ }
2111
2188
  const payload = {
2112
2189
  activeNode: activeEntry2.node,
2113
2190
  overNode: overEntry.node,
@@ -2119,7 +2196,61 @@ function DataExplorerDraggableTree({
2119
2196
  context
2120
2197
  };
2121
2198
  void onDragEnd(payload);
2199
+ clearDragState();
2122
2200
  };
2201
+ const dragOverlay = activeEntry && dragPreviewLayout ? /* @__PURE__ */ jsxRuntime.jsx(
2202
+ "div",
2203
+ {
2204
+ "aria-hidden": "true",
2205
+ className: "pointer-events-none fixed z-[1000] min-w-0",
2206
+ style: {
2207
+ left: dragPreviewLayout.left,
2208
+ top: dragPreviewLayout.top,
2209
+ ...overlayStyle
2210
+ },
2211
+ children: /* @__PURE__ */ jsxRuntime.jsx(
2212
+ "div",
2213
+ {
2214
+ className: cn("min-w-0 overflow-hidden shadow-lg", classNames?.overlay),
2215
+ style: overlayStyle,
2216
+ children: /* @__PURE__ */ jsxRuntime.jsx(
2217
+ TreeItemRow,
2218
+ {
2219
+ node: activeEntry.node,
2220
+ depth: activeEntry.depth,
2221
+ indentSize,
2222
+ selected: selectedNodeId === activeEntry.node.id,
2223
+ expanded: activeEntry.node.collapsible === false || resolvedExpandedNodeIds.has(activeEntry.node.id),
2224
+ active: true,
2225
+ over: false,
2226
+ hasChildren: activeEntry.node.collapsible === true || Boolean(activeEntry.node.children?.length),
2227
+ disabled: Boolean(activeEntry.node.disabled),
2228
+ selectable: activeEntry.node.selectable !== false,
2229
+ draggable: activeEntry.node.draggable !== false,
2230
+ activationMode,
2231
+ dragHandleLabel: labels?.dragHandle ?? "Drag",
2232
+ expandLabel: labels?.expand ?? "Expand",
2233
+ collapseLabel: labels?.collapse ?? "Collapse",
2234
+ themeSlots: theme.slots,
2235
+ classNames,
2236
+ itemClassName: activeEntry.node.itemClassName,
2237
+ itemStyle,
2238
+ renderNodeActions,
2239
+ renderContext: {
2240
+ node: activeEntry.node,
2241
+ depth: activeEntry.depth,
2242
+ expanded: activeEntry.node.collapsible === false || resolvedExpandedNodeIds.has(activeEntry.node.id),
2243
+ selected: selectedNodeId === activeEntry.node.id,
2244
+ dragging: true,
2245
+ disabled: Boolean(activeEntry.node.disabled),
2246
+ context: activeEntry.node.context ?? context
2247
+ }
2248
+ }
2249
+ )
2250
+ }
2251
+ )
2252
+ }
2253
+ ) : null;
2123
2254
  if (loading) {
2124
2255
  return /* @__PURE__ */ jsxRuntime.jsx("div", { className: cn(theme.slots.treeRoot, classNames?.root, className), children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: cn(theme.slots.treeLoading, classNames?.loading), children: labels?.loading ?? "Loading..." }) });
2125
2256
  }
@@ -2131,19 +2262,13 @@ function DataExplorerDraggableTree({
2131
2262
  {
2132
2263
  sensors,
2133
2264
  collisionDetection: core.closestCenter,
2134
- onDragStart: (event) => {
2135
- setActiveNodeId(String(event.active.id || ""));
2136
- setActiveNodeWidth(event.active.rect.current.initial?.width);
2137
- },
2265
+ onDragStart: handleDragStart,
2266
+ onDragMove: handleDragMove,
2138
2267
  onDragOver: (event) => {
2139
2268
  setOverNodeId(event.over ? String(event.over.id || "") : void 0);
2140
2269
  },
2141
2270
  onDragEnd: handleDragEnd,
2142
- onDragCancel: () => {
2143
- setActiveNodeId(void 0);
2144
- setActiveNodeWidth(void 0);
2145
- setOverNodeId(void 0);
2146
- },
2271
+ onDragCancel: clearDragState,
2147
2272
  children: [
2148
2273
  /* @__PURE__ */ jsxRuntime.jsx(sortable.SortableContext, { items: sortableIds, strategy: sortable.verticalListSortingStrategy, children: /* @__PURE__ */ jsxRuntime.jsx(
2149
2274
  "div",
@@ -2178,63 +2303,15 @@ function DataExplorerDraggableTree({
2178
2303
  renderNodeActions,
2179
2304
  renderNodeChildren,
2180
2305
  onSelect: (nextNode) => onSelectNode?.(nextNode, context),
2181
- onToggle: (nodeId) => setNodeExpanded(nodeId, !expanded)
2306
+ onToggle: (nodeId) => setNodeExpanded(nodeId, !expanded),
2307
+ registerNodeElement
2182
2308
  },
2183
2309
  node.id
2184
2310
  );
2185
2311
  }) })
2186
2312
  }
2187
2313
  ) }),
2188
- /* @__PURE__ */ jsxRuntime.jsx(
2189
- core.DragOverlay,
2190
- {
2191
- dropAnimation: {
2192
- duration: treeItemDropTransition.duration,
2193
- easing: treeItemDropTransition.easing
2194
- },
2195
- children: activeEntry ? /* @__PURE__ */ jsxRuntime.jsx(
2196
- "div",
2197
- {
2198
- className: cn("min-w-0 overflow-hidden shadow-lg", classNames?.overlay),
2199
- style: overlayStyle,
2200
- children: /* @__PURE__ */ jsxRuntime.jsx(
2201
- TreeItemRow,
2202
- {
2203
- node: activeEntry.node,
2204
- depth: activeEntry.depth,
2205
- indentSize,
2206
- selected: selectedNodeId === activeEntry.node.id,
2207
- expanded: activeEntry.node.collapsible === false || resolvedExpandedNodeIds.has(activeEntry.node.id),
2208
- active: true,
2209
- over: false,
2210
- hasChildren: activeEntry.node.collapsible === true || Boolean(activeEntry.node.children?.length),
2211
- disabled: Boolean(activeEntry.node.disabled),
2212
- selectable: activeEntry.node.selectable !== false,
2213
- draggable: activeEntry.node.draggable !== false,
2214
- activationMode,
2215
- dragHandleLabel: labels?.dragHandle ?? "Drag",
2216
- expandLabel: labels?.expand ?? "Expand",
2217
- collapseLabel: labels?.collapse ?? "Collapse",
2218
- themeSlots: theme.slots,
2219
- classNames,
2220
- itemClassName: activeEntry.node.itemClassName,
2221
- itemStyle,
2222
- renderNodeActions,
2223
- renderContext: {
2224
- node: activeEntry.node,
2225
- depth: activeEntry.depth,
2226
- expanded: activeEntry.node.collapsible === false || resolvedExpandedNodeIds.has(activeEntry.node.id),
2227
- selected: selectedNodeId === activeEntry.node.id,
2228
- dragging: true,
2229
- disabled: Boolean(activeEntry.node.disabled),
2230
- context: activeEntry.node.context ?? context
2231
- }
2232
- }
2233
- )
2234
- }
2235
- ) : null
2236
- }
2237
- )
2314
+ typeof document === "undefined" ? dragOverlay : dragOverlay ? reactDom.createPortal(dragOverlay, document.body) : null
2238
2315
  ]
2239
2316
  }
2240
2317
  );