@lvce-editor/output-view 1.2.0 → 1.3.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.
@@ -957,7 +957,8 @@ const create$1 = (id, uri, x, y, width, height, workspaceUri) => {
957
957
  selectedOption: '',
958
958
  smallWidthBreakPoint: 650,
959
959
  workspaceUri,
960
- options: []
960
+ options: [],
961
+ error: ''
961
962
  };
962
963
  set$1(id, state, state);
963
964
  };
@@ -1491,10 +1492,20 @@ const RendererWorker = {
1491
1492
  };
1492
1493
 
1493
1494
  const loadLines = async uri => {
1494
- // TODO use log stream, updating the output when the file is changed
1495
- const content = await RendererWorker.invoke('FileSystem.readFile', uri);
1496
- const lines = content.split('\n');
1497
- return lines;
1495
+ try {
1496
+ // TODO use log stream, updating the output when the file is changed
1497
+ const content = await RendererWorker.invoke('FileSystem.readFile', uri);
1498
+ const lines = content.split('\n');
1499
+ return {
1500
+ error: '',
1501
+ lines
1502
+ };
1503
+ } catch (error) {
1504
+ return {
1505
+ error: `${error}`,
1506
+ lines: []
1507
+ };
1508
+ }
1498
1509
  };
1499
1510
 
1500
1511
  const isString = value => {
@@ -1509,14 +1520,18 @@ const getSavedCollapsedUris = savedState => {
1509
1520
  const loadContent = async (state, savedState) => {
1510
1521
  const collapsedUris = getSavedCollapsedUris(savedState);
1511
1522
  const selectedUri = getSelectedItem();
1512
- const lines = await loadLines(selectedUri);
1523
+ const {
1524
+ lines,
1525
+ error
1526
+ } = await loadLines(selectedUri);
1513
1527
  return {
1514
1528
  ...state,
1515
1529
  inputSource: Script,
1516
1530
  listItems: lines,
1517
1531
  collapsedUris,
1518
1532
  options: [],
1519
- selectedOption: selectedUri
1533
+ selectedOption: selectedUri,
1534
+ error
1520
1535
  };
1521
1536
  };
1522
1537
 
@@ -1606,20 +1621,20 @@ const Actions = 'Actions';
1606
1621
  const Viewlet = 'Viewlet';
1607
1622
  const Output = 'Output';
1608
1623
 
1624
+ const parentNode = {
1625
+ type: VirtualDomElements.Div,
1626
+ className: 'Line',
1627
+ childCount: 1
1628
+ };
1609
1629
  const getLineDom = line => {
1610
- return [{
1611
- type: VirtualDomElements.Div,
1612
- className: 'Line',
1613
- childCount: 1
1614
- }, text(line)];
1630
+ return [parentNode, text(line)];
1615
1631
  };
1616
1632
 
1617
- const getOutputVirtualDom = lines => {
1633
+ const getContentDom = (lines, error) => {
1634
+ if (error) {
1635
+ return [];
1636
+ }
1618
1637
  return [{
1619
- type: VirtualDomElements.Div,
1620
- className: mergeClassNames(Viewlet, Output),
1621
- childCount: 1
1622
- }, {
1623
1638
  type: VirtualDomElements.Div,
1624
1639
  className: 'OutputContent',
1625
1640
  role: 'log',
@@ -1628,8 +1643,28 @@ const getOutputVirtualDom = lines => {
1628
1643
  }, ...lines.flatMap(getLineDom)];
1629
1644
  };
1630
1645
 
1646
+ const getErrorDom = error => {
1647
+ if (!error) {
1648
+ return [];
1649
+ }
1650
+ return [{
1651
+ type: VirtualDomElements.Div,
1652
+ className: 'Error',
1653
+ tabIndex: 0,
1654
+ childCount: 1
1655
+ }, text(error)];
1656
+ };
1657
+
1658
+ const getOutputVirtualDom = (lines, error) => {
1659
+ return [{
1660
+ type: VirtualDomElements.Div,
1661
+ className: mergeClassNames(Viewlet, Output),
1662
+ childCount: 1
1663
+ }, ...getContentDom(lines, error), ...getErrorDom(error)];
1664
+ };
1665
+
1631
1666
  const renderItems = (oldState, newState) => {
1632
- const dom = getOutputVirtualDom(newState.listItems);
1667
+ const dom = getOutputVirtualDom(newState.listItems, newState.error);
1633
1668
  return ['Viewlet.setDom2', dom];
1634
1669
  };
1635
1670
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/output-view",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "description": "Output View Worker",
5
5
  "repository": {
6
6
  "type": "git",