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.js CHANGED
@@ -179,7 +179,7 @@ var CollapseBox_default = CollapsibleBox;
179
179
  // Splitter/index.tsx
180
180
  import React, { useCallback, useEffect, useMemo, useRef, useState as useState2 } from "react";
181
181
  import { Fragment, jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
182
- var DRAGGER_SIZE = 8;
182
+ var DEFAULT_DRAGGER_SIZE = 4;
183
183
  var SplitterPanel = ({ children }) => /* @__PURE__ */ jsx3(Fragment, { children });
184
184
  var isPercentSize = (value) => typeof value === "string" && value.endsWith("%");
185
185
  var parseSize = (value, total, fallback) => {
@@ -197,6 +197,7 @@ var clamp = (value, min, max) => Math.min(Math.max(value, min), max);
197
197
  var CustomSplitter = ({
198
198
  children,
199
199
  className,
200
+ draggerSize = DEFAULT_DRAGGER_SIZE,
200
201
  lazy = false,
201
202
  onResize,
202
203
  onResizeEnd,
@@ -208,7 +209,6 @@ var CustomSplitter = ({
208
209
  const resolvedOrientation = orientation != null ? orientation : vertical ? "vertical" : "horizontal";
209
210
  const rootRef = useRef(null);
210
211
  const sizesRef = useRef([]);
211
- const lastNonZeroSizesRef = useRef([]);
212
212
  const [containerSize, setContainerSize] = useState2(0);
213
213
  const [draggingIndex, setDraggingIndex] = useState2(null);
214
214
  const [hoveredIndex, setHoveredIndex] = useState2(null);
@@ -219,7 +219,7 @@ var CustomSplitter = ({
219
219
  ),
220
220
  [children]
221
221
  );
222
- const trackSize = Math.max(0, containerSize - Math.max(0, panels.length - 1) * DRAGGER_SIZE);
222
+ const trackSize = Math.max(0, containerSize - Math.max(0, panels.length - 1) * draggerSize);
223
223
  const getPanelMin = useCallback(
224
224
  (index) => {
225
225
  var _a;
@@ -249,6 +249,9 @@ var CustomSplitter = ({
249
249
  if (size <= 1) {
250
250
  return 0;
251
251
  }
252
+ if (size < getPanelMin(index)) {
253
+ return size;
254
+ }
252
255
  return clamp(size, getPanelMin(index), getPanelMax(index));
253
256
  });
254
257
  },
@@ -287,11 +290,6 @@ var CustomSplitter = ({
287
290
  const normalized = normalizeToTrack(nextSizes);
288
291
  setSizes(normalized);
289
292
  sizesRef.current = normalized;
290
- normalized.forEach((size, index) => {
291
- if (size > 1) {
292
- lastNonZeroSizesRef.current[index] = size;
293
- }
294
- });
295
293
  if (notify) {
296
294
  onResize == null ? void 0 : onResize(roundSizes(normalized));
297
295
  }
@@ -315,17 +313,16 @@ var CustomSplitter = ({
315
313
  setSizes((previous) => {
316
314
  const nextSizes = buildInitialSizes(previous);
317
315
  sizesRef.current = nextSizes;
318
- lastNonZeroSizesRef.current = nextSizes.map(
319
- (size) => Math.max(size, trackSize / Math.max(panels.length, 1))
320
- );
321
316
  return nextSizes;
322
317
  });
323
- }, [buildInitialSizes, panels.length, trackSize]);
318
+ }, [buildInitialSizes]);
324
319
  const getResizedPair = useCallback(
325
320
  (sourceSizes, index, delta) => {
326
321
  const nextSizes = [...sourceSizes];
327
- const leftMin = getPanelMin(index);
328
- const rightMin = getPanelMin(index + 1);
322
+ const isLeftCollapsed = sourceSizes[index] <= 1;
323
+ const isRightCollapsed = sourceSizes[index + 1] <= 1;
324
+ const leftMin = isLeftCollapsed ? 0 : getPanelMin(index);
325
+ const rightMin = isRightCollapsed ? 0 : getPanelMin(index + 1);
329
326
  const leftMax = getPanelMax(index);
330
327
  const rightMax = getPanelMax(index + 1);
331
328
  const minDelta = Math.max(leftMin - sourceSizes[index], sourceSizes[index + 1] - rightMax);
@@ -373,14 +370,16 @@ var CustomSplitter = ({
373
370
  document.addEventListener("pointerup", handlePointerUp);
374
371
  };
375
372
  const toggleCollapse = (index, neighborIndex) => {
373
+ var _a;
376
374
  const nextSizes = [...sizesRef.current];
377
375
  if (nextSizes[index] > 1) {
378
- lastNonZeroSizesRef.current[index] = nextSizes[index];
379
376
  nextSizes[neighborIndex] += nextSizes[index];
380
377
  nextSizes[index] = 0;
381
378
  } else {
382
- const restoredSize = lastNonZeroSizesRef.current[index] || parseSize(panels[index].props.defaultSize, trackSize, trackSize / panels.length);
383
- nextSizes[index] = clamp(restoredSize, getPanelMin(index), getPanelMax(index));
379
+ const initialSizes = buildInitialSizes();
380
+ const initialSize = (_a = initialSizes[index]) != null ? _a : parseSize(panels[index].props.defaultSize, trackSize, trackSize / panels.length);
381
+ const restoredSize = clamp(initialSize, getPanelMin(index), getPanelMax(index));
382
+ nextSizes[index] = restoredSize;
384
383
  nextSizes[neighborIndex] = Math.max(0, nextSizes[neighborIndex] - nextSizes[index]);
385
384
  }
386
385
  updateSizes(nextSizes);
@@ -417,6 +416,7 @@ var CustomSplitter = ({
417
416
  return null;
418
417
  }
419
418
  const Icon = resolvedOrientation === "horizontal" ? direction === "start" ? LeftOutlined : RightOutlined : direction === "start" ? UpOutlined : DownOutlined;
419
+ const isHorizontal = resolvedOrientation === "horizontal";
420
420
  return /* @__PURE__ */ jsx3(
421
421
  "button",
422
422
  {
@@ -430,173 +430,203 @@ var CustomSplitter = ({
430
430
  alignItems: "center",
431
431
  background: "#fff",
432
432
  border: "1px solid #d9d9d9",
433
- borderRadius: 4,
433
+ borderRadius: 3,
434
434
  color: "#595959",
435
435
  cursor: "pointer",
436
436
  display: "flex",
437
- height: 20,
437
+ height: isHorizontal ? 40 : 14,
438
+ width: isHorizontal ? 14 : 40,
438
439
  justifyContent: "center",
439
440
  padding: 0,
440
- width: 20,
441
- fontSize: 12,
442
- boxShadow: "0 2px 4px rgba(0,0,0,0.08)"
441
+ fontSize: 10,
442
+ boxShadow: "0 1px 2px rgba(0, 0, 0, 0.05)",
443
+ transition: "all 0.2s ease"
443
444
  },
444
445
  type: "button",
445
- children: /* @__PURE__ */ jsx3(Icon, {})
446
- }
447
- );
448
- };
449
- const renderCollapsedExpandHandle = (panelIndex) => {
450
- var _a;
451
- const panel = panels[panelIndex];
452
- if (!(panel == null ? void 0 : panel.props.collapsible)) {
453
- return null;
454
- }
455
- const isCollapsed = sizes.length > 0 && ((_a = sizes[panelIndex]) != null ? _a : 0) <= 1;
456
- if (!isCollapsed) {
457
- return null;
458
- }
459
- const isFirstPanel = panelIndex === 0;
460
- const neighborIndex = isFirstPanel ? panelIndex + 1 : panelIndex - 1;
461
- const Icon = resolvedOrientation === "horizontal" ? isFirstPanel ? RightOutlined : LeftOutlined : isFirstPanel ? DownOutlined : UpOutlined;
462
- 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";
463
- 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%)" };
464
- return /* @__PURE__ */ jsx3(
465
- "button",
466
- {
467
- "aria-label": label,
468
- title: label,
469
- onClick: (event) => {
470
- event.stopPropagation();
471
- toggleCollapse(panelIndex, neighborIndex);
446
+ onMouseEnter: (e) => {
447
+ e.currentTarget.style.background = "#e5e7eb";
448
+ e.currentTarget.style.color = "#1f2937";
472
449
  },
473
- style: {
474
- position: "absolute",
475
- alignItems: "center",
476
- background: "#fff",
477
- border: "1px solid #1677ff",
478
- borderRadius: 4,
479
- color: "#1677ff",
480
- cursor: "pointer",
481
- display: "flex",
482
- height: 24,
483
- justifyContent: "center",
484
- padding: 0,
485
- width: 24,
486
- fontSize: 12,
487
- boxShadow: "0 2px 8px rgba(22, 119, 255, 0.35)",
488
- zIndex: 20,
489
- ...positionStyle
450
+ onMouseLeave: (e) => {
451
+ e.currentTarget.style.background = "#fff";
452
+ e.currentTarget.style.color = "#595959";
490
453
  },
491
- type: "button",
492
454
  children: /* @__PURE__ */ jsx3(Icon, {})
493
- },
494
- `collapsed-handle-${panelIndex}`
455
+ }
495
456
  );
496
457
  };
497
- return /* @__PURE__ */ jsxs2("div", { className, ref: rootRef, style: rootStyle, children: [
498
- panels.map((panel, index) => {
499
- var _a, _b, _c;
500
- const isHidden = sizes[index] <= 1;
501
- const isLeftOrTopCollapsed = ((_a = sizes[index]) != null ? _a : 0) <= 1;
502
- const isRightOrBottomCollapsed = ((_b = sizes[index + 1]) != null ? _b : 0) <= 1;
503
- const isAnyCollapsed = isLeftOrTopCollapsed || isRightOrBottomCollapsed;
504
- return /* @__PURE__ */ jsxs2(React.Fragment, { children: [
505
- /* @__PURE__ */ jsx3(
506
- "div",
507
- {
508
- style: {
509
- background: index % 2 ? "#fff" : "#fafafa",
510
- boxSizing: "border-box",
511
- flex: `0 0 ${(_c = sizes[index]) != null ? _c : 0}px`,
512
- minHeight: 0,
513
- minWidth: 0,
514
- overflow: "auto",
515
- padding: isHidden ? 0 : 16,
516
- transition: draggingIndex === null ? "flex-basis 0.2s ease" : void 0,
517
- ...panel.props.style
518
- },
519
- children: !isHidden && panel.props.children
520
- }
521
- ),
522
- index < panels.length - 1 && /* @__PURE__ */ jsxs2(
523
- "div",
524
- {
525
- "aria-orientation": resolvedOrientation,
526
- onClick: () => {
527
- if (isRightOrBottomCollapsed) {
528
- toggleCollapse(index + 1, index);
529
- } else if (isLeftOrTopCollapsed) {
530
- toggleCollapse(index, index + 1);
458
+ return /* @__PURE__ */ jsx3("div", { className, ref: rootRef, style: rootStyle, children: panels.map((panel, index) => {
459
+ var _a, _b, _c, _d;
460
+ const isHidden = sizes[index] <= 1;
461
+ const isLeftOrTopCollapsed = ((_a = sizes[index]) != null ? _a : 0) <= 1;
462
+ const isRightOrBottomCollapsed = ((_b = sizes[index + 1]) != null ? _b : 0) <= 1;
463
+ const isAnyCollapsed = isLeftOrTopCollapsed || isRightOrBottomCollapsed;
464
+ return /* @__PURE__ */ jsxs2(React.Fragment, { children: [
465
+ /* @__PURE__ */ jsx3(
466
+ "div",
467
+ {
468
+ style: {
469
+ background: index % 2 ? "#fff" : "#fafafa",
470
+ boxSizing: "border-box",
471
+ flex: `0 0 ${(_c = sizes[index]) != null ? _c : 0}px`,
472
+ minHeight: 0,
473
+ minWidth: 0,
474
+ overflow: "hidden",
475
+ position: "relative",
476
+ transition: draggingIndex === null ? "flex-basis 0.2s ease" : void 0,
477
+ ...panel.props.style
478
+ },
479
+ children: !isHidden && /* @__PURE__ */ jsx3(
480
+ "div",
481
+ {
482
+ style: {
483
+ boxSizing: "border-box",
484
+ height: "100%",
485
+ overflow: "auto",
486
+ padding: ((_d = sizes[index]) != null ? _d : 0) < 32 ? 0 : 16,
487
+ width: "100%"
488
+ },
489
+ children: panel.props.children
490
+ }
491
+ )
492
+ }
493
+ ),
494
+ index < panels.length - 1 && /* @__PURE__ */ jsxs2(
495
+ "div",
496
+ {
497
+ "aria-orientation": resolvedOrientation,
498
+ onDoubleClick: resetSizes,
499
+ onKeyDown: (event) => {
500
+ const step = event.shiftKey ? 40 : 10;
501
+ const directionMap = resolvedOrientation === "horizontal" ? { ArrowLeft: -step, ArrowRight: step } : { ArrowUp: -step, ArrowDown: step };
502
+ const delta = directionMap[event.key];
503
+ if (delta !== void 0) {
504
+ event.preventDefault();
505
+ resizePair(index, delta);
506
+ }
507
+ },
508
+ onPointerDown: (event) => startResize(index, event),
509
+ onPointerEnter: () => setHoveredIndex(index),
510
+ onPointerLeave: () => setHoveredIndex(null),
511
+ role: "separator",
512
+ title: "\u62D6\u52A8\u8C03\u6574\u5927\u5C0F\uFF0C\u53CC\u51FB\u91CD\u7F6E",
513
+ style: {
514
+ alignItems: "center",
515
+ background: hoveredIndex === index || draggingIndex === index ? "#e6f4ff" : "#f5f5f5",
516
+ boxSizing: "border-box",
517
+ cursor: resolvedOrientation === "horizontal" ? "col-resize" : "row-resize",
518
+ display: "flex",
519
+ flex: `0 0 ${draggerSize}px`,
520
+ justifyContent: "center",
521
+ outline: "none",
522
+ position: "relative",
523
+ userSelect: "none",
524
+ zIndex: isAnyCollapsed ? 2 : 1
525
+ },
526
+ tabIndex: 0,
527
+ children: [
528
+ (hoveredIndex === index || draggingIndex === index || !isAnyCollapsed) && /* @__PURE__ */ jsx3(
529
+ "div",
530
+ {
531
+ style: {
532
+ background: hoveredIndex === index || draggingIndex === index ? "#1677ff" : "#d9d9d9",
533
+ borderRadius: 2,
534
+ height: resolvedOrientation === "horizontal" ? 40 : 2,
535
+ width: resolvedOrientation === "horizontal" ? 2 : 40
536
+ }
531
537
  }
532
- },
533
- onDoubleClick: resetSizes,
534
- onKeyDown: (event) => {
535
- const step = event.shiftKey ? 40 : 10;
536
- const directionMap = resolvedOrientation === "horizontal" ? { ArrowLeft: -step, ArrowRight: step } : { ArrowUp: -step, ArrowDown: step };
537
- const delta = directionMap[event.key];
538
- if (delta !== void 0) {
539
- event.preventDefault();
540
- resizePair(index, delta);
538
+ ),
539
+ !isAnyCollapsed && /* @__PURE__ */ jsxs2(
540
+ "div",
541
+ {
542
+ style: {
543
+ position: "absolute",
544
+ top: "50%",
545
+ left: "50%",
546
+ transform: "translate(-50%, -50%)",
547
+ display: "flex",
548
+ flexDirection: resolvedOrientation === "horizontal" ? "row" : "column",
549
+ alignItems: "center",
550
+ justifyContent: "center",
551
+ gap: 2,
552
+ opacity: hoveredIndex === index || draggingIndex === index ? 1 : 0,
553
+ pointerEvents: hoveredIndex === index || draggingIndex === index ? "auto" : "none",
554
+ transition: "opacity 0.15s ease",
555
+ zIndex: 5
556
+ },
557
+ children: [
558
+ renderCollapseButton(index, index, "start"),
559
+ renderCollapseButton(index, index + 1, "end")
560
+ ]
541
561
  }
542
- },
543
- onPointerDown: (event) => startResize(index, event),
544
- onPointerEnter: () => setHoveredIndex(index),
545
- onPointerLeave: () => setHoveredIndex(null),
546
- role: "separator",
547
- title: isAnyCollapsed ? "\u70B9\u51FB\u53EF\u5C55\u5F00\u6062\u590D\u9762\u677F" : "\u62D6\u52A8\u8C03\u6574\u5927\u5C0F\uFF0C\u53CC\u51FB\u91CD\u7F6E",
548
- style: {
549
- alignItems: "center",
550
- background: hoveredIndex === index || draggingIndex === index || isAnyCollapsed ? "#e6f4ff" : "#f5f5f5",
551
- boxSizing: "border-box",
552
- cursor: isAnyCollapsed ? "pointer" : resolvedOrientation === "horizontal" ? "col-resize" : "row-resize",
553
- display: "flex",
554
- flex: `0 0 ${DRAGGER_SIZE}px`,
555
- justifyContent: "center",
556
- outline: "none",
557
- position: "relative",
558
- userSelect: "none",
559
- zIndex: isAnyCollapsed ? 2 : 1
560
- },
561
- tabIndex: 0,
562
- children: [
563
- /* @__PURE__ */ jsx3(
564
- "div",
565
- {
566
- style: {
567
- background: hoveredIndex === index || draggingIndex === index || isAnyCollapsed ? "#1677ff" : "#d9d9d9",
568
- borderRadius: 2,
569
- height: resolvedOrientation === "horizontal" ? 48 : 2,
570
- width: resolvedOrientation === "horizontal" ? 2 : 48
571
- }
572
- }
573
- ),
574
- !isAnyCollapsed && /* @__PURE__ */ jsxs2(
575
- "div",
576
- {
577
- style: {
578
- position: "absolute",
579
- display: "flex",
580
- flexDirection: resolvedOrientation === "horizontal" ? "column" : "row",
581
- gap: 4,
582
- opacity: hoveredIndex === index ? 1 : 0.85,
583
- transition: "opacity 0.15s ease",
584
- pointerEvents: "auto",
585
- zIndex: 5
586
- },
587
- children: [
588
- renderCollapseButton(index, index, "start"),
589
- renderCollapseButton(index, index + 1, "end")
590
- ]
591
- }
592
- )
593
- ]
594
- }
595
- )
596
- ] }, index);
597
- }),
598
- panels.map((_, index) => renderCollapsedExpandHandle(index))
599
- ] });
562
+ ),
563
+ isAnyCollapsed && /* @__PURE__ */ jsx3(
564
+ "div",
565
+ {
566
+ style: {
567
+ position: "absolute",
568
+ top: resolvedOrientation === "horizontal" ? "50%" : isLeftOrTopCollapsed ? 0 : void 0,
569
+ bottom: resolvedOrientation === "horizontal" ? void 0 : isRightOrBottomCollapsed ? 0 : void 0,
570
+ left: resolvedOrientation === "horizontal" ? isLeftOrTopCollapsed ? 0 : void 0 : "50%",
571
+ right: resolvedOrientation === "horizontal" ? isRightOrBottomCollapsed ? 0 : void 0 : void 0,
572
+ display: "flex",
573
+ alignItems: "center",
574
+ justifyContent: "center",
575
+ opacity: 1,
576
+ pointerEvents: "auto",
577
+ zIndex: 5,
578
+ transform: resolvedOrientation === "horizontal" ? `translate(${isLeftOrTopCollapsed ? "4px" : "-4px"}, -50%)` : `translate(-50%, ${isLeftOrTopCollapsed ? "4px" : "-4px"})`
579
+ },
580
+ children: (() => {
581
+ const ExpandIcon = resolvedOrientation === "horizontal" ? isLeftOrTopCollapsed ? RightOutlined : LeftOutlined : isLeftOrTopCollapsed ? DownOutlined : UpOutlined;
582
+ const targetIndex = isLeftOrTopCollapsed ? index : index + 1;
583
+ const neighborIndex = isLeftOrTopCollapsed ? index + 1 : index;
584
+ const isHorizontal = resolvedOrientation === "horizontal";
585
+ return /* @__PURE__ */ jsx3(
586
+ "button",
587
+ {
588
+ "aria-label": "\u5C55\u5F00\u9762\u677F",
589
+ title: "\u5C55\u5F00\u9762\u677F",
590
+ onClick: (event) => {
591
+ event.stopPropagation();
592
+ toggleCollapse(targetIndex, neighborIndex);
593
+ },
594
+ style: {
595
+ alignItems: "center",
596
+ background: "#f3f4f6",
597
+ border: "1px solid #e5e7eb",
598
+ borderRadius: 3,
599
+ color: "#595959",
600
+ cursor: "pointer",
601
+ display: "flex",
602
+ height: isHorizontal ? 40 : 14,
603
+ width: isHorizontal ? 14 : 40,
604
+ justifyContent: "center",
605
+ padding: 0,
606
+ fontSize: 10,
607
+ boxShadow: "0 1px 3px rgba(0, 0, 0, 0.08)",
608
+ transition: "all 0.2s ease"
609
+ },
610
+ type: "button",
611
+ onMouseEnter: (e) => {
612
+ e.currentTarget.style.background = "#e5e7eb";
613
+ e.currentTarget.style.color = "#1f2937";
614
+ },
615
+ onMouseLeave: (e) => {
616
+ e.currentTarget.style.background = "#f3f4f6";
617
+ e.currentTarget.style.color = "#595959";
618
+ },
619
+ children: /* @__PURE__ */ jsx3(ExpandIcon, {})
620
+ }
621
+ );
622
+ })()
623
+ }
624
+ )
625
+ ]
626
+ }
627
+ )
628
+ ] }, index);
629
+ }) });
600
630
  };
601
631
  CustomSplitter.Panel = SplitterPanel;
602
632
  var Splitter_default = CustomSplitter;