@lvce-editor/ports-view 0.15.0 → 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.
- package/dist/portsViewWorkerMain.js +93 -99
- package/package.json +1 -1
|
@@ -54,49 +54,6 @@ class VError extends Error {
|
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
class AssertionError extends Error {
|
|
58
|
-
constructor(message) {
|
|
59
|
-
super(message);
|
|
60
|
-
this.name = 'AssertionError';
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
const Object$1 = 1;
|
|
64
|
-
const Number$1 = 2;
|
|
65
|
-
const Array$1 = 3;
|
|
66
|
-
const String$1 = 4;
|
|
67
|
-
const Boolean$1 = 5;
|
|
68
|
-
const Function = 6;
|
|
69
|
-
const Null = 7;
|
|
70
|
-
const Unknown = 8;
|
|
71
|
-
const getType = value => {
|
|
72
|
-
switch (typeof value) {
|
|
73
|
-
case 'number':
|
|
74
|
-
return Number$1;
|
|
75
|
-
case 'function':
|
|
76
|
-
return Function;
|
|
77
|
-
case 'string':
|
|
78
|
-
return String$1;
|
|
79
|
-
case 'object':
|
|
80
|
-
if (value === null) {
|
|
81
|
-
return Null;
|
|
82
|
-
}
|
|
83
|
-
if (Array.isArray(value)) {
|
|
84
|
-
return Array$1;
|
|
85
|
-
}
|
|
86
|
-
return Object$1;
|
|
87
|
-
case 'boolean':
|
|
88
|
-
return Boolean$1;
|
|
89
|
-
default:
|
|
90
|
-
return Unknown;
|
|
91
|
-
}
|
|
92
|
-
};
|
|
93
|
-
const number = value => {
|
|
94
|
-
const type = getType(value);
|
|
95
|
-
if (type !== Number$1) {
|
|
96
|
-
throw new AssertionError('expected value to be of type number');
|
|
97
|
-
}
|
|
98
|
-
};
|
|
99
|
-
|
|
100
57
|
const isMessagePort = value => {
|
|
101
58
|
return value && value instanceof MessagePort;
|
|
102
59
|
};
|
|
@@ -675,9 +632,12 @@ const applyDataProperties = (restoredError, error) => {
|
|
|
675
632
|
writable: true
|
|
676
633
|
});
|
|
677
634
|
}
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
restoredError
|
|
635
|
+
const name = error.data.name || error.data.type;
|
|
636
|
+
if (name) {
|
|
637
|
+
Object.defineProperty(restoredError, 'name', {
|
|
638
|
+
configurable: true,
|
|
639
|
+
value: name
|
|
640
|
+
});
|
|
681
641
|
}
|
|
682
642
|
};
|
|
683
643
|
const applyDirectProperties = (restoredError, error) => {
|
|
@@ -694,7 +654,7 @@ const applyDirectProperties = (restoredError, error) => {
|
|
|
694
654
|
}
|
|
695
655
|
};
|
|
696
656
|
const restoreMessageError = (error, _currentStack) => {
|
|
697
|
-
const restoredError = constructError(error.message, error.type || error.data?.type, error.name);
|
|
657
|
+
const restoredError = constructError(error.message, error.type || error.data?.type, error.name || error.data?.name);
|
|
698
658
|
if (typeof error.code === 'string' || typeof error.code === 'number') {
|
|
699
659
|
Object.defineProperty(restoredError, 'code', {
|
|
700
660
|
configurable: true,
|
|
@@ -904,6 +864,12 @@ const handleJsonRpcMessage = async (...args) => {
|
|
|
904
864
|
requiresSocket,
|
|
905
865
|
resolve
|
|
906
866
|
} = options;
|
|
867
|
+
if (message === 'ready') {
|
|
868
|
+
return;
|
|
869
|
+
}
|
|
870
|
+
if (!message || typeof message !== 'object') {
|
|
871
|
+
throw new JsonRpcError('unexpected message');
|
|
872
|
+
}
|
|
907
873
|
if ('id' in message) {
|
|
908
874
|
if ('method' in message) {
|
|
909
875
|
const response = await getResponse(message, ipc, execute, preparePrettyError, logError, requiresSocket);
|
|
@@ -1021,6 +987,9 @@ const logError = () => {
|
|
|
1021
987
|
// handled by renderer worker
|
|
1022
988
|
};
|
|
1023
989
|
const handleMessage = event => {
|
|
990
|
+
if (event.data === 'ready') {
|
|
991
|
+
return Promise.resolve();
|
|
992
|
+
}
|
|
1024
993
|
const actualRequiresSocket = event?.target?.requiresSocket || requiresSocket;
|
|
1025
994
|
const actualExecute = event?.target?.execute || execute;
|
|
1026
995
|
return handleJsonRpcMessage(event.target, event.data, actualExecute, event.target._resolve, preparePrettyError, logError, actualRequiresSocket);
|
|
@@ -1094,7 +1063,7 @@ const createMockRpc = ({
|
|
|
1094
1063
|
};
|
|
1095
1064
|
|
|
1096
1065
|
const rpcs = Object.create(null);
|
|
1097
|
-
const set$
|
|
1066
|
+
const set$3 = (id, rpc) => {
|
|
1098
1067
|
rpcs[id] = rpc;
|
|
1099
1068
|
};
|
|
1100
1069
|
const get$1 = id => {
|
|
@@ -1106,37 +1075,38 @@ const remove = id => {
|
|
|
1106
1075
|
|
|
1107
1076
|
/* eslint-disable @typescript-eslint/explicit-function-return-type */
|
|
1108
1077
|
const create$2 = rpcId => {
|
|
1078
|
+
// Set by set() only: a mock rpc from registerMockRpc does not count as connected.
|
|
1079
|
+
let connected = false;
|
|
1109
1080
|
return {
|
|
1110
1081
|
async dispose() {
|
|
1111
1082
|
const rpc = get$1(rpcId);
|
|
1083
|
+
connected = false;
|
|
1112
1084
|
await rpc.dispose();
|
|
1113
1085
|
},
|
|
1114
|
-
// @ts-ignore
|
|
1115
1086
|
invoke(method, ...params) {
|
|
1116
1087
|
const rpc = get$1(rpcId);
|
|
1117
|
-
// @ts-ignore
|
|
1118
1088
|
return rpc.invoke(method, ...params);
|
|
1119
1089
|
},
|
|
1120
|
-
// @ts-ignore
|
|
1121
1090
|
invokeAndTransfer(method, ...params) {
|
|
1122
1091
|
const rpc = get$1(rpcId);
|
|
1123
|
-
// @ts-ignore
|
|
1124
1092
|
return rpc.invokeAndTransfer(method, ...params);
|
|
1125
1093
|
},
|
|
1094
|
+
isConnected() {
|
|
1095
|
+
return connected;
|
|
1096
|
+
},
|
|
1126
1097
|
registerMockRpc(commandMap) {
|
|
1127
1098
|
const mockRpc = createMockRpc({
|
|
1128
1099
|
commandMap
|
|
1129
1100
|
});
|
|
1130
|
-
set$
|
|
1131
|
-
// @ts-ignore
|
|
1101
|
+
set$3(rpcId, mockRpc);
|
|
1132
1102
|
mockRpc[Symbol.dispose] = () => {
|
|
1133
1103
|
remove(rpcId);
|
|
1134
1104
|
};
|
|
1135
|
-
// @ts-ignore
|
|
1136
1105
|
return mockRpc;
|
|
1137
1106
|
},
|
|
1138
1107
|
set(rpc) {
|
|
1139
|
-
set$
|
|
1108
|
+
set$3(rpcId, rpc);
|
|
1109
|
+
connected = true;
|
|
1140
1110
|
}
|
|
1141
1111
|
};
|
|
1142
1112
|
};
|
|
@@ -1181,23 +1151,67 @@ const SetFocusContext = 'Viewlet.setFocusContext';
|
|
|
1181
1151
|
const SetPatches = 'Viewlet.setPatches';
|
|
1182
1152
|
|
|
1183
1153
|
const {
|
|
1184
|
-
invoke: invoke$
|
|
1185
|
-
|
|
1154
|
+
invoke: invoke$1,
|
|
1155
|
+
isConnected,
|
|
1156
|
+
set: set$2
|
|
1186
1157
|
} = create$2(RendererProcess);
|
|
1187
1158
|
|
|
1159
|
+
class AssertionError extends Error {
|
|
1160
|
+
constructor(message) {
|
|
1161
|
+
super(message);
|
|
1162
|
+
this.name = 'AssertionError';
|
|
1163
|
+
}
|
|
1164
|
+
}
|
|
1165
|
+
const Object$1 = 1;
|
|
1166
|
+
const Number$1 = 2;
|
|
1167
|
+
const Array$1 = 3;
|
|
1168
|
+
const String$1 = 4;
|
|
1169
|
+
const Boolean$1 = 5;
|
|
1170
|
+
const Function = 6;
|
|
1171
|
+
const Null = 7;
|
|
1172
|
+
const Unknown = 8;
|
|
1173
|
+
const getType = value => {
|
|
1174
|
+
switch (typeof value) {
|
|
1175
|
+
case 'number':
|
|
1176
|
+
return Number$1;
|
|
1177
|
+
case 'function':
|
|
1178
|
+
return Function;
|
|
1179
|
+
case 'string':
|
|
1180
|
+
return String$1;
|
|
1181
|
+
case 'object':
|
|
1182
|
+
if (value === null) {
|
|
1183
|
+
return Null;
|
|
1184
|
+
}
|
|
1185
|
+
if (Array.isArray(value)) {
|
|
1186
|
+
return Array$1;
|
|
1187
|
+
}
|
|
1188
|
+
return Object$1;
|
|
1189
|
+
case 'boolean':
|
|
1190
|
+
return Boolean$1;
|
|
1191
|
+
default:
|
|
1192
|
+
return Unknown;
|
|
1193
|
+
}
|
|
1194
|
+
};
|
|
1195
|
+
const number = value => {
|
|
1196
|
+
const type = getType(value);
|
|
1197
|
+
if (type !== Number$1) {
|
|
1198
|
+
throw new AssertionError('expected value to be of type number');
|
|
1199
|
+
}
|
|
1200
|
+
};
|
|
1201
|
+
|
|
1188
1202
|
const {
|
|
1189
|
-
invoke
|
|
1190
|
-
set: set$
|
|
1203
|
+
invoke,
|
|
1204
|
+
set: set$1
|
|
1191
1205
|
} = create$2(RendererWorker);
|
|
1192
1206
|
const showContextMenu2 = async (uid, menuId, x, y, args) => {
|
|
1193
1207
|
number(uid);
|
|
1194
1208
|
number(menuId);
|
|
1195
1209
|
number(x);
|
|
1196
1210
|
number(y);
|
|
1197
|
-
await invoke
|
|
1211
|
+
await invoke('ContextMenu.show2', uid, menuId, x, y, args);
|
|
1198
1212
|
};
|
|
1199
1213
|
const writeClipBoardText = async text => {
|
|
1200
|
-
await invoke
|
|
1214
|
+
await invoke('ClipBoard.writeText', /* text */text);
|
|
1201
1215
|
};
|
|
1202
1216
|
|
|
1203
1217
|
const toCommandId = key => {
|
|
@@ -1630,7 +1644,7 @@ const recalculateVirtualList = state => {
|
|
|
1630
1644
|
const minLineY = itemHeight === 0 ? 0 : Math.floor(deltaY / itemHeight);
|
|
1631
1645
|
const visibleCount = itemHeight === 0 ? 0 : Math.ceil(listHeight / itemHeight) + 1;
|
|
1632
1646
|
const maxLineY = Math.min(ports.length, minLineY + visibleCount);
|
|
1633
|
-
const scrollBarHeight =
|
|
1647
|
+
const scrollBarHeight = listHeight === 0 || contentHeight <= listHeight ? 0 : Math.max(minimumScrollBarSize, listHeight * listHeight / contentHeight);
|
|
1634
1648
|
const scrollBarY = finalDeltaY === 0 ? 0 : deltaY / finalDeltaY * (listHeight - scrollBarHeight);
|
|
1635
1649
|
const calculated = {
|
|
1636
1650
|
...state,
|
|
@@ -1737,7 +1751,7 @@ const forwardRemotePort = async (state, port) => {
|
|
|
1737
1751
|
uid
|
|
1738
1752
|
} = state;
|
|
1739
1753
|
try {
|
|
1740
|
-
const forwardedPort = await invoke
|
|
1754
|
+
const forwardedPort = await invoke('Application.executeForView', uid, 'PortProvider.forwardPort', port);
|
|
1741
1755
|
if (!forwardedPort || typeof forwardedPort !== 'object' || !('localPort' in forwardedPort)) {
|
|
1742
1756
|
throw new Error('Remote SSH returned an invalid local forwarding port');
|
|
1743
1757
|
}
|
|
@@ -1769,7 +1783,7 @@ const {
|
|
|
1769
1783
|
get,
|
|
1770
1784
|
getCommandIds,
|
|
1771
1785
|
registerCommands,
|
|
1772
|
-
set
|
|
1786
|
+
set,
|
|
1773
1787
|
wrapGetter,
|
|
1774
1788
|
wrapSerialCommand
|
|
1775
1789
|
} = create$1();
|
|
@@ -1806,7 +1820,7 @@ const create = (uid, uri, x, y, width, height, platform, assetDir, parentUid) =>
|
|
|
1806
1820
|
y
|
|
1807
1821
|
};
|
|
1808
1822
|
const calculated = recalculateVirtualList(state);
|
|
1809
|
-
set
|
|
1823
|
+
set(uid, calculated, calculated);
|
|
1810
1824
|
};
|
|
1811
1825
|
|
|
1812
1826
|
const isFocusContextEqual = (oldState, newState) => {
|
|
@@ -2359,8 +2373,8 @@ const openAddress = async (state, portNumber) => {
|
|
|
2359
2373
|
return state;
|
|
2360
2374
|
}
|
|
2361
2375
|
const url = getAddressUrl(port.forwardedAddress);
|
|
2362
|
-
await invoke
|
|
2363
|
-
await invoke
|
|
2376
|
+
await invoke('Layout.showPreview', 'simple-browser://');
|
|
2377
|
+
await invoke('SimpleBrowser.openOrRevealTab', url);
|
|
2364
2378
|
return state;
|
|
2365
2379
|
};
|
|
2366
2380
|
|
|
@@ -2404,13 +2418,10 @@ const toggleRemoteSshPort = async (state, portNumber) => {
|
|
|
2404
2418
|
let forwardedAddress = oldForwardedAddress;
|
|
2405
2419
|
try {
|
|
2406
2420
|
if (port.active) {
|
|
2407
|
-
await invoke
|
|
2421
|
+
await invoke('Application.executeForView', uid, 'PortProvider.stopForwardPort', portNumber);
|
|
2408
2422
|
} else {
|
|
2409
|
-
const forwardedPort = await invoke
|
|
2410
|
-
if (!forwardedPort || typeof forwardedPort !== 'object' || !('localPort' in forwardedPort)) {
|
|
2411
|
-
throw new Error('Remote SSH returned an invalid local forwarding port');
|
|
2412
|
-
}
|
|
2413
|
-
if (!Number.isSafeInteger(forwardedPort.localPort) || Number(forwardedPort.localPort) < 1 || Number(forwardedPort.localPort) > 65_535) {
|
|
2423
|
+
const forwardedPort = await invoke('Application.executeForView', uid, 'PortProvider.forwardPort', portNumber);
|
|
2424
|
+
if (!forwardedPort || typeof forwardedPort !== 'object' || !('localPort' in forwardedPort) || !Number.isSafeInteger(forwardedPort.localPort) || Number(forwardedPort.localPort) < 1 || Number(forwardedPort.localPort) > 65_535) {
|
|
2414
2425
|
throw new Error('Remote SSH returned an invalid local forwarding port');
|
|
2415
2426
|
}
|
|
2416
2427
|
forwardedAddress = `localhost:${forwardedPort.localPort}`;
|
|
@@ -2497,30 +2508,13 @@ const handleFocus = state => {
|
|
|
2497
2508
|
};
|
|
2498
2509
|
};
|
|
2499
2510
|
|
|
2500
|
-
const state = {
|
|
2501
|
-
connected: false
|
|
2502
|
-
};
|
|
2503
|
-
const isConnected = () => {
|
|
2504
|
-
const {
|
|
2505
|
-
connected
|
|
2506
|
-
} = state;
|
|
2507
|
-
return connected;
|
|
2508
|
-
};
|
|
2509
|
-
const invoke = (method, ...params) => {
|
|
2510
|
-
return invoke$2(method, ...params);
|
|
2511
|
-
};
|
|
2512
|
-
const set = rpc => {
|
|
2513
|
-
set$3(rpc);
|
|
2514
|
-
state.connected = true;
|
|
2515
|
-
};
|
|
2516
|
-
|
|
2517
2511
|
const handleMessagePort = async (port, setAsRendererProcess = true) => {
|
|
2518
2512
|
const rpc = await create$4({
|
|
2519
|
-
commandMap: createDirectEventCommandMap(uid => invoke
|
|
2513
|
+
commandMap: createDirectEventCommandMap(uid => invoke('Viewlet.requestRender', uid)),
|
|
2520
2514
|
messagePort: port
|
|
2521
2515
|
});
|
|
2522
2516
|
if (setAsRendererProcess) {
|
|
2523
|
-
set(rpc);
|
|
2517
|
+
set$2(rpc);
|
|
2524
2518
|
}
|
|
2525
2519
|
};
|
|
2526
2520
|
|
|
@@ -2541,7 +2535,7 @@ const loadContent = async (state, workspaceUri = '') => {
|
|
|
2541
2535
|
const request = {};
|
|
2542
2536
|
requests.set(uid, request);
|
|
2543
2537
|
try {
|
|
2544
|
-
const ports = workspaceUri ? await invoke
|
|
2538
|
+
const ports = workspaceUri ? await invoke('Application.executeForView', uid, 'PortProvider.getPorts', workspaceUri) : [];
|
|
2545
2539
|
if (requests.get(uid) !== request) {
|
|
2546
2540
|
return get(uid).newState;
|
|
2547
2541
|
}
|
|
@@ -2587,7 +2581,7 @@ const stopRemotePort = async (state, portNumber) => {
|
|
|
2587
2581
|
uid
|
|
2588
2582
|
} = state;
|
|
2589
2583
|
try {
|
|
2590
|
-
await invoke
|
|
2584
|
+
await invoke('Application.executeForView', uid, 'PortProvider.stopForwardPort', portNumber);
|
|
2591
2585
|
} catch (error) {
|
|
2592
2586
|
return {
|
|
2593
2587
|
...state,
|
|
@@ -2973,7 +2967,7 @@ const render2 = (uid, diffResult) => {
|
|
|
2973
2967
|
scheduledState
|
|
2974
2968
|
} = get(uid);
|
|
2975
2969
|
const commands = pendingDiffs.map(diffType => getRenderer(diffType)(oldState, scheduledState)).filter(command => command.length > 0);
|
|
2976
|
-
set
|
|
2970
|
+
set(uid, scheduledState, scheduledState);
|
|
2977
2971
|
if (!isConnected() || commands.length === 0) {
|
|
2978
2972
|
return commands;
|
|
2979
2973
|
}
|
|
@@ -2984,12 +2978,12 @@ const renderDirect = async (uid, commands, oldState, renderedState) => {
|
|
|
2984
2978
|
const workerCommands = commands.filter(isWorkerCommand);
|
|
2985
2979
|
const processCommands = commands.filter(command => !isWorkerCommand(command));
|
|
2986
2980
|
try {
|
|
2987
|
-
const transactionId = await invoke('Viewlet.queueCommands', uid, [...processCommands, ['Viewlet.setUid', uid, uid]]);
|
|
2981
|
+
const transactionId = await invoke$1('Viewlet.queueCommands', uid, [...processCommands, ['Viewlet.setUid', uid, uid]]);
|
|
2988
2982
|
return [...workerCommands, ['Viewlet.commitPending', uid, transactionId]];
|
|
2989
2983
|
} catch (error) {
|
|
2990
2984
|
const current = get(uid);
|
|
2991
2985
|
if (current?.oldState === renderedState) {
|
|
2992
|
-
set
|
|
2986
|
+
set(uid, oldState, current.newState, current.scheduledState);
|
|
2993
2987
|
}
|
|
2994
2988
|
throw error;
|
|
2995
2989
|
}
|
|
@@ -3113,7 +3107,7 @@ const listen = async () => {
|
|
|
3113
3107
|
const rpc = await create$3({
|
|
3114
3108
|
commandMap: commandMap
|
|
3115
3109
|
});
|
|
3116
|
-
set$
|
|
3110
|
+
set$1(rpc);
|
|
3117
3111
|
};
|
|
3118
3112
|
|
|
3119
3113
|
const main = async () => {
|