@lvce-editor/ports-view 0.6.3 → 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.
@@ -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,
@@ -2033,26 +2118,25 @@ const handleBlur = state => {
2033
2118
  };
2034
2119
  };
2035
2120
 
2036
- const handleClickAt = (state, clientY, name) => {
2121
+ const getIndexAt = (state, clientY) => {
2037
2122
  const {
2038
2123
  deltaY,
2039
2124
  headerHeight,
2040
2125
  itemHeight,
2126
+ listHeight,
2041
2127
  minLineY,
2042
2128
  ports,
2043
2129
  y
2044
2130
  } = state;
2045
- if (name.startsWith('port-address-') || name.startsWith('port-status-')) {
2046
- const port = Number(name.slice(name.lastIndexOf('-') + 1));
2047
- const index = ports.findIndex(item => item.port === port);
2048
- return index === -1 ? state : focusIndex(state, index);
2049
- }
2050
2131
  const relativeY = clientY - y - headerHeight;
2132
+ if (itemHeight <= 0 || relativeY < 0 || relativeY >= listHeight) {
2133
+ return -1;
2134
+ }
2051
2135
  const index = minLineY + Math.floor((relativeY + deltaY % itemHeight) / itemHeight);
2052
- if (relativeY < 0 || index < 0 || index >= ports.length) {
2053
- return state;
2136
+ if (index < 0 || index >= ports.length) {
2137
+ return -1;
2054
2138
  }
2055
- return focusIndex(state, index);
2139
+ return index;
2056
2140
  };
2057
2141
 
2058
2142
  const SchemeRegex = /^[a-z][a-z\d+.-]*:\/\//i;
@@ -2090,26 +2174,58 @@ const togglePortActive = (state, portNumber) => {
2090
2174
  };
2091
2175
  };
2092
2176
 
2093
- const parsePort = name => {
2094
- return Number(name.slice(name.lastIndexOf('-') + 1));
2095
- };
2096
2177
  const handleClick = async (state, clientY, name) => {
2097
2178
  const {
2098
2179
  ports
2099
2180
  } = state;
2181
+ const index = getIndexAt(state, clientY);
2182
+ if (index === -1) {
2183
+ return state;
2184
+ }
2185
+ const port = ports[index];
2186
+ const focused = focusIndex(state, index);
2100
2187
  if (name.startsWith('port-address-')) {
2101
- const portNumber = parsePort(name);
2102
- const index = ports.findIndex(item => item.port === portNumber);
2103
- const focused = index === -1 ? state : focusIndex(state, index);
2104
- return openAddress(focused, portNumber);
2188
+ return openAddress(focused, port.port);
2105
2189
  }
2106
2190
  if (name.startsWith('port-status-')) {
2107
- const portNumber = parsePort(name);
2108
- const index = ports.findIndex(item => item.port === portNumber);
2109
- const focused = index === -1 ? state : focusIndex(state, index);
2110
- return togglePortActive(focused, portNumber);
2191
+ return togglePortActive(focused, port.port);
2192
+ }
2193
+ return focused;
2194
+ };
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;
2111
2207
  }
2112
- return handleClickAt(state, clientY, name);
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;
2113
2229
  };
2114
2230
 
2115
2231
  const handleFocus = state => {
@@ -2264,6 +2380,7 @@ const HandleFocus = 6;
2264
2380
  const HandleStartAddPort = 7;
2265
2381
  const HandleSubmitAddPort = 8;
2266
2382
  const HandleWheel = 9;
2383
+ const HandleContextMenu = 10;
2267
2384
 
2268
2385
  const errorMessage = {
2269
2386
  childCount: 1,
@@ -2500,6 +2617,7 @@ const getPortsVirtualDom = state => {
2500
2617
  className: mergeClassNames(Viewlet, Ports),
2501
2618
  onBlur: HandleBlur,
2502
2619
  onClick: HandleClick,
2620
+ onContextMenu: HandleContextMenu,
2503
2621
  onFocus: HandleFocus,
2504
2622
  onWheel: HandleWheel,
2505
2623
  role: Table,
@@ -2564,6 +2682,10 @@ const renderEventListeners = () => {
2564
2682
  }, {
2565
2683
  name: HandleClick,
2566
2684
  params: ['handleClick', ClientY, TargetName]
2685
+ }, {
2686
+ name: HandleContextMenu,
2687
+ params: ['handleContextMenu', ClientX, ClientY, TargetName],
2688
+ preventDefault: true
2567
2689
  }, {
2568
2690
  name: HandleFocus,
2569
2691
  params: ['handleFocus']
@@ -2620,6 +2742,7 @@ const toggleFocusedPort = state => {
2620
2742
  const commandMap = {
2621
2743
  'Ports.addPort': wrapCommand(addPort),
2622
2744
  'Ports.cancelAddPort': wrapCommand(cancelAddPort),
2745
+ 'Ports.copyLink': wrapCommand(copyLink),
2623
2746
  'Ports.create': create,
2624
2747
  'Ports.diff2': diff2,
2625
2748
  'Ports.dispose': dispose,
@@ -2631,10 +2754,13 @@ const commandMap = {
2631
2754
  'Ports.getCommandIds': getCommandIds,
2632
2755
  'Ports.getComponentState': getComponentState,
2633
2756
  'Ports.getKeyBindings': getKeyBindings,
2757
+ 'Ports.getMenuEntries2': wrapGetter(getMenuEntries2),
2758
+ 'Ports.getMenuIds': getMenuIds,
2634
2759
  'Ports.handleAddPortInput': wrapCommand(handleAddPortInput),
2635
2760
  'Ports.handleAddPortKeyDown': wrapCommand(handleAddPortKeyDown),
2636
2761
  'Ports.handleBlur': wrapCommand(handleBlur),
2637
2762
  'Ports.handleClick': wrapCommand(handleClick),
2763
+ 'Ports.handleContextMenu': wrapCommand(handleContextMenu),
2638
2764
  'Ports.handleFocus': wrapCommand(handleFocus),
2639
2765
  'Ports.handleWheel': wrapCommand(handleWheel),
2640
2766
  'Ports.handleWorkspaceChange': wrapCommand(loadContent),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/ports-view",
3
- "version": "0.6.3",
3
+ "version": "0.7.1",
4
4
  "description": "Ports View Worker",
5
5
  "repository": {
6
6
  "type": "git",