dsh-remote-vs 0.15.1 → 0.17.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.
@@ -16,6 +16,7 @@ import { MAX_SELECTION_DOWNLOAD, type RemoteFileEntry } from '../protocol.ts'
16
16
  import { api, uploadFile } from './api.ts'
17
17
  import { startDownload, startSelectionDownload } from './downloads.ts'
18
18
  import { useConnectionStatus, isConnectionFailure } from './connection.ts'
19
+ import { createDragExpander, type DragExpander } from './drag-expand.ts'
19
20
  import { insertRemoteReference, sameLocalDir } from './composer.ts'
20
21
  import { ListingRequests } from './listing-requests.ts'
21
22
  import { repoRelative, useExplorer } from './store.tsx'
@@ -656,6 +657,34 @@ export function RemoteExplorer(props: { showHidden: boolean; onToggleHidden: ()
656
657
  const uploadAbort = useRef<AbortController | undefined>(undefined)
657
658
  /** True while a remote WRITE batch is in flight (upload/paste/delete serialization). */
658
659
  const transferRef = useRef(false)
660
+ /**
661
+ * `expanded` readable SYNCHRONOUSLY by the window-capture drag listeners.
662
+ *
663
+ * Those listeners live outside React's tree and are re-attached per binding,
664
+ * so reading the state value from inside them would be one render stale; the
665
+ * spring-load decision ("is this directory already open?") has to answer for
666
+ * the tree as the pointer sees it.
667
+ */
668
+ const expandedRef = useRef<Set<string>>(expanded)
669
+ expandedRef.current = expanded
670
+ /** The latest {@link springOpen}; the expander below is created once and reads through. */
671
+ const springOpenRef = useRef<(dir: string) => void>(() => undefined)
672
+ /**
673
+ * Spring-loaded folders (see `drag-expand.ts`): one instance per mounted
674
+ * panel. Both drag paths feed it — the row's own `onDragOver` (our rows =
675
+ * move) and the window-capture `dragover` (OS files = upload) — because those
676
+ * are two different event deliveries, not one.
677
+ */
678
+ const dragExpand = useRef<DragExpander | undefined>(undefined)
679
+ if (dragExpand.current === undefined) {
680
+ dragExpand.current = createDragExpander(
681
+ (dir) => springOpenRef.current(dir),
682
+ {
683
+ set: (callback, ms) => window.setTimeout(callback, ms),
684
+ clear: (handle) => window.clearTimeout(handle),
685
+ },
686
+ )
687
+ }
659
688
  /** Last handled "show this folder" request id (see `shouldConsumeReveal`). */
660
689
  const lastRevealId = useRef(0)
661
690
  const menu = useContextMenu()
@@ -701,12 +730,19 @@ export function RemoteExplorer(props: { showHidden: boolean; onToggleHidden: ()
701
730
  },
702
731
  ), [alias])
703
732
 
704
- const loadDir = useCallback(async (dir: string, force = false): Promise<void> => {
705
- if (alias === '') return
733
+ /**
734
+ * List one directory into the tree cache.
735
+ *
736
+ * @returns whether the listing landed. Callers that act on the RESULT (the
737
+ * spring-loaded expand, which has to collapse a directory it could not read)
738
+ * need it; the many refresh callers ignore it.
739
+ */
740
+ const loadDir = useCallback(async (dir: string, force = false, silent = false): Promise<boolean> => {
741
+ if (alias === '') return false
706
742
  // While the link is down, a listing can only produce a 45 s SSH dial (and a
707
743
  // spinner over the "no cache" placeholder). Cached rows stay; recovery
708
744
  // re-lists through the revision bump, so skipping here loses nothing.
709
- if (offline) return
745
+ if (offline) return false
710
746
  const key = dirKey(alias, dir)
711
747
  // NOTE: a cached listing is deliberately NOT reused as the only source. The
712
748
  // tree relies on every caller re-listing after a write (`force` = start a
@@ -719,13 +755,19 @@ export function RemoteExplorer(props: { showHidden: boolean; onToggleHidden: ()
719
755
  next.add(key)
720
756
  return next
721
757
  })
758
+ let listed = false
722
759
  try {
723
760
  await listingsApi.request(dir, revisionRef.current, force)
761
+ listed = true
724
762
  } catch (error) {
725
763
  // A transport failure is already on the connection chip, and the cached
726
764
  // rows are still on screen: one toast per background refresh would repeat
727
- // the same story until the link is back. Business failures still speak.
728
- if (!isConnectionFailure(error)) toast(error instanceof Error ? error.message : String(error), true)
765
+ // the same story until the link is back. Business failures still speak —
766
+ // except on a SILENT read (spring-loaded expand while the pointer rests
767
+ // on a directory): that listing was never requested by a click, so a
768
+ // toast would interrupt with an error the user cannot act on. The real
769
+ // open of the same directory still explains itself.
770
+ if (!silent && !isConnectionFailure(error)) toast(error instanceof Error ? error.message : String(error), true)
729
771
  } finally {
730
772
  setLoading(prev => {
731
773
  const next = new Set(prev)
@@ -733,6 +775,7 @@ export function RemoteExplorer(props: { showHidden: boolean; onToggleHidden: ()
733
775
  return next
734
776
  })
735
777
  }
778
+ return listed
736
779
  }, [alias, listingsApi, offline])
737
780
 
738
781
  /**
@@ -882,10 +925,20 @@ export function RemoteExplorer(props: { showHidden: boolean; onToggleHidden: ()
882
925
  alive.current = true
883
926
  return () => {
884
927
  alive.current = false
928
+ dragExpand.current?.reset()
885
929
  if (prefetchTimer.current !== undefined) window.clearTimeout(prefetchTimer.current)
886
930
  }
887
931
  }, [])
888
932
 
933
+ /**
934
+ * A binding change invalidates every drag candidate: `expanded` is re-keyed to
935
+ * the new workspace, so a countdown armed on the old tree could open a path
936
+ * that does not even exist on the host now bound.
937
+ */
938
+ useEffect(() => {
939
+ dragExpand.current?.reset()
940
+ }, [alias, root])
941
+
889
942
  /**
890
943
  * One directory's visible, sorted rows, cached for the life of one
891
944
  * `listings`/`showHidden`/`alias` combination.
@@ -934,6 +987,49 @@ export function RemoteExplorer(props: { showHidden: boolean; onToggleHidden: ()
934
987
  if (!isOpen) void loadDir(entry.path)
935
988
  }
936
989
 
990
+ /**
991
+ * Spring-open one directory under a resting drag (see `drag-expand.ts`).
992
+ *
993
+ * The listing is read FORCE — a file is about to land in this directory, so a
994
+ * cached listing could hide the very file the drop is about to clash with —
995
+ * and SILENT, because a speculative read must not paint a failure toast the
996
+ * user never asked for. Opening an already-open directory is a no-op: the
997
+ * expander only arms on closed rows, and a second open would restart the
998
+ * listing for nothing.
999
+ *
1000
+ * A FAILED read collapses the directory again. Leaving it open would show an
1001
+ * empty folder (indistinguishable from a real empty one) and — worse — the
1002
+ * directory then sits in `expanded`, so every later revision bump re-lists it
1003
+ * WITHOUT the silent flag and repeats the same error toast on every write.
1004
+ */
1005
+ const springOpen = useCallback((dir: string): void => {
1006
+ if (dir === '' || offline) return
1007
+ setExpanded(prev => {
1008
+ if (prev.has(dir)) return prev
1009
+ const next = new Set(prev)
1010
+ next.add(dir)
1011
+ return next
1012
+ })
1013
+ void loadDir(dir, true, true).then((listed) => {
1014
+ if (listed) return
1015
+ // A concurrent NON-silent re-list (a revision bump, or the user opening
1016
+ // the same row) may have SUCCEEDED while this speculative read failed;
1017
+ // collapsing then would fold a directory the tree can actually show. Only
1018
+ // collapse while the cache still holds nothing for it.
1019
+ if (listingsRef.current[dirKey(alias, dir)] !== undefined) return
1020
+ setExpanded(prev => {
1021
+ if (!prev.has(dir)) return prev
1022
+ const next = new Set(prev)
1023
+ next.delete(dir)
1024
+ return next
1025
+ })
1026
+ })
1027
+ }, [alias, offline, loadDir])
1028
+ // Written during render on purpose: an idempotent latest-value ref, exactly
1029
+ // like `revisionRef` below. The expander outlives every render, so a captured
1030
+ // copy would call into a stale `offline`/`loadDir` pair.
1031
+ springOpenRef.current = springOpen
1032
+
937
1033
  /** Open one path: previews for images, diffs for changed text files. */
938
1034
  const openEntry = useCallback((entry: RemoteFileEntry): void => {
939
1035
  if (entry.isDir) {
@@ -1589,19 +1685,59 @@ export function RemoteExplorer(props: { showHidden: boolean; onToggleHidden: ()
1589
1685
  event.stopPropagation()
1590
1686
  if (event.dataTransfer !== null) event.dataTransfer.dropEffect = 'copy'
1591
1687
  }
1688
+ /**
1689
+ * The DIRECTORY row under the pointer, or undefined.
1690
+ *
1691
+ * Same hit stack as `dropDirFromEvent` (the shell paints a full-screen
1692
+ * "drop here" overlay during a file drag, so `event.target` is that
1693
+ * overlay, never the row), but this one answers "which closed directory is
1694
+ * the pointer resting on" for spring-loading. A FILE row answers undefined:
1695
+ * a drop there lands in its parent directory, which is already open.
1696
+ */
1697
+ const hoverDirOf = (event: DragEvent): string | undefined => {
1698
+ const point = pointerOf(event)
1699
+ if (point === undefined) return undefined
1700
+ for (const element of document.elementsFromPoint(point.x, point.y)) {
1701
+ const row = element.closest('[data-rvs-path]')
1702
+ if (row === null) continue
1703
+ const path = row.getAttribute('data-rvs-path') ?? ''
1704
+ if (path === '') continue
1705
+ return row.getAttribute('data-rvs-dir') === '1' ? path : undefined
1706
+ }
1707
+ return undefined
1708
+ }
1709
+ /**
1710
+ * Feed the spring-load expander from an OS-file drag.
1711
+ *
1712
+ * `dragover` fires continuously while the pointer rests, which is exactly
1713
+ * the signal the expander wants: it ignores a repeat for the row already
1714
+ * counting down and only restarts when the pointer moves to another row.
1715
+ * RESET rather than `leave` on a file row or the pane background: the
1716
+ * pointer left the candidate and there is no path to name it by here.
1717
+ */
1718
+ const trackHover = (event: DragEvent): void => {
1719
+ const dir = hoverDirOf(event)
1720
+ if (dir !== undefined && !expandedRef.current.has(dir)) dragExpand.current?.hover(dir)
1721
+ else dragExpand.current?.reset()
1722
+ }
1592
1723
  const onDragEnter = (event: DragEvent): void => {
1593
1724
  if (!isFileDrag(event.dataTransfer) || !overPane(event)) return
1594
1725
  claim(event)
1595
1726
  setDropTarget(root)
1596
1727
  setDropHint(root)
1728
+ trackHover(event)
1597
1729
  }
1598
1730
  const onDragOver = (event: DragEvent): void => {
1599
1731
  if (!isFileDrag(event.dataTransfer) || !overPane(event)) return
1600
1732
  claim(event)
1601
1733
  setDropTarget(root)
1602
1734
  setDropHint(root)
1735
+ trackHover(event)
1603
1736
  }
1604
1737
  const onDrop = (event: DragEvent): void => {
1738
+ // The gesture is over whichever way it ends: no spring-load may fire
1739
+ // after the drop it was preparing for.
1740
+ dragExpand.current?.reset()
1605
1741
  dropLog('drop', {
1606
1742
  types: event.dataTransfer === null ? null : [...event.dataTransfer.types],
1607
1743
  overPane: overPane(event),
@@ -1621,10 +1757,32 @@ export function RemoteExplorer(props: { showHidden: boolean; onToggleHidden: ()
1621
1757
  })
1622
1758
  }
1623
1759
  const onDragLeave = (event: DragEvent): void => {
1624
- // Only when the pointer actually left the pane: the overlay's own
1625
- // dragleave fires for unrelated targets and used to clear the hint
1626
- // mid-drag.
1627
- if (overPane(event)) return
1760
+ // Two different events share this name, and only the first is a leave:
1761
+ // - the pointer moved to another element (relatedTarget is set). The
1762
+ // shell's drag overlay fires these for unrelated targets and they used
1763
+ // to clear the hint mid-drag, so they are ignored.
1764
+ // - the drag ENDED without a drop (Esc, or a drop refused elsewhere)
1765
+ // while the pointer is still inside the pane: overPane() is true and
1766
+ // relatedTarget is null. A drag that started in ANOTHER document (the
1767
+ // OS file manager) never sends `dragend` here — its source node is not
1768
+ // in this document — so this is the ONLY event that can end that
1769
+ // gesture, and it must clear the countdown (otherwise the folder opens
1770
+ // 650 ms after the user cancelled).
1771
+ if (overPane(event) && event.relatedTarget !== null) return
1772
+ dragExpand.current?.reset()
1773
+ setDropTarget(undefined)
1774
+ setDropHint(undefined)
1775
+ }
1776
+ /**
1777
+ * The end of a drag whose SOURCE is in this document (our tree rows): a
1778
+ * drop, Esc, or a drop outside the pane. OS-file drags end in
1779
+ * `onDragLeave` instead (see there). Clearing `dragPaths` matters because a
1780
+ * cancelled move leaves the old selection in it, and the next drag would
1781
+ * then treat a stale row as its move source.
1782
+ */
1783
+ const onDragEnd = (): void => {
1784
+ dragExpand.current?.reset()
1785
+ dragPaths.current = []
1628
1786
  setDropTarget(undefined)
1629
1787
  setDropHint(undefined)
1630
1788
  }
@@ -1632,11 +1790,14 @@ export function RemoteExplorer(props: { showHidden: boolean; onToggleHidden: ()
1632
1790
  window.addEventListener('dragover', onDragOver, true)
1633
1791
  window.addEventListener('drop', onDrop, true)
1634
1792
  window.addEventListener('dragleave', onDragLeave, true)
1793
+ window.addEventListener('dragend', onDragEnd, true)
1635
1794
  return () => {
1795
+ dragExpand.current?.reset()
1636
1796
  window.removeEventListener('dragenter', onDragEnter, true)
1637
1797
  window.removeEventListener('dragover', onDragOver, true)
1638
1798
  window.removeEventListener('drop', onDrop, true)
1639
1799
  window.removeEventListener('dragleave', onDragLeave, true)
1800
+ window.removeEventListener('dragend', onDragEnd, true)
1640
1801
  }
1641
1802
  // `uploadFromDataTransfer` closes over the current alias/root/plan state, so
1642
1803
  // the listeners are re-attached whenever that identity would change.
@@ -1944,7 +2105,8 @@ export function RemoteExplorer(props: { showHidden: boolean; onToggleHidden: ()
1944
2105
  dragOver: (entry, e) => {
1945
2106
  // An OS file drag targets this row's DIRECTORY: a drop on a file row
1946
2107
  // means "put it beside that file" (what the user means when they aim at a
1947
- // file in the list).
2108
+ // file in the list). The real handling of an OS drag lives in the
2109
+ // window-capture listener below; this branch keeps React's own path sane.
1948
2110
  if (isFileDrag(e.dataTransfer)) {
1949
2111
  e.preventDefault()
1950
2112
  e.stopPropagation()
@@ -1952,15 +2114,38 @@ export function RemoteExplorer(props: { showHidden: boolean; onToggleHidden: ()
1952
2114
  setDropHint(entry.isDir ? entry.path : (entry.path.split('/').slice(0, -1).join('/') || '/'))
1953
2115
  return
1954
2116
  }
1955
- if (!entry.isDir) return
1956
2117
  const source = dragPaths.current[0]
1957
- if (source === undefined) return
1958
- if (entry.path === source || entry.path.startsWith(`${source}/`)) return
1959
- e.preventDefault()
1960
- setDropTarget(entry.path)
2118
+ // `text/plain` is what our own `onDragStart` sets (`ExplorerRowView`) and
2119
+ // what a DOM drag of a row therefore carries. Requiring it keeps a stale
2120
+ // source — left behind by a cancelled move before `onDragEnd` clears it —
2121
+ // from turning an unrelated text drag over the tree into a "move" target.
2122
+ const legalTarget = entry.isDir
2123
+ && source !== undefined
2124
+ && e.dataTransfer !== null
2125
+ && [...e.dataTransfer.types].includes('text/plain')
2126
+ && entry.path !== source
2127
+ && !entry.path.startsWith(`${source}/`)
2128
+ if (legalTarget) {
2129
+ e.preventDefault()
2130
+ setDropTarget(entry.path)
2131
+ // Spring-loaded folders: a CLOSED directory under a resting drag opens
2132
+ // after the delay; an already-open one has nothing left to reveal.
2133
+ if (expanded.has(entry.path)) dragExpand.current?.reset()
2134
+ else dragExpand.current?.hover(entry.path)
2135
+ return
2136
+ }
2137
+ // Any other row disarms the countdown: the pointer is not resting on a
2138
+ // directory it could open (a move into itself is refused above too).
2139
+ dragExpand.current?.reset()
2140
+ },
2141
+ dragLeave: (entry) => {
2142
+ dragExpand.current?.leave(entry.path)
2143
+ setDropTarget(current => (current === entry.path ? undefined : current))
1961
2144
  },
1962
- dragLeave: (entry) => { setDropTarget(current => (current === entry.path ? undefined : current)) },
1963
2145
  dropOn: (entry, e) => {
2146
+ // The drop is the end of the gesture even when it is refused: never let
2147
+ // the countdown open a folder after its own drop landed.
2148
+ dragExpand.current?.reset()
1964
2149
  if (isFileDrag(e.dataTransfer)) {
1965
2150
  const into = entry.isDir ? entry.path : (entry.path.split('/').slice(0, -1).join('/') || '/')
1966
2151
  handleDrop(into, e)
@@ -16,6 +16,7 @@ import { applyConnectionStatuses, isConnectionRecovery, setActiveConnectionAlias
16
16
  import { EditorPane } from './EditorPane.tsx'
17
17
  import { FloatingEditorPlaceholder } from './FloatingPlaceholder.tsx'
18
18
  import { DownloadDock } from './DownloadDock.tsx'
19
+ import { PortsView, IconPlug } from './PortsView.tsx'
19
20
  import { QuickOpen } from './QuickOpen.tsx'
20
21
  import { RemoteExplorer } from './RemoteExplorer.tsx'
21
22
  import { SearchView } from './SearchView.tsx'
@@ -37,7 +38,7 @@ import {
37
38
  MiniSpinner,
38
39
  } from './vsc/kit.tsx'
39
40
 
40
- type RailView = 'explorer' | 'search' | 'scm' | 'history' | 'editor' | 'terminal' | 'workspaces'
41
+ type RailView = 'explorer' | 'search' | 'scm' | 'history' | 'editor' | 'terminal' | 'ports' | 'workspaces'
41
42
 
42
43
  const SPLIT_KEY = 'dsh-remote-vs.split'
43
44
  const HIDDEN_KEY = 'dsh-remote-vs.showHidden'
@@ -429,6 +430,10 @@ function Shell(props: { ctx: Context; visible: boolean }): ReactNode {
429
430
  // The terminal draws its own header + tab strip, so it takes the whole
430
431
  // slot (no extra padding wrapper).
431
432
  return <TerminalView t={t} hosts={store.hosts} visible={panelLive('terminal')} request={store.terminalRequest} />
433
+ case 'ports':
434
+ // Same shape as the terminal: its own header (host picker + refresh) and
435
+ // its own scroller, so no viewpad wrapper either.
436
+ return <PortsView t={t} hosts={store.hosts} visible={panelLive('ports')} />
432
437
  case 'workspaces':
433
438
  return (
434
439
  <div className="rvs-viewpad" style={{ height: '100%' }}>
@@ -515,6 +520,7 @@ function Shell(props: { ctx: Context; visible: boolean }): ReactNode {
515
520
  {editorInStack && store.tabs.length > 0
516
521
  && railButton('editor', store.activeTab?.rel.split('/').pop() ?? t('tab.editor'), <IconDiff size={17} />, store.tabs.length)}
517
522
  {railButton('terminal', t('tab.terminal'), <IconTerminal size={17} />)}
523
+ {railButton('ports', t('tab.ports'), <IconPlug size={17} />)}
518
524
  {railButton('workspaces', t('tab.workspaces'), <IconServer size={17} />, store.workspaces.length)}
519
525
  </div>
520
526
  <div className="rvs-column" ref={columnRef}>