@lvce-editor/ports-view 0.8.0 → 0.9.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.
- package/dist/portsViewWorkerMain.js +148 -14
- package/package.json +1 -1
|
@@ -615,6 +615,23 @@ const restoreMessageError = (error, _currentStack) => {
|
|
|
615
615
|
}
|
|
616
616
|
return restoredError;
|
|
617
617
|
};
|
|
618
|
+
const getFallbackMessage = error => {
|
|
619
|
+
if (error && typeof error.message === 'string' && error.message) {
|
|
620
|
+
return error.message;
|
|
621
|
+
}
|
|
622
|
+
if (error && error.data) {
|
|
623
|
+
return getFallbackMessage(error.data);
|
|
624
|
+
}
|
|
625
|
+
const stringified = String(error);
|
|
626
|
+
if (stringified !== '[object Object]') {
|
|
627
|
+
return stringified;
|
|
628
|
+
}
|
|
629
|
+
try {
|
|
630
|
+
return JSON.stringify(error);
|
|
631
|
+
} catch {
|
|
632
|
+
return stringified;
|
|
633
|
+
}
|
|
634
|
+
};
|
|
618
635
|
const restoreJsonRpcError = error => {
|
|
619
636
|
const currentStack = getCurrentStack();
|
|
620
637
|
if (error && error instanceof Error) {
|
|
@@ -623,13 +640,13 @@ const restoreJsonRpcError = error => {
|
|
|
623
640
|
if (error && error.code && error.code === MethodNotFound) {
|
|
624
641
|
return restoreMethodNotFoundError(error, currentStack);
|
|
625
642
|
}
|
|
643
|
+
if (error && error.error) {
|
|
644
|
+
return restoreJsonRpcError(error.error);
|
|
645
|
+
}
|
|
626
646
|
if (error && error.message) {
|
|
627
647
|
return restoreMessageError(error);
|
|
628
648
|
}
|
|
629
|
-
|
|
630
|
-
return new Error(`JsonRpc Error: ${error}`);
|
|
631
|
-
}
|
|
632
|
-
return new Error(`JsonRpc Error: ${error}`);
|
|
649
|
+
return new Error(`JsonRpc Error: ${getFallbackMessage(error)}`);
|
|
633
650
|
};
|
|
634
651
|
const unwrapJsonRpcResult = responseMessage => {
|
|
635
652
|
if ('error' in responseMessage) {
|
|
@@ -1554,7 +1571,8 @@ const handleAddPortInput = (state, value) => {
|
|
|
1554
1571
|
};
|
|
1555
1572
|
const submitAddPort = state => {
|
|
1556
1573
|
const {
|
|
1557
|
-
addPortValue
|
|
1574
|
+
addPortValue,
|
|
1575
|
+
workspaceUri
|
|
1558
1576
|
} = state;
|
|
1559
1577
|
const value = addPortValue.trim();
|
|
1560
1578
|
const port = Number(value);
|
|
@@ -1564,11 +1582,24 @@ const submitAddPort = state => {
|
|
|
1564
1582
|
addPortError: enterAPortNumberBetween1And65535()
|
|
1565
1583
|
};
|
|
1566
1584
|
}
|
|
1585
|
+
if (!workspaceUri.startsWith('remote-ssh://')) {
|
|
1586
|
+
return addPortToState(state, port, port, userForwarded());
|
|
1587
|
+
}
|
|
1588
|
+
return forwardRemotePort(state, port);
|
|
1589
|
+
};
|
|
1590
|
+
const addPortToState = (state, port, localPort, origin) => {
|
|
1591
|
+
const {
|
|
1592
|
+
ports
|
|
1593
|
+
} = state;
|
|
1594
|
+
const withoutDuplicate = {
|
|
1595
|
+
...state,
|
|
1596
|
+
ports: ports.filter(item => item.port !== port)
|
|
1597
|
+
};
|
|
1567
1598
|
return {
|
|
1568
|
-
...addPort(
|
|
1599
|
+
...addPort(withoutDuplicate, {
|
|
1569
1600
|
active: true,
|
|
1570
|
-
forwardedAddress: `localhost:${
|
|
1571
|
-
origin
|
|
1601
|
+
forwardedAddress: `localhost:${localPort}`,
|
|
1602
|
+
origin,
|
|
1572
1603
|
port,
|
|
1573
1604
|
runningProcess: ''
|
|
1574
1605
|
}),
|
|
@@ -1577,6 +1608,30 @@ const submitAddPort = state => {
|
|
|
1577
1608
|
editing: false
|
|
1578
1609
|
};
|
|
1579
1610
|
};
|
|
1611
|
+
const forwardRemotePort = async (state, port) => {
|
|
1612
|
+
const {
|
|
1613
|
+
uid
|
|
1614
|
+
} = state;
|
|
1615
|
+
try {
|
|
1616
|
+
const forwardedPort = await invoke('Application.executeForView', uid, 'PortProvider.forwardPort', port);
|
|
1617
|
+
if (!forwardedPort || typeof forwardedPort !== 'object' || !('localPort' in forwardedPort)) {
|
|
1618
|
+
throw new Error('Remote SSH returned an invalid local forwarding port');
|
|
1619
|
+
}
|
|
1620
|
+
const {
|
|
1621
|
+
localPort
|
|
1622
|
+
} = forwardedPort;
|
|
1623
|
+
if (!Number.isSafeInteger(localPort) || Number(localPort) < 1 || Number(localPort) > 65_535) {
|
|
1624
|
+
throw new Error('Remote SSH returned an invalid local forwarding port');
|
|
1625
|
+
}
|
|
1626
|
+
return addPortToState(state, port, Number(localPort), 'Remote SSH');
|
|
1627
|
+
} catch (error) {
|
|
1628
|
+
return {
|
|
1629
|
+
...state,
|
|
1630
|
+
addPortError: error instanceof Error ? error.message : String(error),
|
|
1631
|
+
editing: true
|
|
1632
|
+
};
|
|
1633
|
+
}
|
|
1634
|
+
};
|
|
1580
1635
|
|
|
1581
1636
|
const copyLink = async (state, href) => {
|
|
1582
1637
|
await writeClipBoardText(href);
|
|
@@ -1612,6 +1667,7 @@ const create = (uid, uri, x, y, width, height, platform, assetDir, parentUid) =>
|
|
|
1612
1667
|
maxLineY: 0,
|
|
1613
1668
|
minimumScrollBarSize: 20,
|
|
1614
1669
|
minLineY: 0,
|
|
1670
|
+
pageScrollMultiplier: 16,
|
|
1615
1671
|
parentUid,
|
|
1616
1672
|
platform,
|
|
1617
1673
|
ports: [],
|
|
@@ -1620,6 +1676,7 @@ const create = (uid, uri, x, y, width, height, platform, assetDir, parentUid) =>
|
|
|
1620
1676
|
uid,
|
|
1621
1677
|
visiblePorts: [],
|
|
1622
1678
|
width,
|
|
1679
|
+
workspaceUri: uri,
|
|
1623
1680
|
x,
|
|
1624
1681
|
y
|
|
1625
1682
|
};
|
|
@@ -2184,8 +2241,12 @@ const openAddress = async (state, portNumber) => {
|
|
|
2184
2241
|
|
|
2185
2242
|
const togglePortActive = (state, portNumber) => {
|
|
2186
2243
|
const {
|
|
2187
|
-
ports
|
|
2244
|
+
ports,
|
|
2245
|
+
workspaceUri
|
|
2188
2246
|
} = state;
|
|
2247
|
+
if (workspaceUri.startsWith('remote-ssh://')) {
|
|
2248
|
+
return toggleRemoteSshPort(state, portNumber);
|
|
2249
|
+
}
|
|
2189
2250
|
const updated = {
|
|
2190
2251
|
...state,
|
|
2191
2252
|
ports: ports.map(item => {
|
|
@@ -2203,6 +2264,52 @@ const togglePortActive = (state, portNumber) => {
|
|
|
2203
2264
|
visiblePorts: getVisiblePorts(updated)
|
|
2204
2265
|
};
|
|
2205
2266
|
};
|
|
2267
|
+
const toggleRemoteSshPort = async (state, portNumber) => {
|
|
2268
|
+
const {
|
|
2269
|
+
ports,
|
|
2270
|
+
uid
|
|
2271
|
+
} = state;
|
|
2272
|
+
const port = ports.find(item => item.port === portNumber);
|
|
2273
|
+
if (!port) {
|
|
2274
|
+
return state;
|
|
2275
|
+
}
|
|
2276
|
+
const {
|
|
2277
|
+
forwardedAddress: oldForwardedAddress
|
|
2278
|
+
} = port;
|
|
2279
|
+
let forwardedAddress = oldForwardedAddress;
|
|
2280
|
+
try {
|
|
2281
|
+
if (port.active) {
|
|
2282
|
+
await invoke('Application.executeForView', uid, 'PortProvider.stopForwardPort', portNumber);
|
|
2283
|
+
} else {
|
|
2284
|
+
const forwardedPort = await invoke('Application.executeForView', uid, 'PortProvider.forwardPort', portNumber);
|
|
2285
|
+
if (!forwardedPort || typeof forwardedPort !== 'object' || !('localPort' in forwardedPort)) {
|
|
2286
|
+
throw new Error('Remote SSH returned an invalid local forwarding port');
|
|
2287
|
+
}
|
|
2288
|
+
if (!Number.isSafeInteger(forwardedPort.localPort) || Number(forwardedPort.localPort) < 1 || Number(forwardedPort.localPort) > 65_535) {
|
|
2289
|
+
throw new Error('Remote SSH returned an invalid local forwarding port');
|
|
2290
|
+
}
|
|
2291
|
+
forwardedAddress = `localhost:${forwardedPort.localPort}`;
|
|
2292
|
+
}
|
|
2293
|
+
} catch (error) {
|
|
2294
|
+
return {
|
|
2295
|
+
...state,
|
|
2296
|
+
addPortError: error instanceof Error ? error.message : String(error),
|
|
2297
|
+
editing: true
|
|
2298
|
+
};
|
|
2299
|
+
}
|
|
2300
|
+
const updated = {
|
|
2301
|
+
...state,
|
|
2302
|
+
ports: ports.map(item => item.port === portNumber ? {
|
|
2303
|
+
...item,
|
|
2304
|
+
active: !item.active,
|
|
2305
|
+
forwardedAddress
|
|
2306
|
+
} : item)
|
|
2307
|
+
};
|
|
2308
|
+
return {
|
|
2309
|
+
...updated,
|
|
2310
|
+
visiblePorts: getVisiblePorts(updated)
|
|
2311
|
+
};
|
|
2312
|
+
};
|
|
2206
2313
|
|
|
2207
2314
|
const handleClick = async (state, clientY, name) => {
|
|
2208
2315
|
const {
|
|
@@ -2265,12 +2372,12 @@ const handleFocus = state => {
|
|
|
2265
2372
|
};
|
|
2266
2373
|
};
|
|
2267
2374
|
|
|
2268
|
-
const PageScrollMultiplier = 16;
|
|
2269
2375
|
const handleWheel = (state, deltaMode, deltaY) => {
|
|
2270
2376
|
const {
|
|
2271
|
-
deltaY: oldDeltaY
|
|
2377
|
+
deltaY: oldDeltaY,
|
|
2378
|
+
pageScrollMultiplier
|
|
2272
2379
|
} = state;
|
|
2273
|
-
const multiplier = deltaMode === 0 ? 1 :
|
|
2380
|
+
const multiplier = deltaMode === 0 ? 1 : pageScrollMultiplier;
|
|
2274
2381
|
return setDeltaY(state, oldDeltaY + deltaY * multiplier);
|
|
2275
2382
|
};
|
|
2276
2383
|
|
|
@@ -2286,7 +2393,10 @@ const loadContent = async (state, workspaceUri = '') => {
|
|
|
2286
2393
|
if (requests.get(uid) !== request) {
|
|
2287
2394
|
return get(uid).newState;
|
|
2288
2395
|
}
|
|
2289
|
-
return
|
|
2396
|
+
return {
|
|
2397
|
+
...setPorts(state, ports),
|
|
2398
|
+
workspaceUri
|
|
2399
|
+
};
|
|
2290
2400
|
} finally {
|
|
2291
2401
|
if (requests.get(uid) === request) {
|
|
2292
2402
|
requests.delete(uid);
|
|
@@ -2310,8 +2420,32 @@ const openFocusedAddress = async state => {
|
|
|
2310
2420
|
const removePort = (state, portNumber) => {
|
|
2311
2421
|
const {
|
|
2312
2422
|
focusedIndex: oldFocusedIndex,
|
|
2313
|
-
ports: oldPorts
|
|
2423
|
+
ports: oldPorts,
|
|
2424
|
+
workspaceUri
|
|
2425
|
+
} = state;
|
|
2426
|
+
if (workspaceUri.startsWith('remote-ssh://')) {
|
|
2427
|
+
return stopRemotePort(state, portNumber);
|
|
2428
|
+
}
|
|
2429
|
+
return updateState(state, oldPorts, oldFocusedIndex, portNumber);
|
|
2430
|
+
};
|
|
2431
|
+
const stopRemotePort = async (state, portNumber) => {
|
|
2432
|
+
const {
|
|
2433
|
+
focusedIndex,
|
|
2434
|
+
ports,
|
|
2435
|
+
uid
|
|
2314
2436
|
} = state;
|
|
2437
|
+
try {
|
|
2438
|
+
await invoke('Application.executeForView', uid, 'PortProvider.stopForwardPort', portNumber);
|
|
2439
|
+
} catch (error) {
|
|
2440
|
+
return {
|
|
2441
|
+
...state,
|
|
2442
|
+
addPortError: error instanceof Error ? error.message : String(error),
|
|
2443
|
+
editing: true
|
|
2444
|
+
};
|
|
2445
|
+
}
|
|
2446
|
+
return updateState(state, ports, focusedIndex, portNumber);
|
|
2447
|
+
};
|
|
2448
|
+
const updateState = (state, oldPorts, oldFocusedIndex, portNumber) => {
|
|
2315
2449
|
const ports = oldPorts.filter(item => item.port !== portNumber);
|
|
2316
2450
|
const focusedIndex = Math.min(oldFocusedIndex, ports.length - 1);
|
|
2317
2451
|
return recalculateVirtualList({
|