@lvce-editor/ports-view 0.7.2 → 0.8.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.
@@ -1024,12 +1024,12 @@ const ClientX = 'event.clientX';
1024
1024
  const ClientY = 'event.clientY';
1025
1025
  const DeltaMode = 'event.deltaMode';
1026
1026
  const DeltaY = 'event.deltaY';
1027
- const Key = 'event.key';
1028
1027
  const TargetName = 'event.target.name';
1029
1028
  const TargetValue = 'event.target.value';
1030
1029
 
1031
1030
  const Backspace = 1;
1032
1031
  const Enter = 3;
1032
+ const Escape = 8;
1033
1033
  const Space = 9;
1034
1034
  const End = 255;
1035
1035
  const Home = 12;
@@ -1044,6 +1044,7 @@ const None = 0;
1044
1044
 
1045
1045
  const RendererWorker = 1;
1046
1046
 
1047
+ const FocusSelector = 'Viewlet.focusSelector';
1047
1048
  const SetCss = 'Viewlet.setCss';
1048
1049
  const SetDom2 = 'Viewlet.setDom2';
1049
1050
  const SetFocusContext = 'Viewlet.setFocusContext';
@@ -1453,6 +1454,24 @@ const clamp = (value, minimum, maximum) => {
1453
1454
  return Math.min(Math.max(value, minimum), maximum);
1454
1455
  };
1455
1456
 
