@lvce-editor/ports-view 0.7.3 → 0.8.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/dist/portsViewWorkerMain.js +165 -35
- package/package.json +1 -1
|
@@ -1454,6 +1454,24 @@ const clamp = (value, minimum, maximum) => {
|
|
|
1454
1454
|
return Math.min(Math.max(value, minimum), maximum);
|
|
1455
1455
|
};
|
|
1456
1456
|
|
|
1457
|
+
const getVisiblePorts = state => {
|
|
1458
|
+
const {
|
|
1459
|
+
focusedIndex,
|
|
1460
|
+
maxLineY,
|
|
1461
|
+
minLineY,
|
|
1462
|
+
ports
|
|
1463
|
+
} = state;
|
|
1464
|
+
const visible = [];
|
|
1465
|
+
for (let index = minLineY; index < maxLineY; index++) {
|
|
1466
|
+
visible.push({
|
|
1467
|
+
...ports[index],
|
|
1468
|
+
index,
|
|
1469
|
+
selected: index === focusedIndex
|
|
1470
|
+
});
|
|
1471
|
+
}
|
|
1472
|
+
return visible;
|
|
1473
|
+
};
|
|
1474
|
+
|
|
1457
1475
|
const recalculateVirtualList = state => {
|
|
1458
1476
|
const {
|
|
1459
1477
|
deltaY: oldDeltaY,
|
|
@@ -1473,7 +1491,7 @@ const recalculateVirtualList = state => {
|
|
|
1473
1491
|
const maxLineY = Math.min(ports.length, minLineY + visibleCount);
|
|
1474
1492
|
const scrollBarHeight = contentHeight <= listHeight || listHeight === 0 ? 0 : Math.max(minimumScrollBarSize, listHeight * listHeight / contentHeight);
|
|
1475
1493
|
const scrollBarY = finalDeltaY === 0 ? 0 : deltaY / finalDeltaY * (listHeight - scrollBarHeight);
|
|
1476
|
-
|
|
1494
|
+
const calculated = {
|
|
1477
1495
|
...state,
|
|
1478
1496
|
deltaY,
|
|
1479
1497
|
finalDeltaY,
|
|
@@ -1483,6 +1501,10 @@ const recalculateVirtualList = state => {
|
|
|
1483
1501
|
scrollBarHeight,
|
|
1484
1502
|
scrollBarY
|
|
1485
1503
|
};
|
|
1504
|
+
return {
|
|
1505
|
+
...calculated,
|
|
1506
|
+
visiblePorts: getVisiblePorts(calculated)
|
|
1507
|
+
};
|
|
1486
1508
|
};
|
|
1487
1509
|
|
|
1488
1510
|
const setPorts = (state, ports) => {
|
|
@@ -1532,7 +1554,8 @@ const handleAddPortInput = (state, value) => {
|
|
|
1532
1554
|
};
|
|
1533
1555
|
const submitAddPort = state => {
|
|
1534
1556
|
const {
|
|
1535
|
-
addPortValue
|
|
1557
|
+
addPortValue,
|
|
1558
|
+
workspaceUri
|
|
1536
1559
|
} = state;
|
|
1537
1560
|
const value = addPortValue.trim();
|
|
1538
1561
|
const port = Number(value);
|
|
@@ -1542,11 +1565,24 @@ const submitAddPort = state => {
|
|
|
1542
1565
|
addPortError: enterAPortNumberBetween1And65535()
|
|
1543
1566
|
};
|
|
1544
1567
|
}
|
|
1568
|
+
if (!workspaceUri.startsWith('remote-ssh://')) {
|
|
1569
|
+
return addPortToState(state, port, port, userForwarded());
|
|
1570
|
+
}
|
|
1571
|
+
return forwardRemotePort(state, port);
|
|
1572
|
+
};
|
|
1573
|
+
const addPortToState = (state, port, localPort, origin) => {
|
|
1574
|
+
const {
|
|
1575
|
+
ports
|
|
1576
|
+
} = state;
|
|
1577
|
+
const withoutDuplicate = {
|
|
1578
|
+
...state,
|
|
1579
|
+
ports: ports.filter(item => item.port !== port)
|
|
1580
|
+
};
|
|
1545
1581
|
return {
|
|
1546
|
-
...addPort(
|
|
1582
|
+
...addPort(withoutDuplicate, {
|
|
1547
1583
|
active: true,
|
|
1548
|
-
forwardedAddress: `localhost:${
|
|
1549
|
-
origin
|
|
1584
|
+
forwardedAddress: `localhost:${localPort}`,
|
|
1585
|
+
origin,
|
|
1550
1586
|
port,
|
|
1551
1587
|
runningProcess: ''
|
|
1552
1588
|
}),
|
|
@@ -1555,6 +1591,30 @@ const submitAddPort = state => {
|
|
|
1555
1591
|
editing: false
|
|
1556
1592
|
};
|
|
1557
1593
|
};
|
|
1594
|
+
const forwardRemotePort = async (state, port) => {
|
|
1595
|
+
const {
|
|
1596
|
+
uid
|
|
1597
|
+
} = state;
|
|
1598
|
+
try {
|
|
1599
|
+
const forwardedPort = await invoke('Application.executeForView', uid, 'PortProvider.forwardPort', port);
|
|
1600
|
+
if (!forwardedPort || typeof forwardedPort !== 'object' || !('localPort' in forwardedPort)) {
|
|
1601
|
+
throw new Error('Remote SSH returned an invalid local forwarding port');
|
|
1602
|
+
}
|
|
1603
|
+
const {
|
|
1604
|
+
localPort
|
|
1605
|
+
} = forwardedPort;
|
|
1606
|
+
if (!Number.isSafeInteger(localPort) || Number(localPort) < 1 || Number(localPort) > 65_535) {
|
|
1607
|
+
throw new Error('Remote SSH returned an invalid local forwarding port');
|
|
1608
|
+
}
|
|
1609
|
+
return addPortToState(state, port, Number(localPort), 'Remote SSH');
|
|
1610
|
+
} catch (error) {
|
|
1611
|
+
return {
|
|
1612
|
+
...state,
|
|
1613
|
+
addPortError: error instanceof Error ? error.message : String(error),
|
|
1614
|
+
editing: true
|
|
1615
|
+
};
|
|
1616
|
+
}
|
|
1617
|
+
};
|
|
1558
1618
|
|
|
1559
1619
|
const copyLink = async (state, href) => {
|
|
1560
1620
|
await writeClipBoardText(href);
|
|
@@ -1590,13 +1650,16 @@ const create = (uid, uri, x, y, width, height, platform, assetDir, parentUid) =>
|
|
|
1590
1650
|
maxLineY: 0,
|
|
1591
1651
|
minimumScrollBarSize: 20,
|
|
1592
1652
|
minLineY: 0,
|
|
1653
|
+
pageScrollMultiplier: 16,
|
|
1593
1654
|
parentUid,
|
|
1594
1655
|
platform,
|
|
1595
1656
|
ports: [],
|
|
1596
1657
|
scrollBarHeight: 0,
|
|
1597
1658
|
scrollBarY: 0,
|
|
1598
1659
|
uid,
|
|
1660
|
+
visiblePorts: [],
|
|
1599
1661
|
width,
|
|
1662
|
+
workspaceUri: uri,
|
|
1600
1663
|
x,
|
|
1601
1664
|
y
|
|
1602
1665
|
};
|
|
@@ -2108,11 +2171,15 @@ const getMenuIds = () => {
|
|
|
2108
2171
|
};
|
|
2109
2172
|
|
|
2110
2173
|
const handleBlur = state => {
|
|
2111
|
-
|
|
2174
|
+
const updated = {
|
|
2112
2175
|
...state,
|
|
2113
2176
|
focused: false,
|
|
2114
2177
|
focusedIndex: -1
|
|
2115
2178
|
};
|
|
2179
|
+
return {
|
|
2180
|
+
...updated,
|
|
2181
|
+
visiblePorts: getVisiblePorts(updated)
|
|
2182
|
+
};
|
|
2116
2183
|
};
|
|
2117
2184
|
|
|
2118
2185
|
const getIndexAt = (state, clientY) => {
|
|
@@ -2157,9 +2224,13 @@ const openAddress = async (state, portNumber) => {
|
|
|
2157
2224
|
|
|
2158
2225
|
const togglePortActive = (state, portNumber) => {
|
|
2159
2226
|
const {
|
|
2160
|
-
ports
|
|
2227
|
+
ports,
|
|
2228
|
+
workspaceUri
|
|
2161
2229
|
} = state;
|
|
2162
|
-
|
|
2230
|
+
if (workspaceUri.startsWith('remote-ssh://')) {
|
|
2231
|
+
return toggleRemoteSshPort(state, portNumber);
|
|
2232
|
+
}
|
|
2233
|
+
const updated = {
|
|
2163
2234
|
...state,
|
|
2164
2235
|
ports: ports.map(item => {
|
|
2165
2236
|
if (item.port !== portNumber) {
|
|
@@ -2171,6 +2242,56 @@ const togglePortActive = (state, portNumber) => {
|
|
|
2171
2242
|
};
|
|
2172
2243
|
})
|
|
2173
2244
|
};
|
|
2245
|
+
return {
|
|
2246
|
+
...updated,
|
|
2247
|
+
visiblePorts: getVisiblePorts(updated)
|
|
2248
|
+
};
|
|
2249
|
+
};
|
|
2250
|
+
const toggleRemoteSshPort = async (state, portNumber) => {
|
|
2251
|
+
const {
|
|
2252
|
+
ports,
|
|
2253
|
+
uid
|
|
2254
|
+
} = state;
|
|
2255
|
+
const port = ports.find(item => item.port === portNumber);
|
|
2256
|
+
if (!port) {
|
|
2257
|
+
return state;
|
|
2258
|
+
}
|
|
2259
|
+
const {
|
|
2260
|
+
forwardedAddress: oldForwardedAddress
|
|
2261
|
+
} = port;
|
|
2262
|
+
let forwardedAddress = oldForwardedAddress;
|
|
2263
|
+
try {
|
|
2264
|
+
if (port.active) {
|
|
2265
|
+
await invoke('Application.executeForView', uid, 'PortProvider.stopForwardPort', portNumber);
|
|
2266
|
+
} else {
|
|
2267
|
+
const forwardedPort = await invoke('Application.executeForView', uid, 'PortProvider.forwardPort', portNumber);
|
|
2268
|
+
if (!forwardedPort || typeof forwardedPort !== 'object' || !('localPort' in forwardedPort)) {
|
|
2269
|
+
throw new Error('Remote SSH returned an invalid local forwarding port');
|
|
2270
|
+
}
|
|
2271
|
+
if (!Number.isSafeInteger(forwardedPort.localPort) || Number(forwardedPort.localPort) < 1 || Number(forwardedPort.localPort) > 65_535) {
|
|
2272
|
+
throw new Error('Remote SSH returned an invalid local forwarding port');
|
|
2273
|
+
}
|
|
2274
|
+
forwardedAddress = `localhost:${forwardedPort.localPort}`;
|
|
2275
|
+
}
|
|
2276
|
+
} catch (error) {
|
|
2277
|
+
return {
|
|
2278
|
+
...state,
|
|
2279
|
+
addPortError: error instanceof Error ? error.message : String(error),
|
|
2280
|
+
editing: true
|
|
2281
|
+
};
|
|
2282
|
+
}
|
|
2283
|
+
const updated = {
|
|
2284
|
+
...state,
|
|
2285
|
+
ports: ports.map(item => item.port === portNumber ? {
|
|
2286
|
+
...item,
|
|
2287
|
+
active: !item.active,
|
|
2288
|
+
forwardedAddress
|
|
2289
|
+
} : item)
|
|
2290
|
+
};
|
|
2291
|
+
return {
|
|
2292
|
+
...updated,
|
|
2293
|
+
visiblePorts: getVisiblePorts(updated)
|
|
2294
|
+
};
|
|
2174
2295
|
};
|
|
2175
2296
|
|
|
2176
2297
|
const handleClick = async (state, clientY, name) => {
|
|
@@ -2234,12 +2355,12 @@ const handleFocus = state => {
|
|
|
2234
2355
|
};
|
|
2235
2356
|
};
|
|
2236
2357
|
|
|
2237
|
-
const PageScrollMultiplier = 16;
|
|
2238
2358
|
const handleWheel = (state, deltaMode, deltaY) => {
|
|
2239
2359
|
const {
|
|
2240
|
-
deltaY: oldDeltaY
|
|
2360
|
+
deltaY: oldDeltaY,
|
|
2361
|
+
pageScrollMultiplier
|
|
2241
2362
|
} = state;
|
|
2242
|
-
const multiplier = deltaMode === 0 ? 1 :
|
|
2363
|
+
const multiplier = deltaMode === 0 ? 1 : pageScrollMultiplier;
|
|
2243
2364
|
return setDeltaY(state, oldDeltaY + deltaY * multiplier);
|
|
2244
2365
|
};
|
|
2245
2366
|
|
|
@@ -2255,7 +2376,10 @@ const loadContent = async (state, workspaceUri = '') => {
|
|
|
2255
2376
|
if (requests.get(uid) !== request) {
|
|
2256
2377
|
return get(uid).newState;
|
|
2257
2378
|
}
|
|
2258
|
-
return
|
|
2379
|
+
return {
|
|
2380
|
+
...setPorts(state, ports),
|
|
2381
|
+
workspaceUri
|
|
2382
|
+
};
|
|
2259
2383
|
} finally {
|
|
2260
2384
|
if (requests.get(uid) === request) {
|
|
2261
2385
|
requests.delete(uid);
|
|
@@ -2279,8 +2403,32 @@ const openFocusedAddress = async state => {
|
|
|
2279
2403
|
const removePort = (state, portNumber) => {
|
|
2280
2404
|
const {
|
|
2281
2405
|
focusedIndex: oldFocusedIndex,
|
|
2282
|
-
ports: oldPorts
|
|
2406
|
+
ports: oldPorts,
|
|
2407
|
+
workspaceUri
|
|
2408
|
+
} = state;
|
|
2409
|
+
if (workspaceUri.startsWith('remote-ssh://')) {
|
|
2410
|
+
return stopRemotePort(state, portNumber);
|
|
2411
|
+
}
|
|
2412
|
+
return updateState(state, oldPorts, oldFocusedIndex, portNumber);
|
|
2413
|
+
};
|
|
2414
|
+
const stopRemotePort = async (state, portNumber) => {
|
|
2415
|
+
const {
|
|
2416
|
+
focusedIndex,
|
|
2417
|
+
ports,
|
|
2418
|
+
uid
|
|
2283
2419
|
} = state;
|
|
2420
|
+
try {
|
|
2421
|
+
await invoke('Application.executeForView', uid, 'PortProvider.stopForwardPort', portNumber);
|
|
2422
|
+
} catch (error) {
|
|
2423
|
+
return {
|
|
2424
|
+
...state,
|
|
2425
|
+
addPortError: error instanceof Error ? error.message : String(error),
|
|
2426
|
+
editing: true
|
|
2427
|
+
};
|
|
2428
|
+
}
|
|
2429
|
+
return updateState(state, ports, focusedIndex, portNumber);
|
|
2430
|
+
};
|
|
2431
|
+
const updateState = (state, oldPorts, oldFocusedIndex, portNumber) => {
|
|
2284
2432
|
const ports = oldPorts.filter(item => item.port !== portNumber);
|
|
2285
2433
|
const focusedIndex = Math.min(oldFocusedIndex, ports.length - 1);
|
|
2286
2434
|
return recalculateVirtualList({
|
|
@@ -2531,24 +2679,6 @@ const getPortRowVirtualDom = port => {
|
|
|
2531
2679
|
}, text(port.forwardedAddress), ...getTextCell(port.runningProcess), ...getTextCell(port.origin)];
|
|
2532
2680
|
};
|
|
2533
2681
|
|
|
2534
|
-
const getVisiblePorts = state => {
|
|
2535
|
-
const {
|
|
2536
|
-
focusedIndex,
|
|
2537
|
-
maxLineY,
|
|
2538
|
-
minLineY,
|
|
2539
|
-
ports
|
|
2540
|
-
} = state;
|
|
2541
|
-
const visible = [];
|
|
2542
|
-
for (let index = minLineY; index < maxLineY; index++) {
|
|
2543
|
-
visible.push({
|
|
2544
|
-
...ports[index],
|
|
2545
|
-
index,
|
|
2546
|
-
selected: index === focusedIndex
|
|
2547
|
-
});
|
|
2548
|
-
}
|
|
2549
|
-
return visible;
|
|
2550
|
-
};
|
|
2551
|
-
|
|
2552
2682
|
const emptyBody = {
|
|
2553
2683
|
childCount: 1,
|
|
2554
2684
|
className: PortsTableBody,
|
|
@@ -2564,19 +2694,19 @@ const emptyMessage = {
|
|
|
2564
2694
|
const getPortsTableBodyVirtualDom = state => {
|
|
2565
2695
|
const {
|
|
2566
2696
|
loaded,
|
|
2567
|
-
ports
|
|
2697
|
+
ports,
|
|
2698
|
+
visiblePorts
|
|
2568
2699
|
} = state;
|
|
2569
2700
|
if (loaded && ports.length === 0) {
|
|
2570
2701
|
return [emptyBody, emptyMessage, text(noForwardedPorts())];
|
|
2571
2702
|
}
|
|
2572
|
-
const visible = getVisiblePorts(state);
|
|
2573
2703
|
return [{
|
|
2574
2704
|
ariaRowCount: ports.length + 1,
|
|
2575
|
-
childCount:
|
|
2705
|
+
childCount: visiblePorts.length,
|
|
2576
2706
|
className: PortsTableBody,
|
|
2577
2707
|
role: RowGroup,
|
|
2578
2708
|
type: Div
|
|
2579
|
-
}, ...
|
|
2709
|
+
}, ...visiblePorts.flatMap(getPortRowVirtualDom)];
|
|
2580
2710
|
};
|
|
2581
2711
|
|
|
2582
2712
|
const headerRow = {
|