@lvce-editor/ports-view 0.6.3 → 0.7.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.
@@ -2033,26 +2033,25 @@ const handleBlur = state => {
2033
2033
  };
2034
2034
  };
2035
2035
 
2036
- const handleClickAt = (state, clientY, name) => {
2036
+ const getIndexAt = (state, clientY) => {
2037
2037
  const {
2038
2038
  deltaY,
2039
2039
  headerHeight,
2040
2040
  itemHeight,
2041
+ listHeight,
2041
2042
  minLineY,
2042
2043
  ports,
2043
2044
  y
2044
2045
  } = 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
2046
  const relativeY = clientY - y - headerHeight;
2047
+ if (itemHeight <= 0 || relativeY < 0 || relativeY >= listHeight) {
2048
+ return -1;
2049
+ }
2051
2050
  const index = minLineY + Math.floor((relativeY + deltaY % itemHeight) / itemHeight);
2052
- if (relativeY < 0 || index < 0 || index >= ports.length) {
2053
- return state;
2051
+ if (index < 0 || index >= ports.length) {
2052
+ return -1;
2054
2053
  }
2055
- return focusIndex(state, index);
2054
+ return index;
2056
2055
  };
2057
2056
 
2058
2057
  const SchemeRegex = /^[a-z][a-z\d+.-]*:\/\//i;
@@ -2090,26 +2089,23 @@ const togglePortActive = (state, portNumber) => {
2090
2089
  };
2091
2090
  };
2092
2091
 
2093
- const parsePort = name => {
2094
- return Number(name.slice(name.lastIndexOf('-') + 1));
2095
- };
2096
2092
  const handleClick = async (state, clientY, name) => {
2097
2093
  const {
2098
2094
  ports
2099
2095
  } = state;
2096
+ const index = getIndexAt(state, clientY);
2097
+ if (index === -1) {
2098
+ return state;
2099
+ }
2100
+ const port = ports[index];
2101
+ const focused = focusIndex(state, index);
2100
2102
  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);
2103
+ return openAddress(focused, port.port);
2105
2104
  }
2106
2105
  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);
2106
+ return togglePortActive(focused, port.port);
2111
2107
  }
2112
- return handleClickAt(state, clientY, name);
2108
+ return focused;
2113
2109
  };
2114
2110
 
2115
2111
  const handleFocus = state => {
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.0",
4
4
  "description": "Ports View Worker",
5
5
  "repository": {
6
6
  "type": "git",