1457
+ const getVisiblePorts = state => {
1458
+ const {
1459
+ focusedIndex,
1460
+ maxLineY,
1461
+ minLineY,
1462
+ ports
1463
+ } = state;
1464
+ const visible = [];
1465
+ for (let index = minLineY; index < maxLineY; index++) {
1466
+ visible.push({
1467
+ ...ports[index],
1468
+ index,
1469
+ selected: index === focusedIndex
1470
+ });
1471
+ }
1472
+ return visible;
1473
+ };
1474
+
1456
1475
  const recalculateVirtualList = state => {
1457
1476
  const {
1458
1477
  deltaY: oldDeltaY,
@@ -1472,7 +1491,7 @@ const recalculateVirtualList = state => {
1472
1491
  const maxLineY = Math.min(ports.length, minLineY + visibleCount);
1473
1492
  const scrollBarHeight = contentHeight <= listHeight || listHeight === 0 ? 0 : Math.max(minimumScrollBarSize, listHeight * listHeight / contentHeight);
1474
1493
  const scrollBarY = finalDeltaY === 0 ? 0 : deltaY / finalDeltaY * (listHeight - scrollBarHeight);
1475
- return {
1494
+ const calculated = {
1476
1495
  ...state,
1477
1496
  deltaY,
1478
1497
  finalDeltaY,
@@ -1482,6 +1501,10 @@ const recalculateVirtualList = state => {
1482
1501
  scrollBarHeight,
1483
1502
  scrollBarY
1484
1503
  };
1504
+ return {
1505
+ ...calculated,
1506
+ visiblePorts: getVisiblePorts(calculated)
1507
+ };
1485
1508
  };
1486
1509
 
1487
1510
  const setPorts = (state, ports) => {
@@ -1554,15 +1577,6 @@ const submitAddPort = state => {
1554
1577
  editing: false
1555
1578
  };
1556
1579
  };
1557
- const handleAddPortKeyDown = (state, key) => {
1558
- if (key === 'Enter') {
1559
- return submitAddPort(state);
1560
- }
1561
- if (key === 'Escape') {
1562
- return cancelAddPort(state);
1563
- }
1564
- return state;
1565
- };
1566
1580
 
1567
1581
  const copyLink = async (state, href) => {
1568
1582
  await writeClipBoardText(href);
@@ -1604,6 +1618,7 @@ const create = (uid, uri, x, y, width, height, platform, assetDir, parentUid) =>
1604
1618
  scrollBarHeight: 0,
1605
1619
  scrollBarY: 0,
1606
1620
  uid,
1621
+ visiblePorts: [],
1607
1622
  width,
1608
1623
  x,
1609
1624
  y
@@ -1613,7 +1628,7 @@ const create = (uid, uri, x, y, width, height, platform, assetDir, parentUid) =>
1613
1628
  };
1614
1629
 
1615
1630
  const isFocusContextEqual = (oldState, newState) => {
1616
- return oldState.focused === newState.focused && oldState.editing === newState.editing;
1631
+ return oldState.focused === newState.focused;
1617
1632
  };
1618
1633
  const isDomEqual = (oldState, newState) => {
1619
1634
  return oldState.addPortError === newState.addPortError && oldState.addPortValue === newState.addPortValue && oldState.editing === newState.editing && oldState.focusedIndex === newState.focusedIndex && oldState.loaded === newState.loaded && oldState.maxLineY === newState.maxLineY && oldState.minLineY === newState.minLineY && oldState.ports === newState.ports;
@@ -1621,18 +1636,22 @@ const isDomEqual = (oldState, newState) => {
1621
1636
  const isCssEqual = (oldState, newState) => {
1622
1637
  return oldState.loaded && oldState.deltaY % oldState.itemHeight === newState.deltaY % newState.itemHeight && oldState.footerHeight === newState.footerHeight && oldState.headerHeight === newState.headerHeight && oldState.height === newState.height && oldState.itemHeight === newState.itemHeight && oldState.width === newState.width;
1623
1638
  };
1639
+ const isEditingEqual = (oldState, newState) => {
1640
+ return oldState.editing === newState.editing;
1641
+ };
1624
1642
 
1625
1643
  const RenderCss = 1;
1626
1644
  const RenderDom = 2;
1627
1645
  const RenderIncremental = 3;
1628
1646
  const RenderFocusContext = 4;
1647
+ const RenderFocus = 5;
1629
1648
 
1630
1649
  const diff2 = uid => {
1631
1650
  const {
1632
1651
  oldState
1633
1652
  } = get(uid);
1634
1653
  const domDiffType = oldState.loaded ? RenderIncremental : RenderDom;
1635
- return diff(uid, [isDomEqual, isCssEqual, isFocusContextEqual], [domDiffType, RenderCss, RenderFocusContext]);
1654
+ return diff(uid, [isDomEqual, isCssEqual, isFocusContextEqual, isEditingEqual], [domDiffType, RenderCss, RenderFocusContext, RenderFocus]);
1636
1655
  };
1637
1656
 
1638
1657
  const setDeltaY = (state, deltaY) => {
@@ -2037,8 +2056,8 @@ const diffTree = (oldNodes, newNodes) => {
2037
2056
  return removeTrailingNavigationPatches(patches);
2038
2057
  };
2039
2058
 
2040
- const Empty = 0;
2041
2059
  const FocusPorts = 9000;
2060
+ const FocusPortsAddPort = 9001;
2042
2061
 
2043
2062
  const getKeyBindings = () => {
2044
2063
  return [{
@@ -2081,6 +2100,14 @@ const getKeyBindings = () => {
2081
2100
  command: 'Ports.removeFocusedPort',
2082
2101
  key: Backspace,
2083
2102
  when: FocusPorts
2103
+ }, {
2104
+ command: 'Ports.submitAddPort',
2105
+ key: Enter,
2106
+ when: FocusPortsAddPort
2107
+ }, {
2108
+ command: 'Ports.cancelAddPort',
2109
+ key: Escape,
2110
+ when: FocusPortsAddPort
2084
2111
  }];
2085
2112
  };
2086
2113
 
@@ -2104,11 +2131,15 @@ const getMenuIds = () => {
2104
2131
  };
2105
2132
 
2106
2133
  const handleBlur = state => {
2107
- return {
2134
+ const updated = {
2108
2135
  ...state,
2109
2136
  focused: false,
2110
2137
  focusedIndex: -1
2111
2138
  };
2139
+ return {
2140
+ ...updated,
2141
+ visiblePorts: getVisiblePorts(updated)
2142
+ };
2112
2143
  };
2113
2144
 
2114
2145
  const getIndexAt = (state, clientY) => {
@@ -2155,7 +2186,7 @@ const togglePortActive = (state, portNumber) => {
2155
2186
  const {
2156
2187
  ports
2157
2188
  } = state;
2158
- return {
2189
+ const updated = {
2159
2190
  ...state,
2160
2191
  ports: ports.map(item => {
2161
2192
  if (item.port !== portNumber) {
@@ -2167,6 +2198,10 @@ const togglePortActive = (state, portNumber) => {
2167
2198
  };
2168
2199
  })
2169
2200
  };
2201
+ return {
2202
+ ...updated,
2203
+ visiblePorts: getVisiblePorts(updated)
2204
+ };
2170
2205
  };
2171
2206
 
2172
2207
  const handleClick = async (state, clientY, name) => {
@@ -2367,15 +2402,14 @@ const PortsTableRowOdd = 'PortsTableRowOdd';
2367
2402
  const Viewlet = 'Viewlet';
2368
2403
 
2369
2404
  const HandleAddPortInput = 1;
2370
- const HandleAddPortKeyDown = 2;
2371
- const HandleBlur = 3;
2372
- const HandleCancelAddPort = 4;
2373
- const HandleClick = 5;
2374
- const HandleFocus = 6;
2375
- const HandleStartAddPort = 7;
2376
- const HandleSubmitAddPort = 8;
2377
- const HandleWheel = 9;
2378
- const HandleContextMenu = 10;
2405
+ const HandleBlur = 2;
2406
+ const HandleCancelAddPort = 3;
2407
+ const HandleClick = 4;
2408
+ const HandleFocus = 5;
2409
+ const HandleStartAddPort = 6;
2410
+ const HandleSubmitAddPort = 7;
2411
+ const HandleWheel = 8;
2412
+ const HandleContextMenu = 9;
2379
2413
 
2380
2414
  const errorMessage = {
2381
2415
  childCount: 1,
@@ -2403,7 +2437,6 @@ const getPortInputDom = addPortValue => {
2403
2437
  className: AddPortInput,
2404
2438
  inputMode: 'numeric',
2405
2439
  onInput: HandleAddPortInput,
2406
- onKeyDown: HandleAddPortKeyDown,
2407
2440
  placeholder: portNumber(),
2408
2441
  type: Input,
2409
2442
  value: addPortValue
@@ -2529,24 +2562,6 @@ const getPortRowVirtualDom = port => {
2529
2562
  }, text(port.forwardedAddress), ...getTextCell(port.runningProcess), ...getTextCell(port.origin)];
2530
2563
  };
2531
2564
 
2532
- const getVisiblePorts = state => {
2533
- const {
2534
- focusedIndex,
2535
- maxLineY,
2536
- minLineY,
2537
- ports
2538
- } = state;
2539
- const visible = [];
2540
- for (let index = minLineY; index < maxLineY; index++) {
2541
- visible.push({
2542
- ...ports[index],
2543
- index,
2544
- selected: index === focusedIndex
2545
- });
2546
- }
2547
- return visible;
2548
- };
2549
-
2550
2565
  const emptyBody = {
2551
2566
  childCount: 1,
2552
2567
  className: PortsTableBody,
@@ -2562,19 +2577,19 @@ const emptyMessage = {
2562
2577
  const getPortsTableBodyVirtualDom = state => {
2563
2578
  const {
2564
2579
  loaded,
2565
- ports
2580
+ ports,
2581
+ visiblePorts
2566
2582
  } = state;
2567
2583
  if (loaded && ports.length === 0) {
2568
2584
  return [emptyBody, emptyMessage, text(noForwardedPorts())];
2569
2585
  }
2570
- const visible = getVisiblePorts(state);
2571
2586
  return [{
2572
2587
  ariaRowCount: ports.length + 1,
2573
- childCount: visible.length,
2588
+ childCount: visiblePorts.length,
2574
2589
  className: PortsTableBody,
2575
2590
  role: RowGroup,
2576
2591
  type: Div
2577
- }, ...visible.flatMap(getPortRowVirtualDom)];
2592
+ }, ...visiblePorts.flatMap(getPortRowVirtualDom)];
2578
2593
  };
2579
2594
 
2580
2595
  const headerRow = {
@@ -2625,11 +2640,20 @@ const renderDom = (oldState, newState) => {
2625
2640
  return [SetDom2, newState.uid, getPortsVirtualDom(newState)];
2626
2641
  };
2627
2642
 
2643
+ const renderFocus = (oldState, newState) => {
2644
+ if (oldState.editing === newState.editing) {
2645
+ return [];
2646
+ }
2647
+ const selector = newState.editing ? '.AddPortInput' : '.Ports';
2648
+ return [FocusSelector, newState.uid, selector];
2649
+ };
2650
+
2628
2651
  const renderFocusContext = (oldState, newState) => {
2629
2652
  if (!newState.focused) {
2630
- return ['Viewlet.unsetAdditionalFocus', newState.uid, FocusPorts];
2653
+ const focusContext = oldState.editing ? FocusPortsAddPort : FocusPorts;
2654
+ return ['Viewlet.unsetAdditionalFocus', newState.uid, focusContext];
2631
2655
  }
2632
- return [SetFocusContext, newState.uid, newState.editing ? Empty : FocusPorts];
2656
+ return [SetFocusContext, newState.uid, newState.editing ? FocusPortsAddPort : FocusPorts];
2633
2657
  };
2634
2658
 
2635
2659
  const renderIncremental = (oldState, newState) => {
@@ -2644,6 +2668,8 @@ const getRenderer = diffType => {
2644
2668
  return renderCss;
2645
2669
  case RenderDom:
2646
2670
  return renderDom;
2671
+ case RenderFocus:
2672
+ return renderFocus;
2647
2673
  case RenderFocusContext:
2648
2674
  return renderFocusContext;
2649
2675
  case RenderIncremental:
@@ -2665,9 +2691,6 @@ const renderEventListeners = () => {
2665
2691
  return [{
2666
2692
  name: HandleAddPortInput,
2667
2693
  params: ['handleAddPortInput', TargetValue]
2668
- }, {
2669
- name: HandleAddPortKeyDown,
2670
- params: ['handleAddPortKeyDown', Key]
2671
2694
  }, {
2672
2695
  name: HandleBlur,
2673
2696
  params: ['handleBlur']
@@ -2752,7 +2775,6 @@ const commandMap = {
2752
2775
  'Ports.getMenuEntries2': wrapGetter(getMenuEntries2),
2753
2776
  'Ports.getMenuIds': getMenuIds,
2754
2777
  'Ports.handleAddPortInput': wrapCommand(handleAddPortInput),
2755
- 'Ports.handleAddPortKeyDown': wrapCommand(handleAddPortKeyDown),
2756
2778
  'Ports.handleBlur': wrapCommand(handleBlur),
2757
2779
  'Ports.handleClick': wrapCommand(handleClick),
2758
2780
  'Ports.handleContextMenu': wrapCommand(handleContextMenu),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/ports-view",
3
- "version": "0.7.2",
3
+ "version": "0.8.0",
4
4
  "description": "Ports View Worker",
5
5
  "repository": {
6
6
  "type": "git",