@lvce-editor/ports-view 0.7.1 → 0.7.3

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';
@@ -1063,13 +1064,6 @@ const showContextMenu2 = async (uid, menuId, x, y, args) => {
1063
1064
  const writeClipBoardText = async text => {
1064
1065
  await invoke('ClipBoard.writeText', /* text */text);
1065
1066
  };
1066
- const openUri = async (uri, focus, options) => {
1067
- await invoke('Main.openUri', {
1068
- ...options,
1069
- focus,
1070
- uri
1071
- });
1072
- };
1073
1067
 
1074
1068
  const toCommandId = key => {
1075
1069
  const dotIndex = key.indexOf('.');
@@ -1561,15 +1555,6 @@ const submitAddPort = state => {
1561
1555
  editing: false
1562
1556
  };
1563
1557
  };
1564
- const handleAddPortKeyDown = (state, key) => {
1565
- if (key === 'Enter') {
1566
- return submitAddPort(state);
1567
- }
1568
- if (key === 'Escape') {
1569
- return cancelAddPort(state);
1570
- }
1571
- return state;
1572
- };
1573
1558
 
1574
1559
  const copyLink = async (state, href) => {
1575
1560
  await writeClipBoardText(href);
@@ -1620,7 +1605,7 @@ const create = (uid, uri, x, y, width, height, platform, assetDir, parentUid) =>
1620
1605
  };
1621
1606
 
1622
1607
  const isFocusContextEqual = (oldState, newState) => {
1623
- return oldState.focused === newState.focused && oldState.editing === newState.editing;
1608
+ return oldState.focused === newState.focused;
1624
1609
  };
1625
1610
  const isDomEqual = (oldState, newState) => {
1626
1611
  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;
@@ -1628,18 +1613,22 @@ const isDomEqual = (oldState, newState) => {
1628
1613
  const isCssEqual = (oldState, newState) => {
1629
1614
  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;
1630
1615
  };
1616
+ const isEditingEqual = (oldState, newState) => {
1617
+ return oldState.editing === newState.editing;
1618
+ };
1631
1619
 
1632
1620
  const RenderCss = 1;
1633
1621
  const RenderDom = 2;
1634
1622
  const RenderIncremental = 3;
1635
1623
  const RenderFocusContext = 4;
1624
+ const RenderFocus = 5;
1636
1625
 
1637
1626
  const diff2 = uid => {
1638
1627
  const {
1639
1628
  oldState
1640
1629
  } = get(uid);
1641
1630
  const domDiffType = oldState.loaded ? RenderIncremental : RenderDom;
1642
- return diff(uid, [isDomEqual, isCssEqual, isFocusContextEqual], [domDiffType, RenderCss, RenderFocusContext]);
1631
+ return diff(uid, [isDomEqual, isCssEqual, isFocusContextEqual, isEditingEqual], [domDiffType, RenderCss, RenderFocusContext, RenderFocus]);
1643
1632
  };
1644
1633
 
1645
1634
  const setDeltaY = (state, deltaY) => {
@@ -2044,8 +2033,8 @@ const diffTree = (oldNodes, newNodes) => {
2044
2033
  return removeTrailingNavigationPatches(patches);
2045
2034
  };
2046
2035
 
2047
- const Empty = 0;
2048
2036
  const FocusPorts = 9000;
2037
+ const FocusPortsAddPort = 9001;
2049
2038
 
2050
2039
  const getKeyBindings = () => {
2051
2040
  return [{
@@ -2088,6 +2077,14 @@ const getKeyBindings = () => {
2088
2077
  command: 'Ports.removeFocusedPort',
2089
2078
  key: Backspace,
2090
2079
  when: FocusPorts
2080
+ }, {
2081
+ command: 'Ports.submitAddPort',
2082
+ key: Enter,
2083
+ when: FocusPortsAddPort
2084
+ }, {
2085
+ command: 'Ports.cancelAddPort',
2086
+ key: Escape,
2087
+ when: FocusPortsAddPort
2091
2088
  }];
2092
2089
  };
2093
2090
 
@@ -2152,7 +2149,9 @@ const openAddress = async (state, portNumber) => {
2152
2149
  if (!port || !port.forwardedAddress) {
2153
2150
  return state;
2154
2151
  }
2155
- await openUri(getAddressUrl(port.forwardedAddress));
2152
+ const url = getAddressUrl(port.forwardedAddress);
2153
+ await invoke('Layout.showPreview', 'simple-browser://');
2154
+ await invoke('SimpleBrowser.openOrRevealTab', url);
2156
2155
  return state;
2157
2156
  };
2158
2157
 
@@ -2372,15 +2371,14 @@ const PortsTableRowOdd = 'PortsTableRowOdd';
2372
2371
  const Viewlet = 'Viewlet';
2373
2372
 
2374
2373
  const HandleAddPortInput = 1;
2375
- const HandleAddPortKeyDown = 2;
2376
- const HandleBlur = 3;
2377
- const HandleCancelAddPort = 4;
2378
- const HandleClick = 5;
2379
- const HandleFocus = 6;
2380
- const HandleStartAddPort = 7;
2381
- const HandleSubmitAddPort = 8;
2382
- const HandleWheel = 9;
2383
- const HandleContextMenu = 10;
2374
+ const HandleBlur = 2;
2375
+ const HandleCancelAddPort = 3;
2376
+ const HandleClick = 4;
2377
+ const HandleFocus = 5;
2378
+ const HandleStartAddPort = 6;
2379
+ const HandleSubmitAddPort = 7;
2380
+ const HandleWheel = 8;
2381
+ const HandleContextMenu = 9;
2384
2382
 
2385
2383
  const errorMessage = {
2386
2384
  childCount: 1,
@@ -2408,7 +2406,6 @@ const getPortInputDom = addPortValue => {
2408
2406
  className: AddPortInput,
2409
2407
  inputMode: 'numeric',
2410
2408
  onInput: HandleAddPortInput,
2411
- onKeyDown: HandleAddPortKeyDown,
2412
2409
  placeholder: portNumber(),
2413
2410
  type: Input,
2414
2411
  value: addPortValue
@@ -2630,11 +2627,20 @@ const renderDom = (oldState, newState) => {
2630
2627
  return [SetDom2, newState.uid, getPortsVirtualDom(newState)];
2631
2628
  };
2632
2629
 
2630
+ const renderFocus = (oldState, newState) => {
2631
+ if (oldState.editing === newState.editing) {
2632
+ return [];
2633
+ }
2634
+ const selector = newState.editing ? '.AddPortInput' : '.Ports';
2635
+ return [FocusSelector, newState.uid, selector];
2636
+ };
2637
+
2633
2638
  const renderFocusContext = (oldState, newState) => {
2634
2639
  if (!newState.focused) {
2635
- return ['Viewlet.unsetAdditionalFocus', newState.uid, FocusPorts];
2640
+ const focusContext = oldState.editing ? FocusPortsAddPort : FocusPorts;
2641
+ return ['Viewlet.unsetAdditionalFocus', newState.uid, focusContext];
2636
2642
  }
2637
- return [SetFocusContext, newState.uid, newState.editing ? Empty : FocusPorts];
2643
+ return [SetFocusContext, newState.uid, newState.editing ? FocusPortsAddPort : FocusPorts];
2638
2644
  };
2639
2645
 
2640
2646
  const renderIncremental = (oldState, newState) => {
@@ -2649,6 +2655,8 @@ const getRenderer = diffType => {
2649
2655
  return renderCss;
2650
2656
  case RenderDom:
2651
2657
  return renderDom;
2658
+ case RenderFocus:
2659
+ return renderFocus;
2652
2660
  case RenderFocusContext:
2653
2661
  return renderFocusContext;
2654
2662
  case RenderIncremental:
@@ -2670,9 +2678,6 @@ const renderEventListeners = () => {
2670
2678
  return [{
2671
2679
  name: HandleAddPortInput,
2672
2680
  params: ['handleAddPortInput', TargetValue]
2673
- }, {
2674
- name: HandleAddPortKeyDown,
2675
- params: ['handleAddPortKeyDown', Key]
2676
2681
  }, {
2677
2682
  name: HandleBlur,
2678
2683
  params: ['handleBlur']
@@ -2757,7 +2762,6 @@ const commandMap = {
2757
2762
  'Ports.getMenuEntries2': wrapGetter(getMenuEntries2),
2758
2763
  'Ports.getMenuIds': getMenuIds,
2759
2764
  'Ports.handleAddPortInput': wrapCommand(handleAddPortInput),
2760
- 'Ports.handleAddPortKeyDown': wrapCommand(handleAddPortKeyDown),
2761
2765
  'Ports.handleBlur': wrapCommand(handleBlur),
2762
2766
  'Ports.handleClick': wrapCommand(handleClick),
2763
2767
  '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.1",
3
+ "version": "0.7.3",
4
4
  "description": "Ports View Worker",
5
5
  "repository": {
6
6
  "type": "git",