@lvce-editor/output-view 1.8.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
  };
@@ -472,13 +515,13 @@ const create$4$1 = (method, params) => {
472
515
  };
473
516
  };
474
517
  const callbacks = Object.create(null);
475
- const set$4 = (id, fn) => {
518
+ const set$5 = (id, fn) => {
476
519
  callbacks[id] = fn;
477
520
  };
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;
@@ -491,7 +534,7 @@ const registerPromise = () => {
491
534
  resolve,
492
535
  promise
493
536
  } = Promise.withResolvers();
494
- set$4(id, resolve);
537
+ set$5(id, resolve);
495
538
  return {
496
539
  id,
497
540
  promise
@@ -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 => {
@@ -836,7 +879,7 @@ const send = (transport, method, ...params) => {
836
879
  const message = create$4$1(method, params);
837
880
  transport.send(message);
838
881
  };
839
- const invoke = (ipc, method, ...params) => {
882
+ const invoke$1 = (ipc, method, ...params) => {
840
883
  return invokeHelper(ipc, method, params, false);
841
884
  };
842
885
  const invokeAndTransfer = (ipc, method, ...params) => {
@@ -875,7 +918,7 @@ const createRpc = ipc => {
875
918
  send(ipc, method, ...params);
876
919
  },
877
920
  invoke(method, ...params) {
878
- return invoke(ipc, method, ...params);
921
+ return invoke$1(ipc, method, ...params);
879
922
  },
880
923
  invokeAndTransfer(method, ...params) {
881
924
  return invokeAndTransfer(ipc, method, ...params);
@@ -1061,14 +1104,16 @@ const Script = 2;
1061
1104
 
1062
1105
  const {
1063
1106
  get: get$1,
1064
- set: set$2,
1107
+ set: set$4,
1065
1108
  wrapCommand,
1066
1109
  wrapGetter
1067
1110
  } = create$2();
1068
1111
 
1069
- const create$1 = (id, uri, x, y, width, height, workspaceUri) => {
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: '',
@@ -1085,29 +1130,35 @@ const create$1 = (id, uri, x, y, width, height, workspaceUri) => {
1085
1130
  collapsedUris: [],
1086
1131
  selectedOption: '',
1087
1132
  smallWidthBreakPoint: 650,
1088
- workspaceUri,
1133
+ workspaceUri: '',
1089
1134
  options: [],
1090
1135
  error: '',
1091
1136
  errorCode: 0,
1092
1137
  buttons: [],
1093
- filteredItems: []
1138
+ filteredItems: [],
1139
+ platform
1094
1140
  };
1095
- set$2(id, state, state);
1141
+ set$4(id, state, state);
1096
1142
  };
1097
1143
 
1098
- const isEqual$1 = (oldState, newState) => {
1144
+ const isEqual$2 = (oldState, newState) => {
1099
1145
  return newState.inputSource === User || oldState.filterValue === newState.filterValue;
1100
1146
  };
1101
1147
 
1148
+ const isEqual$1 = (oldState, newState) => {
1149
+ return oldState.selectedOption === newState.selectedOption;
1150
+ };
1151
+
1102
1152
  const isEqual = (oldState, newState) => {
1103
- return oldState.filterValue === newState.filterValue && oldState.message === newState.message && oldState.options === newState.options && oldState.listItems === newState.listItems;
1153
+ return oldState.selectedOption === newState.selectedOption;
1104
1154
  };
1105
1155
 
1106
1156
  const RenderItems = 1;
1107
1157
  const RenderFilterValue = 2;
1158
+ const RenderSelectedItem = 3;
1108
1159
 
1109
- const modules = [isEqual, isEqual$1];
1110
- const numbers = [RenderItems, RenderFilterValue];
1160
+ const modules = [isEqual$1, isEqual$2, isEqual];
1161
+ const numbers = [RenderItems, RenderFilterValue, RenderSelectedItem];
1111
1162
 
1112
1163
  const diff = (oldState, newState) => {
1113
1164
  const diffResult = [];
@@ -1280,24 +1331,97 @@ const create = rpcId => {
1280
1331
  }
1281
1332
  };
1282
1333
  };
1334
+ const ExtensionHostWorker = 44;
1283
1335
  const RendererWorker$1 = 1;
1284
1336
  const FileSystemWorker$1 = 209;
1337
+ const {
1338
+ invoke: invoke$9,
1339
+ set: set$9} = create(ExtensionHostWorker);
1340
+ const ExtensionHost = {
1341
+ __proto__: null,
1342
+ invoke: invoke$9,
1343
+ set: set$9
1344
+ };
1285
1345
  const {
1286
1346
  invoke: invoke$7,
1287
- 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
+ };
1288
1370
  const readFile$1 = async uri => {
1289
1371
  return invoke$7('FileSystem.readFile', uri);
1290
1372
  };
1291
1373
  const writeFile$1 = async (uri, content) => {
1292
1374
  return invoke$7('FileSystem.writeFile', uri, content);
1293
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
+ };
1294
1401
  const FileSystemWorker = {
1295
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,
1296
1415
  readFile: readFile$1,
1416
+ readFileAsBlob,
1417
+ remove,
1418
+ rename,
1297
1419
  set: set$7,
1420
+ stat,
1298
1421
  writeFile: writeFile$1
1299
1422
  };
1300
1423
  const {
1424
+ invoke: invoke$3,
1301
1425
  invokeAndTransfer: invokeAndTransfer$3,
1302
1426
  set: set$3} = create(RendererWorker$1);
1303
1427
  const sendMessagePortToFileSystemWorker$2 = async (port, rpcId) => {
@@ -1305,13 +1429,22 @@ const sendMessagePortToFileSystemWorker$2 = async (port, rpcId) => {
1305
1429
  // @ts-ignore
1306
1430
  await invokeAndTransfer$3('SendMessagePortToExtensionHostWorker.sendMessagePortToFileSystemWorker', port, command, rpcId);
1307
1431
  };
1432
+ const sendMessagePortToExtensionHostWorker$1 = async (port, rpcId = 0) => {
1433
+ const command = 'HandleMessagePort.handleMessagePort2';
1434
+ await invokeAndTransfer$3('SendMessagePortToExtensionHostWorker.sendMessagePortToExtensionHostWorker', port, command, rpcId);
1435
+ };
1436
+ const activateByEvent$1 = event => {
1437
+ return invoke$3('ExtensionHostManagement.activateByEvent', event);
1438
+ };
1308
1439
  const RendererWorker = {
1309
1440
  __proto__: null,
1441
+ activateByEvent: activateByEvent$1,
1442
+ sendMessagePortToExtensionHostWorker: sendMessagePortToExtensionHostWorker$1,
1310
1443
  sendMessagePortToFileSystemWorker: sendMessagePortToFileSystemWorker$2,
1311
1444
  set: set$3};
1312
1445
 
1313
1446
  const {
1314
- set: set$1,
1447
+ set: set$2,
1315
1448
  readFile,
1316
1449
  writeFile
1317
1450
  } = FileSystemWorker;
@@ -1430,7 +1563,7 @@ const handleFilterInput = async (state, value) => {
1430
1563
  };
1431
1564
  };
1432
1565
 
1433
- const handleSelect = async (state, id) => {
1566
+ const selectChannel = async (state, id) => {
1434
1567
  const {
1435
1568
  options
1436
1569
  } = state;
@@ -1446,15 +1579,48 @@ const handleSelect = async (state, id) => {
1446
1579
  } = await loadLines(matchingOption.uri);
1447
1580
  return {
1448
1581
  ...state,
1449
- listItems: lines,
1450
1582
  error,
1451
- errorCode: code
1583
+ errorCode: code,
1584
+ listItems: lines,
1585
+ selectedOption: id
1452
1586
  };
1453
1587
  };
1454
1588
 
1589
+ const handleSelect = async (state, id) => {
1590
+ return selectChannel(state, id);
1591
+ };
1592
+
1455
1593
  const {
1594
+ sendMessagePortToExtensionHostWorker,
1456
1595
  sendMessagePortToFileSystemWorker: sendMessagePortToFileSystemWorker$1,
1457
- set} = RendererWorker;
1596
+ set: set$1,
1597
+ activateByEvent
1598
+ } = RendererWorker;
1599
+
1600
+ const sendMessagePortToExtensionHostWorker2 = async port => {
1601
+ await sendMessagePortToExtensionHostWorker(port);
1602
+ };
1603
+
1604
+ const createExtensionHostRpc = async () => {
1605
+ try {
1606
+ const rpc = await TransferMessagePortRpcParent.create({
1607
+ commandMap: {},
1608
+ send: sendMessagePortToExtensionHostWorker2
1609
+ });
1610
+ return rpc;
1611
+ } catch (error) {
1612
+ throw new VError(error, `Failed to create extension host rpc`);
1613
+ }
1614
+ };
1615
+
1616
+ const {
1617
+ set,
1618
+ invoke} = ExtensionHost;
1619
+
1620
+ const initializeExtensionHost = async () => {
1621
+ const extensionHostRpc = await createExtensionHostRpc();
1622
+ set(extensionHostRpc);
1623
+ };
1458
1624
 
1459
1625
  const sendMessagePortToFileSystemWorker = async port => {
1460
1626
  await sendMessagePortToFileSystemWorker$1(port, 0);
@@ -1474,14 +1640,19 @@ const createFileSystemWorkerRpc = async () => {
1474
1640
 
1475
1641
  const initializeFileSystemWorker = async () => {
1476
1642
  const rpc = await createFileSystemWorkerRpc();
1477
- set$1(rpc);
1643
+ set$2(rpc);
1478
1644
  };
1479
1645
 
1480
1646
  const initialize = async () => {
1481
- await initializeFileSystemWorker();
1647
+ await Promise.all([initializeFileSystemWorker(), initializeExtensionHost()]);
1482
1648
  };
1483
1649
 
1650
+ const Web = 1;
1651
+
1484
1652
  const getSelectedItem = platform => {
1653
+ if (platform === Web) {
1654
+ return '';
1655
+ }
1485
1656
  return MainProcess;
1486
1657
  };
1487
1658
 
@@ -1501,7 +1672,30 @@ const loadButtons = () => {
1501
1672
  }];
1502
1673
  };
1503
1674
 
1675
+ const error = error => {
1676
+ console.error(error);
1677
+ };
1678
+
1679
+ const getExtensionOptions = async () => {
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');
1685
+ // @ts-ignore
1686
+ const channels = await invoke('Output.getEnabledProviders');
1687
+ return channels;
1688
+ } catch (error$1) {
1689
+ error(error$1);
1690
+ return [];
1691
+ }
1692
+ };
1693
+
1504
1694
  const loadOptions = async platform => {
1695
+ const extensionOptions = await getExtensionOptions();
1696
+ if (platform === Web) {
1697
+ return extensionOptions;
1698
+ }
1505
1699
  return [{
1506
1700
  id: MainProcess,
1507
1701
  label: 'Main Process',
@@ -1510,7 +1704,29 @@ const loadOptions = async platform => {
1510
1704
  id: SharedProcess,
1511
1705
  label: 'Shared Process',
1512
1706
  uri: 'file:///tmp/log-shared-process.txt'
1513
- }];
1707
+ }, ...extensionOptions];
1708
+ };
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
+ }
1514
1730
  };
1515
1731
 
1516
1732
  const isString = value => {
@@ -1522,19 +1738,29 @@ const getSavedCollapsedUris = savedState => {
1522
1738
  }
1523
1739
  return [];
1524
1740
  };
1741
+ const getMatchingOpen = (options, id) => {
1742
+ return options.find(option => option.id === id) || options[0];
1743
+ };
1525
1744
  const loadContent = async (state, savedState) => {
1745
+ const {
1746
+ platform
1747
+ } = state;
1526
1748
  const collapsedUris = getSavedCollapsedUris(savedState);
1527
- const selectedId = getSelectedItem();
1528
- const options = await loadOptions();
1529
- const uri = options.find(option => option.id === selectedId)?.uri;
1530
- if (!uri) {
1749
+ const selectedId = getSelectedItem(platform);
1750
+ const options = await loadOptions(platform);
1751
+ const option = getMatchingOpen(options, selectedId);
1752
+ if (!option) {
1531
1753
  throw new Error('option not found');
1532
1754
  }
1755
+ const {
1756
+ uri
1757
+ } = option;
1533
1758
  const {
1534
1759
  lines,
1535
1760
  error,
1536
1761
  code
1537
1762
  } = await loadLines(uri);
1763
+ await setupChangeListener(uri);
1538
1764
  const buttons = loadButtons();
1539
1765
  return {
1540
1766
  ...state,
@@ -1699,12 +1925,20 @@ const renderItems = (oldState, newState) => {
1699
1925
  return ['Viewlet.setDom2', dom];
1700
1926
  };
1701
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
+
1702
1934
  const getRenderer = diffType => {
1703
1935
  switch (diffType) {
1704
1936
  case RenderItems:
1705
1937
  return renderItems;
1706
1938
  case RenderFilterValue:
1707
1939
  return renderFilterValue;
1940
+ case RenderSelectedItem:
1941
+ return renderSelectedItem;
1708
1942
  default:
1709
1943
  throw new Error('unknown renderer');
1710
1944
  }
@@ -1724,7 +1958,7 @@ const render2 = (uid, diffResult) => {
1724
1958
  oldState,
1725
1959
  newState
1726
1960
  } = get$1(uid);
1727
- set$2(uid, newState, newState);
1961
+ set$4(uid, newState, newState);
1728
1962
  const commands = applyRender(oldState, newState, diffResult);
1729
1963
  return commands;
1730
1964
  };
@@ -1878,11 +2112,17 @@ const commandMap = {
1878
2112
  'Output.closeFindWidget': wrapCommand(closeFindWidget),
1879
2113
  'Output.create': create$1,
1880
2114
  'Output.diff2': diff2,
2115
+ 'Output.executeWatchCallback': executeWatchCallBack,
1881
2116
  'Output.focusIndex': wrapCommand(focusIndex),
2117
+ 'Output.getActions': getActions,
1882
2118
  'Output.getCommandIds': getCommandIds,
1883
2119
  'Output.getKeyBindings': getKeyBindings,
2120
+ 'Output.handleButtonClick': wrapCommand(handleButtonClick),
1884
2121
  'Output.handleData': wrapCommand(handleData),
1885
2122
  'Output.handleError': wrapCommand(handleError),
2123
+ 'Output.selectChannel': wrapCommand(selectChannel),
2124
+ 'Output.handleFilterInput': wrapCommand(handleFilterInput),
2125
+ 'Output.handleSelect': wrapCommand(handleSelect),
1886
2126
  'Output.initialize': initialize,
1887
2127
  'Output.loadContent2': wrapCommand(loadContent),
1888
2128
  'Output.openFindWidget': wrapCommand(openFindWidget),
@@ -1892,11 +2132,7 @@ const commandMap = {
1892
2132
  'Output.resize': resize,
1893
2133
  'Output.saveState': saveState,
1894
2134
  'Output.setOutputChannel': wrapCommand(setOutputChannel),
1895
- 'Output.getActions': getActions,
1896
- 'Output.terminate': terminate,
1897
- 'Output.handleSelect': wrapCommand(handleSelect),
1898
- 'Output.handleFilterInput': wrapCommand(handleFilterInput),
1899
- 'Output.handleButtonClick': wrapCommand(handleButtonClick)
2135
+ 'Output.terminate': terminate
1900
2136
  };
1901
2137
 
1902
2138
  const listen = async () => {
@@ -1904,7 +2140,7 @@ const listen = async () => {
1904
2140
  const rpc = await WebWorkerRpcClient.create({
1905
2141
  commandMap: commandMapRef
1906
2142
  });
1907
- set(rpc);
2143
+ set$1(rpc);
1908
2144
  };
1909
2145
 
1910
2146
  const main = async () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/output-view",
3
- "version": "1.8.0",
3
+ "version": "1.10.0",
4
4
  "description": "Output View Worker",
5
5
  "repository": {
6
6
  "type": "git",