react-public-components 1.1.3 → 1.1.5

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/index.cjs CHANGED
@@ -216,7 +216,7 @@ var CollapseBox_default = CollapsibleBox;
216
216
  // Splitter/index.tsx
217
217
  var import_react2 = __toESM(require("react"), 1);
218
218
  var import_jsx_runtime3 = require("react/jsx-runtime");
219
- var DRAGGER_SIZE = 8;
219
+ var DEFAULT_DRAGGER_SIZE = 4;
220
220
  var SplitterPanel = ({ children }) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_jsx_runtime3.Fragment, { children });
221
221
  var isPercentSize = (value) => typeof value === "string" && value.endsWith("%");
222
222
  var parseSize = (value, total, fallback) => {
@@ -234,6 +234,7 @@ var clamp = (value, min, max) => Math.min(Math.max(value, min), max);
234
234
  var CustomSplitter = ({
235
235
  children,
236
236
  className,
237
+ draggerSize = DEFAULT_DRAGGER_SIZE,
237
238
  lazy = false,
238
239
  onResize,
239
240
  onResizeEnd,
@@ -245,7 +246,6 @@ var CustomSplitter = ({
245
246
  const resolvedOrientation = orientation != null ? orientation : vertical ? "vertical" : "horizontal";
246
247
  const rootRef = (0, import_react2.useRef)(null);
247
248
  const sizesRef = (0, import_react2.useRef)([]);
248
- const lastNonZeroSizesRef = (0, import_react2.useRef)([]);
249
249
  const [containerSize, setContainerSize] = (0, import_react2.useState)(0);
250
250
  const [draggingIndex, setDraggingIndex] = (0, import_react2.useState)(null);
251
251
  const [hoveredIndex, setHoveredIndex] = (0, import_react2.useState)(null);
@@ -256,7 +256,7 @@ var CustomSplitter = ({
256
256
  ),
257
257
  [children]
258
258
  );
259
- const trackSize = Math.max(0, containerSize - Math.max(0, panels.length - 1) * DRAGGER_SIZE);
259
+ const trackSize = Math.max(0, containerSize - Math.max(0, panels.length - 1) * draggerSize);
260
260
  const getPanelMin = (0, import_react2.useCallback)(
261
261
  (index) => {
262
262
  var _a;
@@ -286,6 +286,9 @@ var CustomSplitter = ({
286
286
  if (size <= 1) {
287
287
  return 0;
288
288
  }
289
+ if (size < getPanelMin(index)) {
290
+ return size;
291
+ }
289
292
  return clamp(size, getPanelMin(index), getPanelMax(index));
290
293
  });
291
294
  },
@@ -324,11 +327,6 @@ var CustomSplitter = ({
324
327
  const normalized = normalizeToTrack(nextSizes);
325
328
  setSizes(normalized);
326
329
  sizesRef.current = normalized;
327
- normalized.forEach((size, index) => {
328
- if (size > 1) {
329
- lastNonZeroSizesRef.current[index] = size;
330
- }
331
- });
332
330
  if (notify) {
333
331
  onResize == null ? void 0 : onResize(roundSizes(normalized));
334
332
  }
@@ -352,17 +350,16 @@ var CustomSplitter = ({
352
350
  setSizes((previous) => {
353
351
  const nextSizes = buildInitialSizes(previous);
354
352
  sizesRef.current = nextSizes;
355
- lastNonZeroSizesRef.current = nextSizes.map(
356
- (size) => Math.max(size, trackSize / Math.max(panels.length, 1))
357
- );
358
353
  return nextSizes;
359
354
  });
360
- }, [buildInitialSizes, panels.length, trackSize]);
355
+ }, [buildInitialSizes]);
361
356
  const getResizedPair = (0, import_react2.useCallback)(
362
357
  (sourceSizes, index, delta) => {
363
358
  const nextSizes = [...sourceSizes];
364
- const leftMin = getPanelMin(index);
365
- const rightMin = getPanelMin(index + 1);
359
+ const isLeftCollapsed = sourceSizes[index] <= 1;
360
+ const isRightCollapsed = sourceSizes[index + 1] <= 1;
361
+ const leftMin = isLeftCollapsed ? 0 : getPanelMin(index);
362
+ const rightMin = isRightCollapsed ? 0 : getPanelMin(index + 1);
366
363
  const leftMax = getPanelMax(index);
367
364
  const rightMax = getPanelMax(index + 1);
368
365
  const minDelta = Math.max(leftMin - sourceSizes[index], sourceSizes[index + 1] - rightMax);
@@ -410,14 +407,16 @@ var CustomSplitter = ({
410
407
  document.addEventListener("pointerup", handlePointerUp);
411
408
  };
412
409
  const toggleCollapse = (index, neighborIndex) => {
410
+ var _a;
413
411
  const nextSizes = [...sizesRef.current];
414
412
  if (nextSizes[index] > 1) {
415
- lastNonZeroSizesRef.current[index] = nextSizes[index];
416
413
  nextSizes[neighborIndex] += nextSizes[index];
417
414
  nextSizes[index] = 0;
418
415
  } else {
419
- const restoredSize = lastNonZeroSizesRef.current[index] || parseSize(panels[index].props.defaultSize, trackSize, trackSize / panels.length);
420
- nextSizes[index] = clamp(restoredSize, getPanelMin(index), getPanelMax(index));
416
+ const initialSizes = buildInitialSizes();
417
+ const initialSize = (_a = initialSizes[index]) != null ? _a : parseSize(panels[index].props.defaultSize, trackSize, trackSize / panels.length);
418
+ const restoredSize = clamp(initialSize, getPanelMin(index), getPanelMax(index));
419
+ nextSizes[index] = restoredSize;
421
420
  nextSizes[neighborIndex] = Math.max(0, nextSizes[neighborIndex] - nextSizes[index]);
422
421
  }
423
422
  updateSizes(nextSizes);
@@ -454,6 +453,7 @@ var CustomSplitter = ({
454
453
  return null;
455
454
  }
456
455
  const Icon = resolvedOrientation === "horizontal" ? direction === "start" ? LeftOutlined : RightOutlined : direction === "start" ? UpOutlined : DownOutlined;
456
+ const isHorizontal = resolvedOrientation === "horizontal";
457
457
  return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
458
458
  "button",
459
459
  {
@@ -467,173 +467,203 @@ var CustomSplitter = ({
467
467
  alignItems: "center",
468
468
  background: "#fff",
469
469
  border: "1px solid #d9d9d9",
470
- borderRadius: 4,
470
+ borderRadius: 3,
471
471
  color: "#595959",
472
472
  cursor: "pointer",
473
473
  display: "flex",
474
- height: 20,
474
+ height: isHorizontal ? 40 : 14,
475
+ width: isHorizontal ? 14 : 40,
475
476
  justifyContent: "center",
476
477
  padding: 0,
477
- width: 20,
478
- fontSize: 12,
479
- boxShadow: "0 2px 4px rgba(0,0,0,0.08)"
478
+ fontSize: 10,
479
+ boxShadow: "0 1px 2px rgba(0, 0, 0, 0.05)",
480
+ transition: "all 0.2s ease"
480
481
  },
481
482
  type: "button",
482
- children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Icon, {})
483
- }
484
- );
485
- };
486
- const renderCollapsedExpandHandle = (panelIndex) => {
487
- var _a;
488
- const panel = panels[panelIndex];
489
- if (!(panel == null ? void 0 : panel.props.collapsible)) {
490
- return null;
491
- }
492
- const isCollapsed = sizes.length > 0 && ((_a = sizes[panelIndex]) != null ? _a : 0) <= 1;
493
- if (!isCollapsed) {
494
- return null;
495
- }
496
- const isFirstPanel = panelIndex === 0;
497
- const neighborIndex = isFirstPanel ? panelIndex + 1 : panelIndex - 1;
498
- const Icon = resolvedOrientation === "horizontal" ? isFirstPanel ? RightOutlined : LeftOutlined : isFirstPanel ? DownOutlined : UpOutlined;
499
- const label = resolvedOrientation === "horizontal" ? isFirstPanel ? "\u5C55\u5F00\u5DE6\u4FA7\u9762\u677F" : "\u5C55\u5F00\u53F3\u4FA7\u9762\u677F" : isFirstPanel ? "\u5C55\u5F00\u4E0A\u65B9\u9762\u677F" : "\u5C55\u5F00\u4E0B\u65B9\u9762\u677F";
500
- const positionStyle = resolvedOrientation === "horizontal" ? isFirstPanel ? { left: 8, top: "50%", transform: "translateY(-50%)" } : { right: 8, top: "50%", transform: "translateY(-50%)" } : isFirstPanel ? { top: 8, left: "50%", transform: "translateX(-50%)" } : { bottom: 8, left: "50%", transform: "translateX(-50%)" };
501
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
502
- "button",
503
- {
504
- "aria-label": label,
505
- title: label,
506
- onClick: (event) => {
507
- event.stopPropagation();
508
- toggleCollapse(panelIndex, neighborIndex);
483
+ onMouseEnter: (e) => {
484
+ e.currentTarget.style.background = "#e5e7eb";
485
+ e.currentTarget.style.color = "#1f2937";
509
486
  },
510
- style: {
511
- position: "absolute",
512
- alignItems: "center",
513
- background: "#fff",
514
- border: "1px solid #1677ff",
515
- borderRadius: 4,
516
- color: "#1677ff",
517
- cursor: "pointer",
518
- display: "flex",
519
- height: 24,
520
- justifyContent: "center",
521
- padding: 0,
522
- width: 24,
523
- fontSize: 12,
524
- boxShadow: "0 2px 8px rgba(22, 119, 255, 0.35)",
525
- zIndex: 20,
526
- ...positionStyle
487
+ onMouseLeave: (e) => {
488
+ e.currentTarget.style.background = "#fff";
489
+ e.currentTarget.style.color = "#595959";
527
490
  },
528
- type: "button",
529
491
  children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Icon, {})
530
- },
531
- `collapsed-handle-${panelIndex}`
492
+ }
532
493
  );
533
494
  };
534
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className, ref: rootRef, style: rootStyle, children: [
535
- panels.map((panel, index) => {
536
- var _a, _b, _c;
537
- const isHidden = sizes[index] <= 1;
538
- const isLeftOrTopCollapsed = ((_a = sizes[index]) != null ? _a : 0) <= 1;
539
- const isRightOrBottomCollapsed = ((_b = sizes[index + 1]) != null ? _b : 0) <= 1;
540
- const isAnyCollapsed = isLeftOrTopCollapsed || isRightOrBottomCollapsed;
541
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_react2.default.Fragment, { children: [
542
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
543
- "div",
544
- {
545
- style: {
546
- background: index % 2 ? "#fff" : "#fafafa",
547
- boxSizing: "border-box",
548
- flex: `0 0 ${(_c = sizes[index]) != null ? _c : 0}px`,
549
- minHeight: 0,
550
- minWidth: 0,
551
- overflow: "auto",
552
- padding: isHidden ? 0 : 16,
553
- transition: draggingIndex === null ? "flex-basis 0.2s ease" : void 0,
554
- ...panel.props.style
555
- },
556
- children: !isHidden && panel.props.children
557
- }
558
- ),
559
- index < panels.length - 1 && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
560
- "div",
561
- {
562
- "aria-orientation": resolvedOrientation,
563
- onClick: () => {
564
- if (isRightOrBottomCollapsed) {
565
- toggleCollapse(index + 1, index);
566
- } else if (isLeftOrTopCollapsed) {
567
- toggleCollapse(index, index + 1);
495
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className, ref: rootRef, style: rootStyle, children: panels.map((panel, index) => {
496
+ var _a, _b, _c, _d;
497
+ const isHidden = sizes[index] <= 1;
498
+ const isLeftOrTopCollapsed = ((_a = sizes[index]) != null ? _a : 0) <= 1;
499
+ const isRightOrBottomCollapsed = ((_b = sizes[index + 1]) != null ? _b : 0) <= 1;
500
+ const isAnyCollapsed = isLeftOrTopCollapsed || isRightOrBottomCollapsed;
501
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_react2.default.Fragment, { children: [
502
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
503
+ "div",
504
+ {
505
+ style: {
506
+ background: index % 2 ? "#fff" : "#fafafa",
507
+ boxSizing: "border-box",
508
+ flex: `0 0 ${(_c = sizes[index]) != null ? _c : 0}px`,
509
+ minHeight: 0,
510
+ minWidth: 0,
511
+ overflow: "hidden",
512
+ position: "relative",
513
+ transition: draggingIndex === null ? "flex-basis 0.2s ease" : void 0,
514
+ ...panel.props.style
515
+ },
516
+ children: !isHidden && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
517
+ "div",
518
+ {
519
+ style: {
520
+ boxSizing: "border-box",
521
+ height: "100%",
522
+ overflow: "auto",
523
+ padding: ((_d = sizes[index]) != null ? _d : 0) < 32 ? 0 : 16,
524
+ width: "100%"
525
+ },
526
+ children: panel.props.children
527
+ }
528
+ )
529
+ }
530
+ ),
531
+ index < panels.length - 1 && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
532
+ "div",
533
+ {
534
+ "aria-orientation": resolvedOrientation,
535
+ onDoubleClick: resetSizes,
536
+ onKeyDown: (event) => {
537
+ const step = event.shiftKey ? 40 : 10;
538
+ const directionMap = resolvedOrientation === "horizontal" ? { ArrowLeft: -step, ArrowRight: step } : { ArrowUp: -step, ArrowDown: step };
539
+ const delta = directionMap[event.key];
540
+ if (delta !== void 0) {
541
+ event.preventDefault();
542
+ resizePair(index, delta);
543
+ }
544
+ },
545
+ onPointerDown: (event) => startResize(index, event),
546
+ onPointerEnter: () => setHoveredIndex(index),
547
+ onPointerLeave: () => setHoveredIndex(null),
548
+ role: "separator",
549
+ title: "\u62D6\u52A8\u8C03\u6574\u5927\u5C0F\uFF0C\u53CC\u51FB\u91CD\u7F6E",
550
+ style: {
551
+ alignItems: "center",
552
+ background: hoveredIndex === index || draggingIndex === index ? "#e6f4ff" : "#f5f5f5",
553
+ boxSizing: "border-box",
554
+ cursor: resolvedOrientation === "horizontal" ? "col-resize" : "row-resize",
555
+ display: "flex",
556
+ flex: `0 0 ${draggerSize}px`,
557
+ justifyContent: "center",
558
+ outline: "none",
559
+ position: "relative",
560
+ userSelect: "none",
561
+ zIndex: isAnyCollapsed ? 2 : 1
562
+ },
563
+ tabIndex: 0,
564
+ children: [
565
+ (hoveredIndex === index || draggingIndex === index || !isAnyCollapsed) && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
566
+ "div",
567
+ {
568
+ style: {
569
+ background: hoveredIndex === index || draggingIndex === index ? "#1677ff" : "#d9d9d9",
570
+ borderRadius: 2,
571
+ height: resolvedOrientation === "horizontal" ? 40 : 2,
572
+ width: resolvedOrientation === "horizontal" ? 2 : 40
573
+ }
568
574
  }
569
- },
570
- onDoubleClick: resetSizes,
571
- onKeyDown: (event) => {
572
- const step = event.shiftKey ? 40 : 10;
573
- const directionMap = resolvedOrientation === "horizontal" ? { ArrowLeft: -step, ArrowRight: step } : { ArrowUp: -step, ArrowDown: step };
574
- const delta = directionMap[event.key];
575
- if (delta !== void 0) {
576
- event.preventDefault();
577
- resizePair(index, delta);
575
+ ),
576
+ !isAnyCollapsed && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
577
+ "div",
578
+ {
579
+ style: {
580
+ position: "absolute",
581
+ top: "50%",
582
+ left: "50%",
583
+ transform: "translate(-50%, -50%)",
584
+ display: "flex",
585
+ flexDirection: resolvedOrientation === "horizontal" ? "row" : "column",
586
+ alignItems: "center",
587
+ justifyContent: "center",
588
+ gap: 2,
589
+ opacity: hoveredIndex === index || draggingIndex === index ? 1 : 0,
590
+ pointerEvents: hoveredIndex === index || draggingIndex === index ? "auto" : "none",
591
+ transition: "opacity 0.15s ease",
592
+ zIndex: 5
593
+ },
594
+ children: [
595
+ renderCollapseButton(index, index, "start"),
596
+ renderCollapseButton(index, index + 1, "end")
597
+ ]
578
598
  }
579
- },
580
- onPointerDown: (event) => startResize(index, event),
581
- onPointerEnter: () => setHoveredIndex(index),
582
- onPointerLeave: () => setHoveredIndex(null),
583
- role: "separator",
584
- title: isAnyCollapsed ? "\u70B9\u51FB\u53EF\u5C55\u5F00\u6062\u590D\u9762\u677F" : "\u62D6\u52A8\u8C03\u6574\u5927\u5C0F\uFF0C\u53CC\u51FB\u91CD\u7F6E",
585
- style: {
586
- alignItems: "center",
587
- background: hoveredIndex === index || draggingIndex === index || isAnyCollapsed ? "#e6f4ff" : "#f5f5f5",
588
- boxSizing: "border-box",
589
- cursor: isAnyCollapsed ? "pointer" : resolvedOrientation === "horizontal" ? "col-resize" : "row-resize",
590
- display: "flex",
591
- flex: `0 0 ${DRAGGER_SIZE}px`,
592
- justifyContent: "center",
593
- outline: "none",
594
- position: "relative",
595
- userSelect: "none",
596
- zIndex: isAnyCollapsed ? 2 : 1
597
- },
598
- tabIndex: 0,
599
- children: [
600
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
601
- "div",
602
- {
603
- style: {
604
- background: hoveredIndex === index || draggingIndex === index || isAnyCollapsed ? "#1677ff" : "#d9d9d9",
605
- borderRadius: 2,
606
- height: resolvedOrientation === "horizontal" ? 48 : 2,
607
- width: resolvedOrientation === "horizontal" ? 2 : 48
608
- }
609
- }
610
- ),
611
- !isAnyCollapsed && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
612
- "div",
613
- {
614
- style: {
615
- position: "absolute",
616
- display: "flex",
617
- flexDirection: resolvedOrientation === "horizontal" ? "column" : "row",
618
- gap: 4,
619
- opacity: hoveredIndex === index ? 1 : 0.85,
620
- transition: "opacity 0.15s ease",
621
- pointerEvents: "auto",
622
- zIndex: 5
623
- },
624
- children: [
625
- renderCollapseButton(index, index, "start"),
626
- renderCollapseButton(index, index + 1, "end")
627
- ]
628
- }
629
- )
630
- ]
631
- }
632
- )
633
- ] }, index);
634
- }),
635
- panels.map((_, index) => renderCollapsedExpandHandle(index))
636
- ] });
599
+ ),
600
+ isAnyCollapsed && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
601
+ "div",
602
+ {
603
+ style: {
604
+ position: "absolute",
605
+ top: resolvedOrientation === "horizontal" ? "50%" : isLeftOrTopCollapsed ? 0 : void 0,
606
+ bottom: resolvedOrientation === "horizontal" ? void 0 : isRightOrBottomCollapsed ? 0 : void 0,
607
+ left: resolvedOrientation === "horizontal" ? isLeftOrTopCollapsed ? 0 : void 0 : "50%",
608
+ right: resolvedOrientation === "horizontal" ? isRightOrBottomCollapsed ? 0 : void 0 : void 0,
609
+ display: "flex",
610
+ alignItems: "center",
611
+ justifyContent: "center",
612
+ opacity: 1,
613
+ pointerEvents: "auto",
614
+ zIndex: 5,
615
+ transform: resolvedOrientation === "horizontal" ? `translate(${isLeftOrTopCollapsed ? "4px" : "-4px"}, -50%)` : `translate(-50%, ${isLeftOrTopCollapsed ? "4px" : "-4px"})`
616
+ },
617
+ children: (() => {
618
+ const ExpandIcon = resolvedOrientation === "horizontal" ? isLeftOrTopCollapsed ? RightOutlined : LeftOutlined : isLeftOrTopCollapsed ? DownOutlined : UpOutlined;
619
+ const targetIndex = isLeftOrTopCollapsed ? index : index + 1;
620
+ const neighborIndex = isLeftOrTopCollapsed ? index + 1 : index;
621
+ const isHorizontal = resolvedOrientation === "horizontal";
622
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
623
+ "button",
624
+ {
625
+ "aria-label": "\u5C55\u5F00\u9762\u677F",
626
+ title: "\u5C55\u5F00\u9762\u677F",
627
+ onClick: (event) => {
628
+ event.stopPropagation();
629
+ toggleCollapse(targetIndex, neighborIndex);
630
+ },
631
+ style: {
632
+ alignItems: "center",
633
+ background: "#f3f4f6",
634
+ border: "1px solid #e5e7eb",
635
+ borderRadius: 3,
636
+ color: "#595959",
637
+ cursor: "pointer",
638
+ display: "flex",
639
+ height: isHorizontal ? 40 : 14,
640
+ width: isHorizontal ? 14 : 40,
641
+ justifyContent: "center",
642
+ padding: 0,
643
+ fontSize: 10,
644
+ boxShadow: "0 1px 3px rgba(0, 0, 0, 0.08)",
645
+ transition: "all 0.2s ease"
646
+ },
647
+ type: "button",
648
+ onMouseEnter: (e) => {
649
+ e.currentTarget.style.background = "#e5e7eb";
650
+ e.currentTarget.style.color = "#1f2937";
651
+ },
652
+ onMouseLeave: (e) => {
653
+ e.currentTarget.style.background = "#f3f4f6";
654
+ e.currentTarget.style.color = "#595959";
655
+ },
656
+ children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ExpandIcon, {})
657
+ }
658
+ );
659
+ })()
660
+ }
661
+ )
662
+ ]
663
+ }
664
+ )
665
+ ] }, index);
666
+ }) });
637
667
  };
638
668
  CustomSplitter.Panel = SplitterPanel;
639
669
  var Splitter_default = CustomSplitter;