@lvce-editor/output-view 1.3.0 → 1.5.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.
@@ -934,7 +934,8 @@ const Script = 2;
934
934
  const {
935
935
  get: get$1,
936
936
  set: set$1,
937
- wrapCommand
937
+ wrapCommand,
938
+ wrapGetter
938
939
  } = create$2();
939
940
 
940
941
  const create$1 = (id, uri, x, y, width, height, workspaceUri) => {
@@ -958,7 +959,8 @@ const create$1 = (id, uri, x, y, width, height, workspaceUri) => {
958
959
  smallWidthBreakPoint: 650,
959
960
  workspaceUri,
960
961
  options: [],
961
- error: ''
962
+ error: '',
963
+ errorCode: 0
962
964
  };
963
965
  set$1(id, state, state);
964
966
  };
@@ -1046,9 +1048,13 @@ const mergeClassNames = (...classNames) => {
1046
1048
  };
1047
1049
  const Div = 4;
1048
1050
  const Text = 12;
1051
+ const Select$2 = 63;
1052
+ const Option$1 = 64;
1049
1053
  const VirtualDomElements = {
1050
1054
  __proto__: null,
1051
- Div};
1055
+ Div,
1056
+ Option: Option$1,
1057
+ Select: Select$2};
1052
1058
  const text = data => {
1053
1059
  return {
1054
1060
  type: Text,
@@ -1121,12 +1127,6 @@ const handleError = async state => {
1121
1127
  };
1122
1128
  };
1123
1129
 
1124
- const initialize = async () => {};
1125
-
1126
- const getSelectedItem = platform => {
1127
- return 'file:///tmp/log-main-process.txt';
1128
- };
1129
-
1130
1130
  const rpcs = Object.create(null);
1131
1131
  const set$g = (id, rpc) => {
1132
1132
  rpcs[id] = rpc;
@@ -1491,6 +1491,10 @@ const RendererWorker = {
1491
1491
  writeClipBoardText
1492
1492
  };
1493
1493
 
1494
+ const isFileNotFoundError = error => {
1495
+ return error.message.includes('File not found');
1496
+ };
1497
+
1494
1498
  const loadLines = async uri => {
1495
1499
  try {
1496
1500
  // TODO use log stream, updating the output when the file is changed
@@ -1498,16 +1502,68 @@ const loadLines = async uri => {
1498
1502
  const lines = content.split('\n');
1499
1503
  return {
1500
1504
  error: '',
1501
- lines
1505
+ lines,
1506
+ code: 0
1502
1507
  };
1503
1508
  } catch (error) {
1509
+ if (isFileNotFoundError(error)) {
1510
+ return {
1511
+ error: `log file not found`,
1512
+ lines: [],
1513
+ code: 1
1514
+ };
1515
+ }
1504
1516
  return {
1505
1517
  error: `${error}`,
1506
- lines: []
1518
+ lines: [],
1519
+ code: 2
1507
1520
  };
1508
1521
  }
1509
1522
  };
1510
1523
 
1524
+ const handleSelect = async (state, id) => {
1525
+ const {
1526
+ options
1527
+ } = state;
1528
+ const matchingOption = options.find(option => option.id === id);
1529
+ if (!matchingOption) {
1530
+ return state;
1531
+ }
1532
+ // TODO potential race condtion when switching output channels fast
1533
+ const {
1534
+ lines,
1535
+ error,
1536
+ code
1537
+ } = await loadLines(matchingOption.uri);
1538
+ return {
1539
+ ...state,
1540
+ listItems: lines,
1541
+ error,
1542
+ errorCode: code
1543
+ };
1544
+ };
1545
+
1546
+ const initialize = async () => {};
1547
+
1548
+ const getSelectedItem = platform => {
1549
+ return 'file:///tmp/log-main-process.txt';
1550
+ };
1551
+
1552
+ const Filter = 'filter';
1553
+ const Output$2 = 'output';
1554
+ const MainProcess = 'MainProcess';
1555
+ const SharedProcess = 'SharedProcess';
1556
+
1557
+ const loadOptions = async platform => {
1558
+ return [{
1559
+ id: MainProcess,
1560
+ uri: 'file:///tmp/log-main-process.txt'
1561
+ }, {
1562
+ id: SharedProcess,
1563
+ uri: 'File:///tmp/log-shared-process.txt'
1564
+ }];
1565
+ };
1566
+
1511
1567
  const isString = value => {
1512
1568
  return typeof value === 'string';
1513
1569
  };
@@ -1520,18 +1576,21 @@ const getSavedCollapsedUris = savedState => {
1520
1576
  const loadContent = async (state, savedState) => {
1521
1577
  const collapsedUris = getSavedCollapsedUris(savedState);
1522
1578
  const selectedUri = getSelectedItem();
1579
+ const options = await loadOptions();
1523
1580
  const {
1524
1581
  lines,
1525
- error
1582
+ error,
1583
+ code
1526
1584
  } = await loadLines(selectedUri);
1527
1585
  return {
1528
1586
  ...state,
1587
+ collapsedUris,
1588
+ error,
1589
+ errorCode: code,
1529
1590
  inputSource: Script,
1530
1591
  listItems: lines,
1531
- collapsedUris,
1532
- options: [],
1533
- selectedOption: selectedUri,
1534
- error
1592
+ options,
1593
+ selectedOption: selectedUri
1535
1594
  };
1536
1595
  };
1537
1596
 
@@ -1543,7 +1602,7 @@ const openFindWidget = async state => {
1543
1602
  };
1544
1603
 
1545
1604
  const Button = 1;
1546
- const Select = 2;
1605
+ const Select$1 = 2;
1547
1606
 
1548
1607
  const Blank = 'Blank';
1549
1608
  const ClearAll = 'ClearAll';
@@ -1560,26 +1619,26 @@ const i18nString = (key, placeholders = emptyObject) => {
1560
1619
  return key.replaceAll(RE_PLACEHOLDER, replacer);
1561
1620
  };
1562
1621
 
1563
- /**
1564
- * @enum {string}
1565
- */
1566
- const UiStrings = {
1567
- Output: 'output',
1568
- ClearOutput: 'clear output',
1569
- TurnOffAutoScroll: 'Turn auto scrolling off',
1570
- OpenLogFile: 'open output log file'
1571
- };
1622
+ const Output$1 = 'output';
1623
+ const ClearOutput = 'clear output';
1624
+ const TurnOffAutoScroll = 'Turn auto scrolling off';
1625
+ const OpenLogFile = 'open output log file';
1626
+ const LogFileNotFound$1 = 'The log file was not found.';
1627
+
1572
1628
  const output = () => {
1573
- return i18nString(UiStrings.Output);
1629
+ return i18nString(Output$1);
1574
1630
  };
1575
1631
  const clearOutput = () => {
1576
- return i18nString(UiStrings.ClearOutput);
1632
+ return i18nString(ClearOutput);
1577
1633
  };
1578
1634
  const turnOffAutoScroll = () => {
1579
- return i18nString(UiStrings.TurnOffAutoScroll);
1635
+ return i18nString(TurnOffAutoScroll);
1580
1636
  };
1581
1637
  const openLogFile = () => {
1582
- return i18nString(UiStrings.OpenLogFile);
1638
+ return i18nString(OpenLogFile);
1639
+ };
1640
+ const logFileNotFound = () => {
1641
+ return i18nString(LogFileNotFound$1);
1583
1642
  };
1584
1643
 
1585
1644
  const toSelectOption = option => {
@@ -1593,7 +1652,7 @@ const getActions = state => {
1593
1652
  options
1594
1653
  } = state;
1595
1654
  return [{
1596
- type: Select,
1655
+ type: Select$1,
1597
1656
  id: output(),
1598
1657
  options: toSelectOptions(options)
1599
1658
  }, {
@@ -1611,8 +1670,6 @@ const getActions = state => {
1611
1670
  }];
1612
1671
  };
1613
1672
 
1614
- const Filter = 'filter';
1615
-
1616
1673
  const renderFilterValue = (oldState, newState) => {
1617
1674
  return ['Viewlet.setValueByName', Filter, newState.filterValue];
1618
1675
  };
@@ -1620,6 +1677,8 @@ const renderFilterValue = (oldState, newState) => {
1620
1677
  const Actions = 'Actions';
1621
1678
  const Viewlet = 'Viewlet';
1622
1679
  const Output = 'Output';
1680
+ const Option = 'Option';
1681
+ const Select = 'Select';
1623
1682
 
1624
1683
  const parentNode = {
1625
1684
  type: VirtualDomElements.Div,
@@ -1643,10 +1702,24 @@ const getContentDom = (lines, error) => {
1643
1702
  }, ...lines.flatMap(getLineDom)];
1644
1703
  };
1645
1704
 
1646
- const getErrorDom = error => {
1705
+ const LogFileNotFound = 1;
1706
+
1707
+ const getLogFileNotFoundDom = () => {
1708
+ return [{
1709
+ type: VirtualDomElements.Div,
1710
+ className: 'Message',
1711
+ tabIndex: 0,
1712
+ childCount: 1
1713
+ }, text(logFileNotFound())];
1714
+ };
1715
+
1716
+ const getErrorDom = (errorCode, error) => {
1647
1717
  if (!error) {
1648
1718
  return [];
1649
1719
  }
1720
+ if (errorCode === LogFileNotFound) {
1721
+ return getLogFileNotFoundDom();
1722
+ }
1650
1723
  return [{
1651
1724
  type: VirtualDomElements.Div,
1652
1725
  className: 'Error',
@@ -1655,16 +1728,16 @@ const getErrorDom = error => {
1655
1728
  }, text(error)];
1656
1729
  };
1657
1730
 
1658
- const getOutputVirtualDom = (lines, error) => {
1731
+ const getOutputVirtualDom = (lines, errorCode, error) => {
1659
1732
  return [{
1660
1733
  type: VirtualDomElements.Div,
1661
1734
  className: mergeClassNames(Viewlet, Output),
1662
1735
  childCount: 1
1663
- }, ...getContentDom(lines, error), ...getErrorDom(error)];
1736
+ }, ...getContentDom(lines, error), ...getErrorDom(errorCode, error)];
1664
1737
  };
1665
1738
 
1666
1739
  const renderItems = (oldState, newState) => {
1667
- const dom = getOutputVirtualDom(newState.listItems, newState.error);
1740
+ const dom = getOutputVirtualDom(newState.listItems, newState.errorCode, newState.error);
1668
1741
  return ['Viewlet.setDom2', dom];
1669
1742
  };
1670
1743
 
@@ -1698,31 +1771,55 @@ const render2 = (uid, diffResult) => {
1698
1771
  return commands;
1699
1772
  };
1700
1773
 
1701
- const getActionsVirtualDom = actions => {
1774
+ const HandleBlur = 'handleBlur';
1775
+ const HandleClearFilterClick = 'handleClearFilterClick';
1776
+ const HandleContextMenu = 'handleContextMenu';
1777
+ const HandleFilterInput = 'handleFilterInput';
1778
+ const HandlePointerDown = 'handlePointerDown';
1779
+ const HandleSelect = 'handleSelect';
1780
+
1781
+ const getOptionVirtualDom = option => {
1782
+ return [{
1783
+ type: VirtualDomElements.Option,
1784
+ className: Option,
1785
+ childCount: 1
1786
+ }, text(option.id)];
1787
+ };
1788
+
1789
+ const getSelectVirtualDom = options => {
1790
+ return [{
1791
+ type: VirtualDomElements.Select,
1792
+ className: Select,
1793
+ childCount: options.length,
1794
+ name: Output$2,
1795
+ onChange: HandleSelect
1796
+ }, ...options.flatMap(getOptionVirtualDom)];
1797
+ };
1798
+
1799
+ const getActionsVirtualDom = options => {
1702
1800
  return [{
1703
1801
  type: VirtualDomElements.Div,
1704
1802
  className: Actions,
1705
1803
  role: AriaRoles.ToolBar,
1706
- childCount: actions.length
1707
- }];
1804
+ childCount: 1
1805
+ }, ...getSelectVirtualDom(options)];
1708
1806
  };
1709
1807
 
1710
- const renderActions = uid => {
1711
- const actions = [];
1712
- const dom = getActionsVirtualDom(actions);
1808
+ const renderActions = state => {
1809
+ const {
1810
+ options
1811
+ } = state;
1812
+ const dom = getActionsVirtualDom(options);
1713
1813
  return dom;
1714
1814
  };
1715
1815
 
1716
- const HandleBlur = 'handleBlur';
1717
- const HandleClearFilterClick = 'handleClearFilterClick';
1718
- const HandleContextMenu = 'handleContextMenu';
1719
- const HandleFilterInput = 'handleFilterInput';
1720
- const HandlePointerDown = 'handlePointerDown';
1721
-
1722
1816
  const renderEventListeners = () => {
1723
1817
  return [{
1724
1818
  name: HandleBlur,
1725
1819
  params: ['handleBlur']
1820
+ }, {
1821
+ name: HandleSelect,
1822
+ params: ['handleSelect', 'event.target.value']
1726
1823
  }, {
1727
1824
  name: HandleContextMenu,
1728
1825
  params: ['handleContextMenu', 'event.clientX', 'event.clientY'],
@@ -1766,25 +1863,26 @@ const setOutputChannel = async state => {
1766
1863
  };
1767
1864
 
1768
1865
  const commandMap = {
1769
- 'Output.closeFindWidget': closeFindWidget,
1866
+ 'Output.closeFindWidget': wrapCommand(closeFindWidget),
1770
1867
  'Output.create': create$1,
1771
1868
  'Output.diff2': diff2,
1772
1869
  'Output.focusIndex': wrapCommand(focusIndex),
1773
1870
  'Output.getCommandIds': getCommandIds,
1774
1871
  'Output.getKeyBindings': getKeyBindings$1,
1775
- 'Output.handleData': handleData,
1776
- 'Output.handleError': handleError,
1872
+ 'Output.handleData': wrapCommand(handleData),
1873
+ 'Output.handleError': wrapCommand(handleError),
1777
1874
  'Output.initialize': initialize,
1778
1875
  'Output.loadContent2': wrapCommand(loadContent),
1779
- 'Output.openFindWidget': openFindWidget,
1876
+ 'Output.openFindWidget': wrapCommand(openFindWidget),
1780
1877
  'Output.render2': render2,
1781
- 'Output.renderActions': renderActions,
1878
+ 'Output.renderActions': wrapGetter(renderActions),
1782
1879
  'Output.renderEventListeners': renderEventListeners,
1783
1880
  'Output.resize': resize,
1784
1881
  'Output.saveState': saveState,
1785
- 'Output.setOutputChannel': setOutputChannel,
1882
+ 'Output.setOutputChannel': wrapCommand(setOutputChannel),
1786
1883
  'Output.getActions': getActions,
1787
- 'Output.terminate': terminate
1884
+ 'Output.terminate': terminate,
1885
+ 'Output.handleSelect': wrapCommand(handleSelect)
1788
1886
  };
1789
1887
 
1790
1888
  const {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/output-view",
3
- "version": "1.3.0",
3
+ "version": "1.5.0",
4
4
  "description": "Output View Worker",
5
5
  "repository": {
6
6
  "type": "git",