@lvce-editor/ports-view 0.7.0 → 0.7.2

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,12 +1053,15 @@ const {
1007
1053
  invoke,
1008
1054
  set: set$1
1009
1055
  } = create$2(RendererWorker);
1010
- const openUri = async (uri, focus, options) => {
1011
- await invoke('Main.openUri', {
1012
- ...options,
1013
- focus,
1014
- uri
1015
- });
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);
1016
1065
  };
1017
1066
 
1018
1067
  const toCommandId = key => {
@@ -1292,6 +1341,7 @@ const i18nString = (key, placeholders = emptyObject) => {
1292
1341
  const Add$1 = 'Add';
1293
1342
  const AddPort = 'Add Port';
1294
1343
  const Cancel = 'Cancel';
1344
+ const CopyLink = 'Copy Link';
1295
1345
  const EnterAPortNumberBetween1And65535 = 'Enter a port number between 1 and 65535';
1296
1346
  const ForwardedAddress = 'Forwarded Address';
1297
1347
  const NoForwardedPorts = 'No forwarded ports';
@@ -1313,6 +1363,9 @@ const addPort$1 = () => {
1313
1363
  const cancel = () => {
1314
1364
  return i18nString(Cancel);
1315
1365
  };
1366
+ const copyLink$1 = () => {
1367
+ return i18nString(CopyLink);
1368
+ };
1316
1369
  const enterAPortNumberBetween1And65535 = () => {
1317
1370
  return i18nString(EnterAPortNumberBetween1And65535);
1318
1371
  };
@@ -1511,6 +1564,11 @@ const handleAddPortKeyDown = (state, key) => {
1511
1564
  return state;
1512
1565
  };
1513
1566
 
1567
+ const copyLink = async (state, href) => {
1568
+ await writeClipBoardText(href);
1569
+ return state;
1570
+ };
1571
+
1514
1572
  const {
1515
1573
  diff,
1516
1574
  dispose,
@@ -1518,7 +1576,8 @@ const {
1518
1576
  getCommandIds,
1519
1577
  registerCommands,
1520
1578
  set,
1521
- wrapCommand
1579
+ wrapCommand,
1580
+ wrapGetter
1522
1581
  } = create$1();
1523
1582
 
1524
1583
  const create = (uid, uri, x, y, width, height, platform, assetDir, parentUid) => {
@@ -2025,6 +2084,25 @@ const getKeyBindings = () => {
2025
2084
  }];
2026
2085
  };
2027
2086
 
2087
+ const PortsTable$1 = 28;
2088
+
2089
+ const getMenuEntries2 = (_state, props) => {
2090
+ if (props.menuId !== PortsTable$1 || !props.href) {
2091
+ return [];
2092
+ }
2093
+ return [{
2094
+ args: [props.href],
2095
+ command: 'Ports.copyLink',
2096
+ flags: None,
2097
+ id: 'copyLink',
2098
+ label: copyLink$1()
2099
+ }];
2100
+ };
2101
+
2102
+ const getMenuIds = () => {
2103
+ return [PortsTable$1];
2104
+ };
2105
+
2028
2106
  const handleBlur = state => {
2029
2107
  return {
2030
2108
  ...state,
@@ -2067,7 +2145,9 @@ const openAddress = async (state, portNumber) => {
2067
2145
  if (!port || !port.forwardedAddress) {
2068
2146
  return state;
2069
2147
  }
2070
- await openUri(getAddressUrl(port.forwardedAddress));
2148
+ const url = getAddressUrl(port.forwardedAddress);
2149
+ await invoke('Layout.showPreview', 'simple-browser://');
2150
+ await invoke('SimpleBrowser.openOrRevealTab', url);
2071
2151
  return state;
2072
2152
  };
2073
2153
 
@@ -2108,6 +2188,41 @@ const handleClick = async (state, clientY, name) => {
2108
2188
  return focused;
2109
2189
  };
2110
2190
 
2191
+ const show2 = async (uid, menuId, x, y, args) => {
2192
+ await showContextMenu2(uid, menuId, x, y, args);
2193
+ };
2194
+
2195
+ const getPortNumber = (state, clientY, name) => {
2196
+ const {
2197
+ ports
2198
+ } = state;
2199
+ if (name.startsWith('port-address-') || name.startsWith('port-status-')) {
2200
+ const portNumber = Number(name.slice(name.lastIndexOf('-') + 1));
2201
+ return ports.some(port => port.port === portNumber) ? portNumber : undefined;
2202
+ }
2203
+ const index = getIndexAt(state, clientY);
2204
+ return index === -1 ? undefined : ports[index]?.port;
2205
+ };
2206
+ const handleContextMenu = async (state, clientX, clientY, name = '') => {
2207
+ const {
2208
+ ports,
2209
+ uid
2210
+ } = state;
2211
+ const portNumber = getPortNumber(state, clientY, name);
2212
+ if (portNumber === undefined) {
2213
+ return state;
2214
+ }
2215
+ const port = ports.find(item => item.port === portNumber);
2216
+ if (!port?.forwardedAddress) {
2217
+ return state;
2218
+ }
2219
+ await show2(uid, PortsTable$1, clientX, clientY, {
2220
+ href: getAddressUrl(port.forwardedAddress),
2221
+ menuId: PortsTable$1
2222
+ });
2223
+ return state;
2224
+ };
2225
+
2111
2226
  const handleFocus = state => {
2112
2227
  return {
2113
2228
  ...state,
@@ -2260,6 +2375,7 @@ const HandleFocus = 6;
2260
2375
  const HandleStartAddPort = 7;
2261
2376
  const HandleSubmitAddPort = 8;
2262
2377
  const HandleWheel = 9;
2378
+ const HandleContextMenu = 10;
2263
2379
 
2264
2380
  const errorMessage = {
2265
2381
  childCount: 1,
@@ -2496,6 +2612,7 @@ const getPortsVirtualDom = state => {
2496
2612
  className: mergeClassNames(Viewlet, Ports),
2497
2613
  onBlur: HandleBlur,
2498
2614
  onClick: HandleClick,
2615
+ onContextMenu: HandleContextMenu,
2499
2616
  onFocus: HandleFocus,
2500
2617
  onWheel: HandleWheel,
2501
2618
  role: Table,
@@ -2560,6 +2677,10 @@ const renderEventListeners = () => {
2560
2677
  }, {
2561
2678
  name: HandleClick,
2562
2679
  params: ['handleClick', ClientY, TargetName]
2680
+ }, {
2681
+ name: HandleContextMenu,
2682
+ params: ['handleContextMenu', ClientX, ClientY, TargetName],
2683
+ preventDefault: true
2563
2684
  }, {
2564
2685
  name: HandleFocus,
2565
2686
  params: ['handleFocus']
@@ -2616,6 +2737,7 @@ const toggleFocusedPort = state => {
2616
2737
  const commandMap = {
2617
2738
  'Ports.addPort': wrapCommand(addPort),
2618
2739
  'Ports.cancelAddPort': wrapCommand(cancelAddPort),
2740
+ 'Ports.copyLink': wrapCommand(copyLink),
2619
2741
  'Ports.create': create,
2620
2742
  'Ports.diff2': diff2,
2621
2743
  'Ports.dispose': dispose,
@@ -2627,10 +2749,13 @@ const commandMap = {
2627
2749
  'Ports.getCommandIds': getCommandIds,
2628
2750
  'Ports.getComponentState': getComponentState,
2629
2751
  'Ports.getKeyBindings': getKeyBindings,
2752
+ 'Ports.getMenuEntries2': wrapGetter(getMenuEntries2),
2753
+ 'Ports.getMenuIds': getMenuIds,
2630
2754
  'Ports.handleAddPortInput': wrapCommand(handleAddPortInput),
2631
2755
  'Ports.handleAddPortKeyDown': wrapCommand(handleAddPortKeyDown),
2632
2756
  'Ports.handleBlur': wrapCommand(handleBlur),
2633
2757
  'Ports.handleClick': wrapCommand(handleClick),
2758
+ 'Ports.handleContextMenu': wrapCommand(handleContextMenu),
2634
2759
  'Ports.handleFocus': wrapCommand(handleFocus),
2635
2760
  'Ports.handleWheel': wrapCommand(handleWheel),
2636
2761
  'Ports.handleWorkspaceChange': wrapCommand(loadContent),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/ports-view",
3
- "version": "0.7.0",
3
+ "version": "0.7.2",
4
4
  "description": "Ports View Worker",
5
5
  "repository": {
6
6
  "type": "git",