@lobehub/ui 2.16.1 → 2.16.3
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/es/Accordion/AccordionItem.js +2 -2
- package/es/DraggablePanel/DraggablePanel.js +148 -68
- package/es/DraggableSideNav/DraggableSideNav.js +393 -285
- package/es/DraggableSideNav/style.js +2 -2
- package/es/DraggableSideNav/type.d.ts +4 -35
- package/es/hooks/useMarkdown/latex.d.ts +124 -12
- package/es/hooks/useMarkdown/latex.js +370 -66
- package/package.json +1 -1
|
@@ -115,7 +115,7 @@ var AccordionItem = /*#__PURE__*/memo(function (_ref) {
|
|
|
115
115
|
height: 'auto',
|
|
116
116
|
opacity: 1,
|
|
117
117
|
transition: {
|
|
118
|
-
duration: 0.
|
|
118
|
+
duration: 0.2,
|
|
119
119
|
ease: [0.4, 0, 0.2, 1]
|
|
120
120
|
}
|
|
121
121
|
},
|
|
@@ -123,7 +123,7 @@ var AccordionItem = /*#__PURE__*/memo(function (_ref) {
|
|
|
123
123
|
height: 0,
|
|
124
124
|
opacity: 0,
|
|
125
125
|
transition: {
|
|
126
|
-
duration: 0.
|
|
126
|
+
duration: 0.2,
|
|
127
127
|
ease: [0.4, 0, 0.2, 1]
|
|
128
128
|
}
|
|
129
129
|
}
|
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
4
|
-
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
5
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
6
|
-
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
7
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
8
|
-
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
9
4
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
10
5
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
11
6
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
12
7
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
13
8
|
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
14
9
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
10
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
11
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
12
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
13
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
14
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
15
15
|
import { useHover } from 'ahooks';
|
|
16
16
|
import { ConfigProvider } from 'antd';
|
|
17
17
|
import { cva } from 'class-variance-authority';
|
|
18
18
|
import { ChevronDown, ChevronLeft, ChevronRight, ChevronUp } from 'lucide-react';
|
|
19
19
|
import { Resizable } from 're-resizable';
|
|
20
|
-
import { memo, use, useEffect, useMemo, useRef,
|
|
20
|
+
import { memo, use, useCallback, useEffect, useMemo, useReducer, useRef, useTransition } from 'react';
|
|
21
21
|
import { Center } from 'react-layout-kit';
|
|
22
22
|
import useControlledState from 'use-merge-value';
|
|
23
23
|
import Icon from "../Icon";
|
|
@@ -35,6 +35,37 @@ var DEFAULT_MODE = 'fixed';
|
|
|
35
35
|
var DEFAULT_EXPANDABLE = true;
|
|
36
36
|
var DEFAULT_EXPAND = true;
|
|
37
37
|
var DEFAULT_SHOW_HANDLE_WIDE_AREA = true;
|
|
38
|
+
|
|
39
|
+
// State reducer for better state management
|
|
40
|
+
|
|
41
|
+
function draggablePanelReducer(state, action) {
|
|
42
|
+
switch (action.type) {
|
|
43
|
+
case 'START_RESIZE':
|
|
44
|
+
{
|
|
45
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
46
|
+
isResizing: true,
|
|
47
|
+
showExpand: false
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
case 'STOP_RESIZE':
|
|
51
|
+
{
|
|
52
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
53
|
+
isResizing: false,
|
|
54
|
+
showExpand: true
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
case 'SET_SHOW_EXPAND':
|
|
58
|
+
{
|
|
59
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
60
|
+
showExpand: action.payload
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
default:
|
|
64
|
+
{
|
|
65
|
+
return state;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
38
69
|
var DraggablePanel = /*#__PURE__*/memo(function (_ref) {
|
|
39
70
|
var _ref$headerHeight = _ref.headerHeight,
|
|
40
71
|
headerHeight = _ref$headerHeight === void 0 ? DEFAULT_HEADER_HEIGHT : _ref$headerHeight,
|
|
@@ -78,6 +109,13 @@ var DraggablePanel = /*#__PURE__*/memo(function (_ref) {
|
|
|
78
109
|
var ref = useRef(null);
|
|
79
110
|
var isHovering = useHover(ref);
|
|
80
111
|
var isVertical = placement === 'top' || placement === 'bottom';
|
|
112
|
+
var _useTransition = useTransition(),
|
|
113
|
+
_useTransition2 = _slicedToArray(_useTransition, 2),
|
|
114
|
+
isPending = _useTransition2[0],
|
|
115
|
+
startTransition = _useTransition2[1];
|
|
116
|
+
|
|
117
|
+
// Use ref for hover timeout to avoid memory leaks
|
|
118
|
+
var hoverTimeoutRef = useRef(undefined);
|
|
81
119
|
|
|
82
120
|
// inherit direction from Ant Design ConfigProvider
|
|
83
121
|
var _use = use(ConfigProvider.ConfigContext),
|
|
@@ -104,23 +142,46 @@ var DraggablePanel = /*#__PURE__*/memo(function (_ref) {
|
|
|
104
142
|
isExpand = _useControlledState2[0],
|
|
105
143
|
setIsExpand = _useControlledState2[1];
|
|
106
144
|
|
|
107
|
-
//
|
|
145
|
+
// Initialize state with useReducer for better performance
|
|
146
|
+
var initialState = {
|
|
147
|
+
isResizing: false,
|
|
148
|
+
showExpand: true
|
|
149
|
+
};
|
|
150
|
+
var _useReducer = useReducer(draggablePanelReducer, initialState),
|
|
151
|
+
_useReducer2 = _slicedToArray(_useReducer, 2),
|
|
152
|
+
state = _useReducer2[0],
|
|
153
|
+
dispatch = _useReducer2[1];
|
|
154
|
+
|
|
155
|
+
// Auto-expand on hover if not pinned with optimized transition
|
|
108
156
|
useEffect(function () {
|
|
109
157
|
if (pin) return;
|
|
158
|
+
|
|
159
|
+
// Clear previous timeout
|
|
160
|
+
if (hoverTimeoutRef.current) {
|
|
161
|
+
clearTimeout(hoverTimeoutRef.current);
|
|
162
|
+
}
|
|
110
163
|
if (isHovering && !isExpand) {
|
|
111
|
-
|
|
164
|
+
startTransition(function () {
|
|
165
|
+
setIsExpand(true);
|
|
166
|
+
});
|
|
112
167
|
} else if (!isHovering && isExpand) {
|
|
113
|
-
|
|
168
|
+
// Add a small delay before collapsing to prevent flickering
|
|
169
|
+
hoverTimeoutRef.current = setTimeout(function () {
|
|
170
|
+
startTransition(function () {
|
|
171
|
+
setIsExpand(false);
|
|
172
|
+
});
|
|
173
|
+
}, 150);
|
|
114
174
|
}
|
|
115
175
|
}, [pin, isHovering, isExpand, setIsExpand]);
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
176
|
+
|
|
177
|
+
// Cleanup timeout on unmount
|
|
178
|
+
useEffect(function () {
|
|
179
|
+
return function () {
|
|
180
|
+
if (hoverTimeoutRef.current) {
|
|
181
|
+
clearTimeout(hoverTimeoutRef.current);
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
}, []);
|
|
124
185
|
var canResizing = resize !== false && isExpand;
|
|
125
186
|
|
|
126
187
|
// Style variants for the panel
|
|
@@ -265,70 +326,84 @@ var DraggablePanel = /*#__PURE__*/memo(function (_ref) {
|
|
|
265
326
|
}
|
|
266
327
|
}, [internalPlacement]);
|
|
267
328
|
|
|
329
|
+
// Toggle expand state with transition for better performance
|
|
330
|
+
var toggleExpand = useCallback(function () {
|
|
331
|
+
if (!expandable) return;
|
|
332
|
+
startTransition(function () {
|
|
333
|
+
setIsExpand(!isExpand);
|
|
334
|
+
});
|
|
335
|
+
}, [expandable, isExpand, setIsExpand]);
|
|
336
|
+
|
|
268
337
|
// Toggle handle component
|
|
269
|
-
var handle =
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
children: /*#__PURE__*/_jsx(Center, {
|
|
277
|
-
className: classNames === null || classNames === void 0 ? void 0 : classNames.handle,
|
|
278
|
-
onClick: function onClick() {
|
|
279
|
-
return setIsExpand(!isExpand);
|
|
338
|
+
var handle = useMemo(function () {
|
|
339
|
+
return /*#__PURE__*/_jsx(Center, {
|
|
340
|
+
className: toggleVariants({
|
|
341
|
+
placement: internalPlacement
|
|
342
|
+
}),
|
|
343
|
+
style: {
|
|
344
|
+
opacity: isExpand ? pin ? undefined : 0 : showHandleWhenCollapsed ? 1 : 0
|
|
280
345
|
},
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
346
|
+
children: /*#__PURE__*/_jsx(Center, {
|
|
347
|
+
className: classNames === null || classNames === void 0 ? void 0 : classNames.handle,
|
|
348
|
+
onClick: toggleExpand,
|
|
349
|
+
style: customStyles === null || customStyles === void 0 ? void 0 : customStyles.handle,
|
|
350
|
+
children: /*#__PURE__*/_jsx(Icon, {
|
|
351
|
+
className: styles.handlerIcon,
|
|
352
|
+
icon: Arrow,
|
|
353
|
+
size: 16,
|
|
354
|
+
style: {
|
|
355
|
+
marginBottom: internalPlacement === 'top' ? 4 : 0,
|
|
356
|
+
marginLeft: internalPlacement === 'right' ? 4 : 0,
|
|
357
|
+
marginRight: internalPlacement === 'left' ? 4 : 0,
|
|
358
|
+
marginTop: internalPlacement === 'bottom' ? 4 : 0,
|
|
359
|
+
transform: "rotate(".concat(isExpand ? 180 : 0, "deg)"),
|
|
360
|
+
transition: 'transform 0.3s ease'
|
|
361
|
+
}
|
|
362
|
+
})
|
|
293
363
|
})
|
|
294
|
-
})
|
|
295
|
-
});
|
|
364
|
+
});
|
|
365
|
+
}, [toggleVariants, internalPlacement, isExpand, pin, showHandleWhenCollapsed, classNames === null || classNames === void 0 ? void 0 : classNames.handle, toggleExpand, customStyles === null || customStyles === void 0 ? void 0 : customStyles.handle, styles.handlerIcon, Arrow]);
|
|
296
366
|
|
|
297
|
-
// Handle resize events
|
|
298
|
-
var handleResize = function
|
|
367
|
+
// Handle resize events with memoization
|
|
368
|
+
var handleResize = useCallback(function (_, _direction, reference_, delta) {
|
|
299
369
|
onSizeDragging === null || onSizeDragging === void 0 || onSizeDragging(delta, {
|
|
300
370
|
height: reference_.style.height,
|
|
301
371
|
width: reference_.style.width
|
|
302
372
|
});
|
|
303
|
-
};
|
|
304
|
-
var handleResizeStart = function
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
373
|
+
}, [onSizeDragging]);
|
|
374
|
+
var handleResizeStart = useCallback(function () {
|
|
375
|
+
dispatch({
|
|
376
|
+
type: 'START_RESIZE'
|
|
377
|
+
});
|
|
378
|
+
}, []);
|
|
379
|
+
var handleResizeStop = useCallback(function (e, direction, reference_, delta) {
|
|
380
|
+
dispatch({
|
|
381
|
+
type: 'STOP_RESIZE'
|
|
382
|
+
});
|
|
311
383
|
onSizeChange === null || onSizeChange === void 0 || onSizeChange(delta, {
|
|
312
384
|
height: reference_.style.height,
|
|
313
385
|
width: reference_.style.width
|
|
314
386
|
});
|
|
315
|
-
};
|
|
387
|
+
}, [onSizeChange]);
|
|
316
388
|
|
|
317
389
|
// Main panel content
|
|
318
|
-
var inner =
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
390
|
+
var inner = useMemo(function () {
|
|
391
|
+
return /*#__PURE__*/_jsx(Resizable, _objectSpread(_objectSpread({}, sizeProps), {}, {
|
|
392
|
+
className: cx(styles.panel, classNames === null || classNames === void 0 ? void 0 : classNames.content),
|
|
393
|
+
enable: canResizing ? resizing : undefined,
|
|
394
|
+
handleClasses: canResizing ? _defineProperty({}, reversePlacement(internalPlacement), cx(handleVariants({
|
|
395
|
+
placement: reversePlacement(internalPlacement)
|
|
396
|
+
}), showHandleHighlight && styles.handleHighlight)) : {},
|
|
397
|
+
onResize: handleResize,
|
|
398
|
+
onResizeStart: handleResizeStart,
|
|
399
|
+
onResizeStop: handleResizeStop,
|
|
400
|
+
style: _objectSpread({
|
|
401
|
+
opacity: isPending ? 0.95 : 1,
|
|
402
|
+
transition: state.isResizing ? 'unset' : undefined
|
|
403
|
+
}, style),
|
|
404
|
+
children: children
|
|
405
|
+
}));
|
|
406
|
+
}, [sizeProps, styles.panel, classNames === null || classNames === void 0 ? void 0 : classNames.content, canResizing, resizing, internalPlacement, handleVariants, showHandleHighlight, styles.handleHighlight, handleResize, handleResizeStart, handleResizeStop, state.isResizing, isPending, style, children, cx]);
|
|
332
407
|
|
|
333
408
|
// For fullscreen mode, return a simpler layout
|
|
334
409
|
if (fullscreen) {
|
|
@@ -344,8 +419,13 @@ var DraggablePanel = /*#__PURE__*/memo(function (_ref) {
|
|
|
344
419
|
}), className),
|
|
345
420
|
dir: dir,
|
|
346
421
|
ref: ref,
|
|
347
|
-
children: [expandable && showExpand && handle, destroyOnClose ? isExpand && inner : inner]
|
|
422
|
+
children: [expandable && state.showExpand && handle, destroyOnClose ? isExpand && inner : inner]
|
|
348
423
|
});
|
|
424
|
+
},
|
|
425
|
+
// Custom comparison function to avoid unnecessary re-renders
|
|
426
|
+
function (prevProps, nextProps) {
|
|
427
|
+
// Only re-render if critical props change
|
|
428
|
+
return prevProps.placement === nextProps.placement && prevProps.mode === nextProps.mode && prevProps.expand === nextProps.expand && prevProps.pin === nextProps.pin && prevProps.fullscreen === nextProps.fullscreen && prevProps.size === nextProps.size && prevProps.defaultSize === nextProps.defaultSize && prevProps.minWidth === nextProps.minWidth && prevProps.minHeight === nextProps.minHeight && prevProps.maxWidth === nextProps.maxWidth && prevProps.maxHeight === nextProps.maxHeight && prevProps.expandable === nextProps.expandable && prevProps.resize === nextProps.resize && prevProps.showHandleWhenCollapsed === nextProps.showHandleWhenCollapsed && prevProps.destroyOnClose === nextProps.destroyOnClose && prevProps.showBorder === nextProps.showBorder && prevProps.showHandleHighlight === nextProps.showHandleHighlight && prevProps.showHandleWideArea === nextProps.showHandleWideArea && prevProps.backgroundColor === nextProps.backgroundColor && prevProps.className === nextProps.className && prevProps.dir === nextProps.dir && prevProps.headerHeight === nextProps.headerHeight && prevProps.onSizeChange === nextProps.onSizeChange && prevProps.onSizeDragging === nextProps.onSizeDragging && prevProps.onExpandChange === nextProps.onExpandChange && prevProps.children === nextProps.children;
|
|
349
429
|
});
|
|
350
430
|
DraggablePanel.displayName = 'DraggablePanel';
|
|
351
431
|
export default DraggablePanel;
|