@lvce-editor/output-view 1.9.0 → 1.10.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.
@@ -54,6 +54,49 @@ class VError extends Error {
54
54
  }
55
55
  }
56
56
 
57
+ class AssertionError extends Error {
58
+ constructor(message) {
59
+ super(message);
60
+ this.name = 'AssertionError';
61
+ }
62
+ }
63
+ const Object$1 = 1;
64
+ const Number$1 = 2;
65
+ const Array$1 = 3;
66
+ const String = 4;
67
+ const Boolean$1 = 5;
68
+ const Function = 6;
69
+ const Null = 7;
70
+ const Unknown = 8;
71
+ const getType = value => {
72
+ switch (typeof value) {
73
+ case 'number':
74
+ return Number$1;
75
+ case 'function':
76
+ return Function;
77
+ case 'string':
78
+ return String;
79
+ case 'object':
80
+ if (value === null) {
81
+ return Null;
82
+ }
83
+ if (Array.isArray(value)) {
84
+ return Array$1;
85
+ }
86
+ return Object$1;
87
+ case 'boolean':
88
+ return Boolean$1;
89
+ default:
90
+ return Unknown;
91
+ }
92
+ };
93
+ const number = value => {
94
+ const type = getType(value);
95
+ if (type !== Number$1) {
96
+ throw new AssertionError('expected value to be of type number');
97
+ }
98
+ };
99
+
57
100
  const isMessagePort = value => {
58
101
  return value && value instanceof MessagePort;
59
102
  };
