@lvce-editor/ports-view 0.8.0 → 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 +127 -10
- package/package.json +1 -1
|
@@ -1554,7 +1554,8 @@ const handleAddPortInput = (state, value) => {
|
|
|
1554
1554
|
};
|
|
1555
1555
|
const submitAddPort = state => {
|
|
1556
1556
|
const {
|
|
1557
|
-
addPortValue
|
|
1557
|
+
addPortValue,
|
|
1558
|
+
workspaceUri
|
|
1558
1559
|
} = state;
|
|
1559
1560
|
const value = addPortValue.trim();
|
|
1560
1561
|
const port = Number(value);
|
|
@@ -1564,11 +1565,24 @@ const submitAddPort = state => {
|
|
|
1564
1565
|
addPortError: enterAPortNumberBetween1And65535()
|
|
1565
1566
|
};
|
|
1566
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
|
+
};
|
|
1567
1581
|
return {
|
|
1568
|
-
...addPort(
|
|
1582
|
+
...addPort(withoutDuplicate, {
|
|
1569
1583
|
active: true,
|
|
1570
|
-
forwardedAddress: `localhost:${
|
|
1571
|
-
origin
|
|
1584
|
+
forwardedAddress: `localhost:${localPort}`,
|
|
1585
|
+
origin,
|
|
1572
1586
|
port,
|
|
1573
1587
|
runningProcess: ''
|
|
1574
1588
|
}),
|
|
@@ -1577,6 +1591,30 @@ const submitAddPort = state => {
|
|
|
1577
1591
|
editing: false
|
|
1578
1592
|
};
|
|
1579
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
|
+
};
|
|
1580
1618
|
|
|
1581
1619
|
const copyLink = async (state, href) => {
|
|
1582
1620
|
await writeClipBoardText(href);
|
|
@@ -1612,6 +1650,7 @@ const create = (uid, uri, x, y, width, height, platform, assetDir, parentUid) =>
|
|
|
1612
1650
|
maxLineY: 0,
|
|
1613
1651
|
minimumScrollBarSize: 20,
|
|
1614
1652
|
minLineY: 0,
|
|
1653
|
+
pageScrollMultiplier: 16,
|
|
1615
1654
|
parentUid,
|
|
1616
1655
|
platform,
|
|
1617
1656
|
ports: [],
|
|
@@ -1620,6 +1659,7 @@ const create = (uid, uri, x, y, width, height, platform, assetDir, parentUid) =>
|
|
|
1620
1659
|
uid,
|
|
1621
1660
|
visiblePorts: [],
|
|
1622
1661
|
width,
|
|
1662
|
+
workspaceUri: uri,
|
|
1623
1663
|
x,
|
|
1624
1664
|
y
|
|
1625
1665
|
};
|
|
@@ -2184,8 +2224,12 @@ const openAddress = async (state, portNumber) => {
|
|
|
2184
2224
|
|
|
2185
2225
|
const togglePortActive = (state, portNumber) => {
|
|
2186
2226
|
const {
|
|
2187
|
-
ports
|
|
2227
|
+
ports,
|
|
2228
|
+
workspaceUri
|
|
2188
2229
|
} = state;
|
|
2230
|
+
if (workspaceUri.startsWith('remote-ssh://')) {
|
|
2231
|
+
return toggleRemoteSshPort(state, portNumber);
|
|
2232
|
+
}
|
|
2189
2233
|
const updated = {
|
|
2190
2234
|
...state,
|
|
2191
2235
|
ports: ports.map(item => {
|
|
@@ -2203,6 +2247,52 @@ const togglePortActive = (state, portNumber) => {
|
|
|
2203
2247
|
visiblePorts: getVisiblePorts(updated)
|
|
2204
2248
|
};
|
|
2205
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
|
+
};
|
|
2295
|
+
};
|
|
2206
2296
|
|
|
2207
2297
|
const handleClick = async (state, clientY, name) => {
|
|
2208
2298
|
const {
|
|
@@ -2265,12 +2355,12 @@ const handleFocus = state => {
|
|
|
2265
2355
|
};
|
|
2266
2356
|
};
|
|
2267
2357
|
|
|
2268
|
-
const PageScrollMultiplier = 16;
|
|
2269
2358
|
const handleWheel = (state, deltaMode, deltaY) => {
|
|
2270
2359
|
const {
|
|
2271
|
-
deltaY: oldDeltaY
|
|
2360
|
+
deltaY: oldDeltaY,
|
|
2361
|
+
pageScrollMultiplier
|
|
2272
2362
|
} = state;
|
|
2273
|
-
const multiplier = deltaMode === 0 ? 1 :
|
|
2363
|
+
const multiplier = deltaMode === 0 ? 1 : pageScrollMultiplier;
|
|
2274
2364
|
return setDeltaY(state, oldDeltaY + deltaY * multiplier);
|
|
2275
2365
|
};
|
|
2276
2366
|
|
|
@@ -2286,7 +2376,10 @@ const loadContent = async (state, workspaceUri = '') => {
|
|
|
2286
2376
|
if (requests.get(uid) !== request) {
|
|
2287
2377
|
return get(uid).newState;
|
|
2288
2378
|
}
|
|
2289
|
-
return
|
|
2379
|
+
return {
|
|
2380
|
+
...setPorts(state, ports),
|
|
2381
|
+
workspaceUri
|
|
2382
|
+
};
|
|
2290
2383
|
} finally {
|
|
2291
2384
|
if (requests.get(uid) === request) {
|
|
2292
2385
|
requests.delete(uid);
|
|
@@ -2310,8 +2403,32 @@ const openFocusedAddress = async state => {
|
|
|
2310
2403
|
const removePort = (state, portNumber) => {
|
|
2311
2404
|
const {
|
|
2312
2405
|
focusedIndex: oldFocusedIndex,
|
|
2313
|
-
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
|
|
2314
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) => {
|
|
2315
2432
|
const ports = oldPorts.filter(item => item.port !== portNumber);
|
|
2316
2433
|
const focusedIndex = Math.min(oldFocusedIndex, ports.length - 1);
|
|
2317
2434
|
return recalculateVirtualList({
|