lilact 0.26.0 → 0.26.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lilact",
3
- "version": "0.26.0",
3
+ "version": "0.26.1",
4
4
  "description": "A Little React/JSX Runtime Implementation for Browser",
5
5
  "repository": "github:arashkazemi/lilact",
6
6
  "homepage": "https://arashkazemi.github.io/lilact/",
@@ -420,7 +420,7 @@ export function DragHandle({
420
420
  * @param max - Maximum allowed position. Defaults to `0.9`.
421
421
  Can also be a function that will be called with (containerWidth|containerHeight,splitterSize) as arguments
422
422
  * @param splitterSize - Thickness of the draggable splitter in pixels. Defaults to `8`.
423
- * @param resizeMode - The behavior on container resize. Its value can be `proportional`, `fixFirst` or `fixSecond`.
423
+ * @param resizePolicy - The behavior on container resize. Its value can be `proportional`, `fixFirst` or `fixSecond`.
424
424
  * Default is `proportional`.
425
425
  * @param onSizeChange - Callback invoked when the position changes. Receives the new normalized position.
426
426
  * @param style - Optional root container styles.
@@ -457,7 +457,7 @@ export const SplitPane = forwardRef(function SplitPane(
457
457
  max = 0.9,
458
458
  splitterSize = 8,
459
459
  onSizeChange,
460
- resizeMode = "proportional",
460
+ resizePolicy = "proportional",
461
461
  style,
462
462
  className,
463
463
  firstPaneStyle,
@@ -517,24 +517,61 @@ export const SplitPane = forwardRef(function SplitPane(
517
517
  sizeRef.current = { w: rect.width, h: rect.height };
518
518
 
519
519
 
520
- if(ref.current?.getPosition) {
521
- if( resizeMode==='fixFirst') {
522
- if(internalMode==='vertical' && o.h>0) {
523
- setPosition( ref.current.getPosition() * o.h/sizeRef.current.h );
524
- }
525
- else if(o.w>0) {
526
- setPosition( ref.current.getPosition() * o.w/sizeRef.current.w );
527
- }
528
- }
529
- else if( resizeMode==='fixSecond') {
530
- if(internalMode==='vertical' && o.h>0) {
531
- setPosition( 1 - ( (1-ref.current.getPosition()) * o.h/sizeRef.current.h ) );
520
+ const EPS = 1e-6;
521
+
522
+ function clamp01(x) {
523
+ return Math.min(1, Math.max(0, x));
524
+ }
525
+
526
+ if (ref.current?.getPosition) {
527
+ const p = ref.current.getPosition();
528
+
529
+ if (resizePolicy === 'fixFirst') {
530
+ if (internalMode === 'vertical') {
531
+ const availOld = o.h - splitterSize;
532
+ const availNew = sizeRef.current.h - splitterSize;
533
+ if (availOld > 0 && availNew > 0) {
534
+ const firstPx = p * availOld; // fixed pane size in px
535
+ const nextP = firstPx / availNew; // recompute normalized
536
+ if (Math.abs(nextP - p) > EPS) setPosition(clamp01(nextP));
537
+ }
538
+ }
539
+ else {
540
+ const availOld = o.w - splitterSize;
541
+ const availNew = sizeRef.current.w - splitterSize;
542
+ if (availOld > 0 && availNew > 0) {
543
+ const firstPx = p * availOld;
544
+ const nextP = firstPx / availNew;
545
+ if (Math.abs(nextP - p) > EPS) setPosition(clamp01(nextP));
546
+ }
532
547
  }
533
- else if(o.w>0) {
534
- setPosition( 1 - ( (1-ref.current.getPosition()) * o.w/sizeRef.current.w ) );
548
+ }
549
+ else if (resizePolicy === 'fixSecond') {
550
+ // fixSecond means second pane pixel size stays constant.
551
+ // secondPx = (1-p) * availOld
552
+ // nextP = 1 - secondPx/availNew
553
+ if (internalMode === 'vertical') {
554
+ const availOld = o.h - splitterSize;
555
+ const availNew = sizeRef.current.h - splitterSize;
556
+ if (availOld > 0 && availNew > 0) {
557
+ const secondPx = (1 - p) * availOld;
558
+ const nextP = 1 - (secondPx / availNew);
559
+ if (Math.abs(nextP - p) > EPS) setPosition(clamp01(nextP));
560
+ }
561
+ }
562
+ else {
563
+ const availOld = o.w - splitterSize;
564
+ const availNew = sizeRef.current.w - splitterSize;
565
+ if (availOld > 0 && availNew > 0) {
566
+ const secondPx = (1 - p) * availOld;
567
+ const nextP = 1 - (secondPx / availNew);
568
+ if (Math.abs(nextP - p) > EPS) setPosition(clamp01(nextP));
569
+ }
535
570
  }
536
571
  }
537
572
  }
573
+
574
+
538
575
  });
539
576
 
540
577
  ro.observe(el);
@@ -542,7 +579,7 @@ export const SplitPane = forwardRef(function SplitPane(
542
579
  sizeRef.current = { w: rect.width, h: rect.height };
543
580
 
544
581
  return () => ro.disconnect();
545
- }, [resizeMode, internalMode]);
582
+ }, [resizePolicy, internalMode]);
546
583
 
547
584
  const startPosRef = useRef(posResolved);
548
585
  const [dragging, setDragging] = useState(false);
@@ -606,7 +643,7 @@ export const SplitPane = forwardRef(function SplitPane(
606
643
  computedPane1Style.bottom = 0;
607
644
  computedPane2Style.top = 0;
608
645
 
609
- if(resizeMode==='fixFirst') {
646
+ if(resizePolicy==='fixFirst') {
610
647
  computedPane1Style.width = p*(w-splitterSize);
611
648
  computedPane2Style.left = computedPane1Style.width+splitterSize;
612
649
 
@@ -617,14 +654,14 @@ export const SplitPane = forwardRef(function SplitPane(
617
654
  width: splitterSize,
618
655
  });
619
656
  }
620
- else if(resizeMode==='fixSecond') {
657
+ else if(resizePolicy==='fixSecond') {
621
658
  computedPane2Style.width = (1-p)*(w-splitterSize);
622
659
  computedPane1Style.right = computedPane2Style.width+splitterSize;
623
660
 
624
661
  Object.assign( computedSplitterStyle, {
625
662
  top: 0,
626
663
  bottom: 0,
627
- left: computedPane2Style.width,
664
+ right: computedPane2Style.width,
628
665
  width: splitterSize,
629
666
  });
630
667
  }
@@ -644,7 +681,7 @@ export const SplitPane = forwardRef(function SplitPane(
644
681
  computedPane1Style.right = 0;
645
682
  computedPane2Style.left = 0;
646
683
 
647
- if(resizeMode==='fixFirst') {
684
+ if(resizePolicy==='fixFirst') {
648
685
  computedPane1Style.height = p*(h-splitterSize);
649
686
  computedPane2Style.top = computedPane1Style.height+splitterSize;
650
687
 
@@ -655,7 +692,7 @@ export const SplitPane = forwardRef(function SplitPane(
655
692
  height: splitterSize,
656
693
  });
657
694
  }
658
- else if(resizeMode==='fixSecond') {
695
+ else if(resizePolicy==='fixSecond') {
659
696
  computedPane2Style.height = (1-p)*(h-splitterSize);
660
697
  computedPane1Style.bottom = computedPane2Style.height+splitterSize;
661
698