@@ -478,7 +521,7 @@ const set$5 = (id, fn) => {
478
521
  const get$2 = id => {
479
522
  return callbacks[id];
480
523
  };
481
- const remove = id => {
524
+ const remove$1 = id => {
482
525
  delete callbacks[id];
483
526
  };
484
527
  let id = 0;
@@ -663,7 +706,7 @@ const resolve = (id, response) => {
663
706
  return;
664
707
  }
665
708
  fn(response);
666
- remove(id);
709
+ remove$1(id);
667
710
  };
668
711
  const E_COMMAND_NOT_FOUND = 'E_COMMAND_NOT_FOUND';
669
712
  const getErrorType = prettyError => {
@@ -1066,9 +1109,11 @@ const {
1066
1109
  wrapGetter
1067
1110
  } = create$2();
1068
1111
 
1069
- const create$1 = (id, uri, x, y, width, height, platform) => {
1112
+ const create$1 = (id, uri, x, y, width, height, platform, parentId) => {
1113
+ number(parentId);
1070
1114
  const state = {
1071
1115
  uid: id,
1116
+ parentId,
1072
1117
  uri,
1073
1118
  focusedIndex: -2,
1074
1119
  message: '',
@@ -1096,19 +1141,24 @@ const create$1 = (id, uri, x, y, width, height, platform) => {
1096
1141
  set$4(id, state, state);
1097
1142
  };
1098
1143
 
1099
- const isEqual$1 = (oldState, newState) => {
1144
+ const isEqual$2 = (oldState, newState) => {
1100
1145
  return newState.inputSource === User || oldState.filterValue === newState.filterValue;
1101
1146
  };
1102
1147
 
1148
+ const isEqual$1 = (oldState, newState) => {
1149
+ return oldState.selectedOption === newState.selectedOption;
1150
+ };
1151
+
1103
1152
  const isEqual = (oldState, newState) => {
1104
- return oldState.filterValue === newState.filterValue && oldState.message === newState.message && oldState.options === newState.options && oldState.listItems === newState.listItems;
1153
+ return oldState.selectedOption === newState.selectedOption;
1105
1154
  };
1106
1155
 
1107
1156
  const RenderItems = 1;
1108
1157
  const RenderFilterValue = 2;
1158
+ const RenderSelectedItem = 3;
1109
1159
 
1110
- const modules = [isEqual, isEqual$1];
1111
- const numbers = [RenderItems, RenderFilterValue];
1160
+ const modules = [isEqual$1, isEqual$2, isEqual];
1161
+ const numbers = [RenderItems, RenderFilterValue, RenderSelectedItem];
1112
1162
 
1113
1163
  const diff = (oldState, newState) => {
1114
1164
  const diffResult = [];
@@ -1294,20 +1344,84 @@ const ExtensionHost = {
1294
1344
  };
1295
1345
  const {
1296
1346
  invoke: invoke$7,
1297
- set: set$7} = create(FileSystemWorker$1);
1347
+ invokeAndTransfer: invokeAndTransfer$7,
1348
+ set: set$7,
1349
+ dispose: dispose$7
1350
+ } = create(FileSystemWorker$1);
1351
+ const remove = async dirent => {
1352
+ return invoke$7('FileSystem.remove', dirent);
1353
+ };
1354
+ const readDirWithFileTypes = async uri => {
1355
+ return invoke$7('FileSystem.readDirWithFileTypes', uri);
1356
+ };
1357
+ const getPathSeparator = async root => {
1358
+ // @ts-ignore
1359
+ return invoke$7('FileSystem.getPathSeparator', root);
1360
+ };
1361
+ const getRealPath = async path => {
1362
+ return invoke$7('FileSystem.getRealPath', path);
1363
+ };
1364
+ const stat = async dirent => {
1365
+ return invoke$7('FileSystem.stat', dirent);
1366
+ };
1367
+ const createFile = async uri => {
1368
+ return invoke$7('FileSystem.writeFile', uri, '');
1369
+ };
1298
1370
  const readFile$1 = async uri => {
1299
1371
  return invoke$7('FileSystem.readFile', uri);
1300
1372
  };
1301
1373
  const writeFile$1 = async (uri, content) => {
1302
1374
  return invoke$7('FileSystem.writeFile', uri, content);
1303
1375
  };
1376
+ const mkdir = async uri => {
1377
+ return invoke$7('FileSystem.mkdir', uri);
1378
+ };
1379
+ const rename = async (oldUri, newUri) => {
1380
+ return invoke$7('FileSystem.rename', oldUri, newUri);
1381
+ };
1382
+ const copy = async (oldUri, newUri) => {
1383
+ return invoke$7('FileSystem.copy', oldUri, newUri);
1384
+ };
1385
+ const exists = async uri => {
1386
+ // @ts-ignore
1387
+ return invoke$7('FileSystem.exists', uri);
1388
+ };
1389
+ const getFolderSize$1 = async uri => {
1390
+ // @ts-ignore
1391
+ return invoke$7('FileSystem.getFolderSize', uri);
1392
+ };
1393
+ const readFileAsBlob = async uri => {
1394
+ // @ts-ignore
1395
+ return invoke$7('FileSystem.readFileAsBlob', uri);
1396
+ };
1397
+ const appendFile = async (uri, text) => {
1398
+ // @ts-ignore
1399
+ return invoke$7('FileSystem.appendFile', uri, text);
1400
+ };
1304
1401
  const FileSystemWorker = {
1305
1402
  __proto__: null,
1403
+ appendFile,
1404
+ copy,
1405
+ createFile,
1406
+ dispose: dispose$7,
1407
+ exists,
1408
+ getFolderSize: getFolderSize$1,
1409
+ getPathSeparator,
1410
+ getRealPath,
1411
+ invoke: invoke$7,
1412
+ invokeAndTransfer: invokeAndTransfer$7,
1413
+ mkdir,
1414
+ readDirWithFileTypes,
1306
1415
  readFile: readFile$1,
1416
+ readFileAsBlob,
1417
+ remove,
1418
+ rename,
1307
1419
  set: set$7,
1420
+ stat,
1308
1421
  writeFile: writeFile$1
1309
1422
  };
1310
1423
  const {
1424
+ invoke: invoke$3,
1311
1425
  invokeAndTransfer: invokeAndTransfer$3,
1312
1426
  set: set$3} = create(RendererWorker$1);
1313
1427
  const sendMessagePortToFileSystemWorker$2 = async (port, rpcId) => {
@@ -1319,8 +1433,12 @@ const sendMessagePortToExtensionHostWorker$1 = async (port, rpcId = 0) => {
1319
1433
  const command = 'HandleMessagePort.handleMessagePort2';
1320
1434
  await invokeAndTransfer$3('SendMessagePortToExtensionHostWorker.sendMessagePortToExtensionHostWorker', port, command, rpcId);
1321
1435
  };
1436
+ const activateByEvent$1 = event => {
1437
+ return invoke$3('ExtensionHostManagement.activateByEvent', event);
1438
+ };
1322
1439
  const RendererWorker = {
1323
1440
  __proto__: null,
1441
+ activateByEvent: activateByEvent$1,
1324
1442
  sendMessagePortToExtensionHostWorker: sendMessagePortToExtensionHostWorker$1,
1325
1443
  sendMessagePortToFileSystemWorker: sendMessagePortToFileSystemWorker$2,
1326
1444
  set: set$3};
@@ -1445,7 +1563,7 @@ const handleFilterInput = async (state, value) => {
1445
1563
  };
1446
1564
  };
1447
1565
 
1448
- const handleSelect = async (state, id) => {
1566
+ const selectChannel = async (state, id) => {
1449
1567
  const {
1450
1568
  options
1451
1569
  } = state;
@@ -1461,16 +1579,23 @@ const handleSelect = async (state, id) => {
1461
1579
  } = await loadLines(matchingOption.uri);
1462
1580
  return {
1463
1581
  ...state,
1464
- listItems: lines,
1465
1582
  error,
1466
- errorCode: code
1583
+ errorCode: code,
1584
+ listItems: lines,
1585
+ selectedOption: id
1467
1586
  };
1468
1587
  };
1469
1588
 
1589
+ const handleSelect = async (state, id) => {
1590
+ return selectChannel(state, id);
1591
+ };
1592
+
1470
1593
  const {
1471
1594
  sendMessagePortToExtensionHostWorker,
1472
1595
  sendMessagePortToFileSystemWorker: sendMessagePortToFileSystemWorker$1,
1473
- set: set$1} = RendererWorker;
1596
+ set: set$1,
1597
+ activateByEvent
1598
+ } = RendererWorker;
1474
1599
 
1475
1600
  const sendMessagePortToExtensionHostWorker2 = async port => {
1476
1601
  await sendMessagePortToExtensionHostWorker(port);
@@ -1547,17 +1672,25 @@ const loadButtons = () => {
1547
1672
  }];
1548
1673
  };
1549
1674
 
1675
+ const error = error => {
1676
+ console.error(error);
1677
+ };
1678
+
1550
1679
  const getExtensionOptions = async () => {
1551
1680
  try {
1681
+ // TODO make api more declarative:
1682
+ // output channels are registered in extension manifest
1683
+ // only downside: it might show channels for extensions that are not active
1684
+ await activateByEvent('onOutput');
1552
1685
  // @ts-ignore
1553
- const channels = await invoke('ExtensionHost.getOutputChannels');
1686
+ const channels = await invoke('Output.getEnabledProviders');
1554
1687
  return channels;
1555
- } catch {
1688
+ } catch (error$1) {
1689
+ error(error$1);
1556
1690
  return [];
1557
1691
  }
1558
1692
  };
1559
1693
 
1560
- // TODO load options from extensions
1561
1694
  const loadOptions = async platform => {
1562
1695
  const extensionOptions = await getExtensionOptions();
1563
1696
  if (platform === Web) {
@@ -1574,6 +1707,28 @@ const loadOptions = async platform => {
1574
1707
  }, ...extensionOptions];
1575
1708
  };
1576
1709
 
1710
+ const watchCallbacks = Object.create(null);
1711
+ const registerWatchCallback = (id, fn) => {
1712
+ watchCallbacks[id] = fn;
1713
+ };
1714
+ const executeWatchCallBack = id => {
1715
+ watchCallbacks[id]();
1716
+ };
1717
+
1718
+ const setupChangeListener = async uri => {
1719
+ try {
1720
+ const watchId = Math.random();
1721
+ registerWatchCallback(watchId, () => {
1722
+ // TODO
1723
+ // console.log('channel changed')
1724
+ });
1725
+ // @ts-ignore
1726
+ await FileSystemWorker.invoke(/* OutputChannel.open */'FileSystem.watchFile', watchId, /* path */uri);
1727
+ } catch {
1728
+ // ignore
1729
+ }
1730
+ };
1731
+
1577
1732
  const isString = value => {
1578
1733
  return typeof value === 'string';
1579
1734
  };
@@ -1605,6 +1760,7 @@ const loadContent = async (state, savedState) => {
1605
1760
  error,
1606
1761
  code
1607
1762
  } = await loadLines(uri);
1763
+ await setupChangeListener(uri);
1608
1764
  const buttons = loadButtons();
1609
1765
  return {
1610
1766
  ...state,
@@ -1769,12 +1925,20 @@ const renderItems = (oldState, newState) => {
1769
1925
  return ['Viewlet.setDom2', dom];
1770
1926
  };
1771
1927
 
1928
+ const renderSelectedItem = (oldState, newState) => {
1929
+ const value = newState.selectedOption;
1930
+ const name = Output$2;
1931
+ return ['Viewlet.setValueByName', newState.parentId, name, value];
1932
+ };
1933
+
1772
1934
  const getRenderer = diffType => {
1773
1935
  switch (diffType) {
1774
1936
  case RenderItems:
1775
1937
  return renderItems;
1776
1938
  case RenderFilterValue:
1777
1939
  return renderFilterValue;
1940
+ case RenderSelectedItem:
1941
+ return renderSelectedItem;
1778
1942
  default:
1779
1943
  throw new Error('unknown renderer');
1780
1944
  }
@@ -1948,11 +2112,17 @@ const commandMap = {
1948
2112
  'Output.closeFindWidget': wrapCommand(closeFindWidget),
1949
2113
  'Output.create': create$1,
1950
2114
  'Output.diff2': diff2,
2115
+ 'Output.executeWatchCallback': executeWatchCallBack,
1951
2116
  'Output.focusIndex': wrapCommand(focusIndex),
2117
+ 'Output.getActions': getActions,
1952
2118
  'Output.getCommandIds': getCommandIds,
1953
2119
  'Output.getKeyBindings': getKeyBindings,
2120
+ 'Output.handleButtonClick': wrapCommand(handleButtonClick),
1954
2121
  'Output.handleData': wrapCommand(handleData),
1955
2122
  'Output.handleError': wrapCommand(handleError),
2123
+ 'Output.selectChannel': wrapCommand(selectChannel),
2124
+ 'Output.handleFilterInput': wrapCommand(handleFilterInput),
2125
+ 'Output.handleSelect': wrapCommand(handleSelect),
1956
2126
  'Output.initialize': initialize,
1957
2127
  'Output.loadContent2': wrapCommand(loadContent),
1958
2128
  'Output.openFindWidget': wrapCommand(openFindWidget),
@@ -1962,11 +2132,7 @@ const commandMap = {
1962
2132
  'Output.resize': resize,
1963
2133
  'Output.saveState': saveState,
1964
2134
  'Output.setOutputChannel': wrapCommand(setOutputChannel),
1965
- 'Output.getActions': getActions,
1966
- 'Output.terminate': terminate,
1967
- 'Output.handleSelect': wrapCommand(handleSelect),
1968
- 'Output.handleFilterInput': wrapCommand(handleFilterInput),
1969
- 'Output.handleButtonClick': wrapCommand(handleButtonClick)
2135
+ 'Output.terminate': terminate
1970
2136
  };
1971
2137
 
1972
2138
  const listen = async () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/output-view",
3
- "version": "1.9.0",
3
+ "version": "1.10.0",
4
4
  "description": "Output View Worker",
5
5
  "repository": {
6
6
  "type": "git",