@lvce-editor/explorer-view 7.13.0 → 7.14.0

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.
@@ -6511,27 +6511,31 @@ const handleResize = (state, dimensions) => {
6511
6511
  };
6512
6512
  };
6513
6513
 
6514
- const handleUpload = async (state, dirents) => {
6515
- if (state.isReadonly) {
6516
- return state;
6514
+ const handleScrollBarCaptureLost = state => {
6515
+ return {
6516
+ ...state,
6517
+ scrollBarActive: false
6518
+ };
6519
+ };
6520
+
6521
+ const getNewDeltaYPercent = (height, scrollBarHeight, relativeY) => {
6522
+ const halfScrollBarHeight = scrollBarHeight / 2;
6523
+ if (relativeY <= halfScrollBarHeight) {
6524
+ return {
6525
+ handleOffset: relativeY,
6526
+ percent: 0
6527
+ };
6517
6528
  }
6518
- const {
6519
- pathSeparator,
6520
- root
6521
- } = state;
6522
- for (const dirent of dirents) {
6523
- // TODO switch
6524
- // TODO symlink might not be possible to be copied
6525
- // TODO create folder if type is 2
6526
- if (dirent.type !== /* File */1) {
6527
- continue;
6528
- }
6529
- // TODO reading text might be inefficient for binary files
6530
- // but not sure how else to send them via jsonrpc
6531
- const content = await dirent.file.text();
6532
- const absolutePath = [root, dirent.file.name].join(pathSeparator);
6533
- await writeFile(absolutePath, content);
6529
+ if (relativeY <= height - halfScrollBarHeight) {
6530
+ return {
6531
+ handleOffset: halfScrollBarHeight,
6532
+ percent: (relativeY - halfScrollBarHeight) / (height - scrollBarHeight)
6533
+ };
6534
6534
  }
6535
+ return {
6536
+ handleOffset: scrollBarHeight - height + relativeY,
6537
+ percent: 1
6538
+ };
6535
6539
  };
6536
6540
 
6537
6541
  const setDeltaY = async (state, deltaY) => {
@@ -6561,6 +6565,89 @@ const setDeltaY = async (state, deltaY) => {
6561
6565
  };
6562
6566
  };
6563
6567
 
6568
+ const handleScrollBarClick = async (state, eventY) => {
6569
+ const {
6570
+ deltaY,
6571
+ height,
6572
+ itemHeight,
6573
+ items,
6574
+ y
6575
+ } = state;
6576
+ const contentHeight = items.length * itemHeight;
6577
+ const finalDeltaY = Math.max(contentHeight - height, 0);
6578
+ const scrollBarHeight = getScrollBarSize(height, contentHeight, 20);
6579
+ const availableTrackHeight = height - scrollBarHeight;
6580
+ if (finalDeltaY === 0 || availableTrackHeight <= 0) {
6581
+ return state;
6582
+ }
6583
+ const relativeY = eventY - y;
6584
+ const currentScrollBarY = deltaY / finalDeltaY * availableTrackHeight;
6585
+ const offsetInThumb = relativeY - currentScrollBarY;
6586
+ if (offsetInThumb >= 0 && offsetInThumb < scrollBarHeight) {
6587
+ return {
6588
+ ...state,
6589
+ handleOffset: offsetInThumb,
6590
+ scrollBarActive: true
6591
+ };
6592
+ }
6593
+ const {
6594
+ handleOffset,
6595
+ percent
6596
+ } = getNewDeltaYPercent(height, scrollBarHeight, relativeY);
6597
+ return {
6598
+ ...(await setDeltaY(state, percent * finalDeltaY)),
6599
+ handleOffset,
6600
+ scrollBarActive: true
6601
+ };
6602
+ };
6603
+
6604
+ const handleScrollBarMove = async (state, eventY) => {
6605
+ const {
6606
+ handleOffset,
6607
+ height,
6608
+ itemHeight,
6609
+ items,
6610
+ scrollBarActive,
6611
+ y
6612
+ } = state;
6613
+ if (!scrollBarActive) {
6614
+ return state;
6615
+ }
6616
+ const contentHeight = items.length * itemHeight;
6617
+ const finalDeltaY = Math.max(contentHeight - height, 0);
6618
+ const scrollBarHeight = getScrollBarSize(height, contentHeight, 20);
6619
+ const availableTrackHeight = height - scrollBarHeight;
6620
+ if (finalDeltaY === 0 || availableTrackHeight <= 0) {
6621
+ return state;
6622
+ }
6623
+ const relativeY = eventY - y - handleOffset;
6624
+ const percent = relativeY / availableTrackHeight;
6625
+ return setDeltaY(state, percent * finalDeltaY);
6626
+ };
6627
+
6628
+ const handleUpload = async (state, dirents) => {
6629
+ if (state.isReadonly) {
6630
+ return state;
6631
+ }
6632
+ const {
6633
+ pathSeparator,
6634
+ root
6635
+ } = state;
6636
+ for (const dirent of dirents) {
6637
+ // TODO switch
6638
+ // TODO symlink might not be possible to be copied
6639
+ // TODO create folder if type is 2
6640
+ if (dirent.type !== /* File */1) {
6641
+ continue;
6642
+ }
6643
+ // TODO reading text might be inefficient for binary files
6644
+ // but not sure how else to send them via jsonrpc
6645
+ const content = await dirent.file.text();
6646
+ const absolutePath = [root, dirent.file.name].join(pathSeparator);
6647
+ await writeFile(absolutePath, content);
6648
+ }
6649
+ };
6650
+
6564
6651
  const handleWheel = (state, deltaMode, deltaY) => {
6565
6652
  return setDeltaY(state, state.deltaY + deltaY);
6566
6653
  };
@@ -6758,11 +6845,12 @@ const getErrorMessagePosition = (itemHeight, focusedIndex, minLineY, depth, inde
6758
6845
  };
6759
6846
  };
6760
6847
 
6761
- const getScrollBarTop = (height, contentHeight, scrollTop) => {
6762
- if (contentHeight <= 0 || !Number.isFinite(contentHeight)) {
6848
+ const getScrollBarTop = (height, contentHeight, scrollTop, scrollBarHeight) => {
6849
+ const finalScrollTop = contentHeight - height;
6850
+ if (finalScrollTop <= 0 || !Number.isFinite(finalScrollTop)) {
6763
6851
  return 0;
6764
6852
  }
6765
- const scrollBarTop = Math.round(scrollTop / contentHeight * height);
6853
+ const scrollBarTop = Math.round(scrollTop / finalScrollTop * (height - scrollBarHeight));
6766
6854
  if (!Number.isFinite(scrollBarTop)) {
6767
6855
  return 0;
6768
6856
  }
@@ -6805,8 +6893,8 @@ const renderCss = (oldState, newState) => {
6805
6893
  } = newState;
6806
6894
  const uniqueIndents = getUniqueIndents(visibleExplorerItems);
6807
6895
  const contentHeight = items.length * itemHeight;
6808
- const scrollBarTop = getScrollBarTop(height, contentHeight, deltaY);
6809
6896
  const scrollBarHeight = getScrollBarSize(height, contentHeight, 20);
6897
+ const scrollBarTop = getScrollBarTop(height, contentHeight, deltaY, scrollBarHeight);
6810
6898
  const depth = items[focusedIndex]?.depth || 0;
6811
6899
  const {
6812
6900
  errorMessageWidth,
@@ -6934,6 +7022,9 @@ const HandleKeyDown = 21;
6934
7022
  const HandleListBlur = 11;
6935
7023
  const HandleListFocus = 12;
6936
7024
  const HandlePointerDown = 14;
7025
+ const HandleScrollBarMove = 22;
7026
+ const HandleScrollBarPointerCaptureLost = 23;
7027
+ const HandleScrollBarPointerDown = 24;
6937
7028
  const HandleWheel = 15;
6938
7029
  const HandleDoubleClick = 16;
6939
7030
 
@@ -7174,6 +7265,7 @@ const getScrollBarVirtualDom = scrollBarHeight => {
7174
7265
  return [{
7175
7266
  childCount: 1,
7176
7267
  className: mergeClassNames(ScrollBar, ScrollBarSmall),
7268
+ onPointerDown: HandleScrollBarPointerDown,
7177
7269
  type: Div
7178
7270
  }, scrollBarThumbNode];
7179
7271
  };
@@ -7445,6 +7537,17 @@ const renderEventListeners = () => {
7445
7537
  }, {
7446
7538
  name: HandlePointerDown,
7447
7539
  params: ['handlePointerDown', Button$3, ClientX, ClientY]
7540
+ }, {
7541
+ name: HandleScrollBarPointerDown,
7542
+ params: ['handleScrollBarClick', ClientY],
7543
+ preventDefault: true,
7544
+ trackPointerEvents: [HandleScrollBarMove, HandleScrollBarPointerCaptureLost]
7545
+ }, {
7546
+ name: HandleScrollBarMove,
7547
+ params: ['handleScrollBarMove', ClientY]
7548
+ }, {
7549
+ name: HandleScrollBarPointerCaptureLost,
7550
+ params: ['handleScrollBarCaptureLost']
7448
7551
  }, {
7449
7552
  name: HandleDoubleClick,
7450
7553
  params: ['handleDoubleClick', ClientX, ClientY]
@@ -7848,6 +7951,9 @@ const commandMap = {
7848
7951
  'Explorer.handlePaste': wrapListItemCommand(handlePaste),
7849
7952
  'Explorer.handlePointerDown': wrapListItemCommand(handlePointerDown),
7850
7953
  'Explorer.handleResize': wrapListItemCommand(handleResize),
7954
+ 'Explorer.handleScrollBarCaptureLost': wrapListItemCommand(handleScrollBarCaptureLost),
7955
+ 'Explorer.handleScrollBarClick': wrapListItemCommand(handleScrollBarClick),
7956
+ 'Explorer.handleScrollBarMove': wrapListItemCommand(handleScrollBarMove),
7851
7957
  'Explorer.handleUpload': wrapListItemCommand(handleUpload),
7852
7958
  'Explorer.handleWheel': wrapListItemCommand(handleWheel),
7853
7959
  'Explorer.handleWorkspaceChange': wrapListItemCommandImmediate(handleWorkspaceChange),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/explorer-view",
3
- "version": "7.13.0",
3
+ "version": "7.14.0",
4
4
  "description": "Explorer Worker",
5
5
  "repository": {
6
6
  "type": "git",