@lvce-editor/ports-view 0.7.0 → 0.7.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 +131 -1
- package/package.json +1 -1
|
@@ -54,6 +54,49 @@ 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
|
+
|
|
57
100
|
const isMessagePort = value => {
|
|
58
101
|
return value && value instanceof MessagePort;
|
|
59
102
|
};
|
|
@@ -977,6 +1020,7 @@ const Text = 12;
|
|
|
977
1020
|
const A = 53;
|
|
978
1021
|
const Reference = 100;
|
|
979
1022
|
|
|
1023
|
+
const ClientX = 'event.clientX';
|
|
980
1024
|
const ClientY = 'event.clientY';
|
|
981
1025
|
const DeltaMode = 'event.deltaMode';
|
|
982
1026
|
const DeltaY = 'event.deltaY';
|
|
@@ -996,6 +1040,8 @@ const KeyA = 29;
|
|
|
996
1040
|
|
|
997
1041
|
const Shift = 1 << 10 >>> 0;
|
|
998
1042
|
|
|
1043
|
+
const None = 0;
|
|
1044
|
+
|
|
999
1045
|
const RendererWorker = 1;
|
|
1000
1046
|
|
|
1001
1047
|
const SetCss = 'Viewlet.setCss';
|
|
@@ -1007,6 +1053,16 @@ const {
|
|
|
1007
1053
|
invoke,
|
|
1008
1054
|
set: set$1
|
|
1009
1055
|
} = create$2(RendererWorker);
|
|
1056
|
+
const showContextMenu2 = async (uid, menuId, x, y, args) => {
|
|
1057
|
+
number(uid);
|
|
1058
|
+
number(menuId);
|
|
1059
|
+
number(x);
|
|
1060
|
+
number(y);
|
|
1061
|
+
await invoke('ContextMenu.show2', uid, menuId, x, y, args);
|
|
1062
|
+
};
|
|
1063
|
+
const writeClipBoardText = async text => {
|
|
1064
|
+
await invoke('ClipBoard.writeText', /* text */text);
|
|
1065
|
+
};
|
|
1010
1066
|
const openUri = async (uri, focus, options) => {
|
|
1011
1067
|
await invoke('Main.openUri', {
|
|
1012
1068
|
...options,
|
|
@@ -1292,6 +1348,7 @@ const i18nString = (key, placeholders = emptyObject) => {
|
|
|
1292
1348
|
const Add$1 = 'Add';
|
|
1293
1349
|
const AddPort = 'Add Port';
|
|
1294
1350
|
const Cancel = 'Cancel';
|
|
1351
|
+
const CopyLink = 'Copy Link';
|
|
1295
1352
|
const EnterAPortNumberBetween1And65535 = 'Enter a port number between 1 and 65535';
|
|
1296
1353
|
const ForwardedAddress = 'Forwarded Address';
|
|
1297
1354
|
const NoForwardedPorts = 'No forwarded ports';
|
|
@@ -1313,6 +1370,9 @@ const addPort$1 = () => {
|
|
|
1313
1370
|
const cancel = () => {
|
|
1314
1371
|
return i18nString(Cancel);
|
|
1315
1372
|
};
|
|
1373
|
+
const copyLink$1 = () => {
|
|
1374
|
+
return i18nString(CopyLink);
|
|
1375
|
+
};
|
|
1316
1376
|
const enterAPortNumberBetween1And65535 = () => {
|
|
1317
1377
|
return i18nString(EnterAPortNumberBetween1And65535);
|
|
1318
1378
|
};
|
|
@@ -1511,6 +1571,11 @@ const handleAddPortKeyDown = (state, key) => {
|
|
|
1511
1571
|
return state;
|
|
1512
1572
|
};
|
|
1513
1573
|
|
|
1574
|
+
const copyLink = async (state, href) => {
|
|
1575
|
+
await writeClipBoardText(href);
|
|
1576
|
+
return state;
|
|
1577
|
+
};
|
|
1578
|
+
|
|
1514
1579
|
const {
|
|
1515
1580
|
diff,
|
|
1516
1581
|
dispose,
|
|
@@ -1518,7 +1583,8 @@ const {
|
|
|
1518
1583
|
getCommandIds,
|
|
1519
1584
|
registerCommands,
|
|
1520
1585
|
set,
|
|
1521
|
-
wrapCommand
|
|
1586
|
+
wrapCommand,
|
|
1587
|
+
wrapGetter
|
|
1522
1588
|
} = create$1();
|
|
1523
1589
|
|
|
1524
1590
|
const create = (uid, uri, x, y, width, height, platform, assetDir, parentUid) => {
|
|
@@ -2025,6 +2091,25 @@ const getKeyBindings = () => {
|
|
|
2025
2091
|
}];
|
|
2026
2092
|
};
|
|
2027
2093
|
|
|
2094
|
+
const PortsTable$1 = 28;
|
|
2095
|
+
|
|
2096
|
+
const getMenuEntries2 = (_state, props) => {
|
|
2097
|
+
if (props.menuId !== PortsTable$1 || !props.href) {
|
|
2098
|
+
return [];
|
|
2099
|
+
}
|
|
2100
|
+
return [{
|
|
2101
|
+
args: [props.href],
|
|
2102
|
+
command: 'Ports.copyLink',
|
|
2103
|
+
flags: None,
|
|
2104
|
+
id: 'copyLink',
|
|
2105
|
+
label: copyLink$1()
|
|
2106
|
+
}];
|
|
2107
|
+
};
|
|
2108
|
+
|
|
2109
|
+
const getMenuIds = () => {
|
|
2110
|
+
return [PortsTable$1];
|
|
2111
|
+
};
|
|
2112
|
+
|
|
2028
2113
|
const handleBlur = state => {
|
|
2029
2114
|
return {
|
|
2030
2115
|
...state,
|
|
@@ -2108,6 +2193,41 @@ const handleClick = async (state, clientY, name) => {
|
|
|
2108
2193
|
return focused;
|
|
2109
2194
|
};
|
|
2110
2195
|
|
|
2196
|
+
const show2 = async (uid, menuId, x, y, args) => {
|
|
2197
|
+
await showContextMenu2(uid, menuId, x, y, args);
|
|
2198
|
+
};
|
|
2199
|
+
|
|
2200
|
+
const getPortNumber = (state, clientY, name) => {
|
|
2201
|
+
const {
|
|
2202
|
+
ports
|
|
2203
|
+
} = state;
|
|
2204
|
+
if (name.startsWith('port-address-') || name.startsWith('port-status-')) {
|
|
2205
|
+
const portNumber = Number(name.slice(name.lastIndexOf('-') + 1));
|
|
2206
|
+
return ports.some(port => port.port === portNumber) ? portNumber : undefined;
|
|
2207
|
+
}
|
|
2208
|
+
const index = getIndexAt(state, clientY);
|
|
2209
|
+
return index === -1 ? undefined : ports[index]?.port;
|
|
2210
|
+
};
|
|
2211
|
+
const handleContextMenu = async (state, clientX, clientY, name = '') => {
|
|
2212
|
+
const {
|
|
2213
|
+
ports,
|
|
2214
|
+
uid
|
|
2215
|
+
} = state;
|
|
2216
|
+
const portNumber = getPortNumber(state, clientY, name);
|
|
2217
|
+
if (portNumber === undefined) {
|
|
2218
|
+
return state;
|
|
2219
|
+
}
|
|
2220
|
+
const port = ports.find(item => item.port === portNumber);
|
|
2221
|
+
if (!port?.forwardedAddress) {
|
|
2222
|
+
return state;
|
|
2223
|
+
}
|
|
2224
|
+
await show2(uid, PortsTable$1, clientX, clientY, {
|
|
2225
|
+
href: getAddressUrl(port.forwardedAddress),
|
|
2226
|
+
menuId: PortsTable$1
|
|
2227
|
+
});
|
|
2228
|
+
return state;
|
|
2229
|
+
};
|
|
2230
|
+
|
|
2111
2231
|
const handleFocus = state => {
|
|
2112
2232
|
return {
|
|
2113
2233
|
...state,
|
|
@@ -2260,6 +2380,7 @@ const HandleFocus = 6;
|
|
|
2260
2380
|
const HandleStartAddPort = 7;
|
|
2261
2381
|
const HandleSubmitAddPort = 8;
|
|
2262
2382
|
const HandleWheel = 9;
|
|
2383
|
+
const HandleContextMenu = 10;
|
|
2263
2384
|
|
|
2264
2385
|
const errorMessage = {
|
|
2265
2386
|
childCount: 1,
|
|
@@ -2496,6 +2617,7 @@ const getPortsVirtualDom = state => {
|
|
|
2496
2617
|
className: mergeClassNames(Viewlet, Ports),
|
|
2497
2618
|
onBlur: HandleBlur,
|
|
2498
2619
|
onClick: HandleClick,
|
|
2620
|
+
onContextMenu: HandleContextMenu,
|
|
2499
2621
|
onFocus: HandleFocus,
|
|
2500
2622
|
onWheel: HandleWheel,
|
|
2501
2623
|
role: Table,
|
|
@@ -2560,6 +2682,10 @@ const renderEventListeners = () => {
|
|
|
2560
2682
|
}, {
|
|
2561
2683
|
name: HandleClick,
|
|
2562
2684
|
params: ['handleClick', ClientY, TargetName]
|
|
2685
|
+
}, {
|
|
2686
|
+
name: HandleContextMenu,
|
|
2687
|
+
params: ['handleContextMenu', ClientX, ClientY, TargetName],
|
|
2688
|
+
preventDefault: true
|
|
2563
2689
|
}, {
|
|
2564
2690
|
name: HandleFocus,
|
|
2565
2691
|
params: ['handleFocus']
|
|
@@ -2616,6 +2742,7 @@ const toggleFocusedPort = state => {
|
|
|
2616
2742
|
const commandMap = {
|
|
2617
2743
|
'Ports.addPort': wrapCommand(addPort),
|
|
2618
2744
|
'Ports.cancelAddPort': wrapCommand(cancelAddPort),
|
|
2745
|
+
'Ports.copyLink': wrapCommand(copyLink),
|
|
2619
2746
|
'Ports.create': create,
|
|
2620
2747
|
'Ports.diff2': diff2,
|
|
2621
2748
|
'Ports.dispose': dispose,
|
|
@@ -2627,10 +2754,13 @@ const commandMap = {
|
|
|
2627
2754
|
'Ports.getCommandIds': getCommandIds,
|
|
2628
2755
|
'Ports.getComponentState': getComponentState,
|
|
2629
2756
|
'Ports.getKeyBindings': getKeyBindings,
|
|
2757
|
+
'Ports.getMenuEntries2': wrapGetter(getMenuEntries2),
|
|
2758
|
+
'Ports.getMenuIds': getMenuIds,
|
|
2630
2759
|
'Ports.handleAddPortInput': wrapCommand(handleAddPortInput),
|
|
2631
2760
|
'Ports.handleAddPortKeyDown': wrapCommand(handleAddPortKeyDown),
|
|
2632
2761
|
'Ports.handleBlur': wrapCommand(handleBlur),
|
|
2633
2762
|
'Ports.handleClick': wrapCommand(handleClick),
|
|
2763
|
+
'Ports.handleContextMenu': wrapCommand(handleContextMenu),
|
|
2634
2764
|
'Ports.handleFocus': wrapCommand(handleFocus),
|
|
2635
2765
|
'Ports.handleWheel': wrapCommand(handleWheel),
|
|
2636
2766
|
'Ports.handleWorkspaceChange': wrapCommand(loadContent),
|