@lvce-editor/output-view 1.6.0 → 1.8.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.
@@ -368,9 +368,103 @@ const IpcChildWithModuleWorkerAndMessagePort$1 = {
368
368
  listen: listen$6,
369
369
  wrap: wrap$e
370
370
  };
371
+ const addListener = (emitter, type, callback) => {
372
+ if ('addEventListener' in emitter) {
373
+ emitter.addEventListener(type, callback);
374
+ } else {
375
+ emitter.on(type, callback);
376
+ }
377
+ };
378
+ const removeListener = (emitter, type, callback) => {
379
+ if ('removeEventListener' in emitter) {
380
+ emitter.removeEventListener(type, callback);
381
+ } else {
382
+ emitter.off(type, callback);
383
+ }
384
+ };
385
+ const getFirstEvent = (eventEmitter, eventMap) => {
386
+ const {
387
+ resolve,
388
+ promise
389
+ } = Promise.withResolvers();
390
+ const listenerMap = Object.create(null);
391
+ const cleanup = value => {
392
+ for (const event of Object.keys(eventMap)) {
393
+ removeListener(eventEmitter, event, listenerMap[event]);
394
+ }
395
+ resolve(value);
396
+ };
397
+ for (const [event, type] of Object.entries(eventMap)) {
398
+ const listener = event => {
399
+ cleanup({
400
+ type,
401
+ event
402
+ });
403
+ };
404
+ addListener(eventEmitter, event, listener);
405
+ listenerMap[event] = listener;
406
+ }
407
+ return promise;
408
+ };
409
+ const Message$1 = 3;
410
+ const create$5$1 = async ({
411
+ messagePort,
412
+ isMessagePortOpen
413
+ }) => {
414
+ if (!isMessagePort(messagePort)) {
415
+ throw new IpcError('port must be of type MessagePort');
416
+ }
417
+ if (isMessagePortOpen) {
418
+ return messagePort;
419
+ }
420
+ const eventPromise = getFirstEvent(messagePort, {
421
+ message: Message$1
422
+ });
423
+ messagePort.start();
424
+ const {
425
+ type,
426
+ event
427
+ } = await eventPromise;
428
+ if (type !== Message$1) {
429
+ throw new IpcError('Failed to wait for ipc message');
430
+ }
431
+ if (event.data !== readyMessage) {
432
+ throw new IpcError('unexpected first message');
433
+ }
434
+ return messagePort;
435
+ };
436
+ const signal$1 = messagePort => {
437
+ messagePort.start();
438
+ };
439
+ class IpcParentWithMessagePort extends Ipc {
440
+ getData = getData$2;
441
+ send(message) {
442
+ this._rawIpc.postMessage(message);
443
+ }
444
+ sendAndTransfer(message) {
445
+ const transfer = getTransferrables(message);
446
+ this._rawIpc.postMessage(message, transfer);
447
+ }
448
+ dispose() {
449
+ this._rawIpc.close();
450
+ }
451
+ onMessage(callback) {
452
+ this._rawIpc.addEventListener('message', callback);
453
+ }
454
+ onClose(callback) {}
455
+ }
456
+ const wrap$5 = messagePort => {
457
+ return new IpcParentWithMessagePort(messagePort);
458
+ };
459
+ const IpcParentWithMessagePort$1 = {
460
+ __proto__: null,
461
+ create: create$5$1,
462
+ signal: signal$1,
463
+ wrap: wrap$5
464
+ };
371
465
 
372
466
  const Two = '2.0';
373
- const create$4 = (method, params) => {
467
+ const create$4$1 = (method, params) => {
374
468
  return {
375
469
  jsonrpc: Two,
376
470
  method,
@@ -378,7 +472,7 @@ const create$4 = (method, params) => {
378
472
  };
379
473
  };
380
474
  const callbacks = Object.create(null);
381
- const set$2 = (id, fn) => {
475
+ const set$4 = (id, fn) => {
382
476
  callbacks[id] = fn;
383
477
  };
384
478
  const get$2 = id => {
@@ -397,7 +491,7 @@ const registerPromise = () => {
397
491
  resolve,
398
492
  promise
399
493
  } = Promise.withResolvers();
400
- set$2(id, resolve);
494
+ set$4(id, resolve);
401
495
  return {
402
496
  id,
403
497
  promise
@@ -625,7 +719,7 @@ const getErrorResponse = (id, error, preparePrettyError, logError) => {
625
719
  const errorProperty = getErrorProperty(error, prettyError);
626
720
  return create$1$1(id, errorProperty);
627
721
  };
628
- const create$5 = (message, result) => {
722
+ const create$6 = (message, result) => {
629
723
  return {
630
724
  jsonrpc: Two,
631
725
  id: message.id,
@@ -634,7 +728,7 @@ const create$5 = (message, result) => {
634
728
  };
635
729
  const getSuccessResponse = (message, result) => {
636
730
  const resultProperty = result ?? null;
637
- return create$5(message, resultProperty);
731
+ return create$6(message, resultProperty);
638
732
  };
639
733
  const getErrorResponseSimple = (id, error) => {
640
734
  return {
@@ -739,7 +833,7 @@ const invokeHelper = async (ipc, method, params, useSendAndTransfer) => {
739
833
  return unwrapJsonRpcResult(responseMessage);
740
834
  };
741
835
  const send = (transport, method, ...params) => {
742
- const message = create$4(method, params);
836
+ const message = create$4$1(method, params);
743
837
  transport.send(message);
744
838
  };
745
839
  const invoke = (ipc, method, ...params) => {
@@ -822,7 +916,41 @@ const listen$1 = async (module, options) => {
822
916
  const ipc = module.wrap(rawIpc);
823
917
  return ipc;
824
918
  };
919
+ const create$5 = async ({
920
+ commandMap,
921
+ messagePort
922
+ }) => {
923
+ // TODO create a commandMap per rpc instance
924
+ register(commandMap);
925
+ const rawIpc = await IpcParentWithMessagePort$1.create({
926
+ messagePort,
927
+ isMessagePortOpen: true
928
+ });
929
+ const ipc = IpcParentWithMessagePort$1.wrap(rawIpc);
930
+ handleIpc(ipc);
931
+ const rpc = createRpc(ipc);
932
+ messagePort.start();
933
+ return rpc;
934
+ };
825
935
  const create$3 = async ({
936
+ commandMap,
937
+ send
938
+ }) => {
939
+ const {
940
+ port1,
941
+ port2
942
+ } = new MessageChannel();
943
+ await send(port1);
944
+ return create$5({
945
+ commandMap,
946
+ messagePort: port2
947
+ });
948
+ };
949
+ const TransferMessagePortRpcParent = {
950
+ __proto__: null,
951
+ create: create$3
952
+ };
953
+ const create$4 = async ({
826
954
  commandMap
827
955
  }) => {
828
956
  // TODO create a commandMap per rpc instance
@@ -834,7 +962,7 @@ const create$3 = async ({
834
962
  };
835
963
  const WebWorkerRpcClient = {
836
964
  __proto__: null,
837
- create: create$3
965
+ create: create$4
838
966
  };
839
967
 
840
968
  const toCommandId$1 = key => {
@@ -933,7 +1061,7 @@ const Script = 2;
933
1061
 
934
1062
  const {
935
1063
  get: get$1,
936
- set: set$1,
1064
+ set: set$2,
937
1065
  wrapCommand,
938
1066
  wrapGetter
939
1067
  } = create$2();
@@ -960,9 +1088,11 @@ const create$1 = (id, uri, x, y, width, height, workspaceUri) => {
960
1088
  workspaceUri,
961
1089
  options: [],
962
1090
  error: '',
963
- errorCode: 0
1091
+ errorCode: 0,
1092
+ buttons: [],
1093
+ filteredItems: []
964
1094
  };
965
- set$1(id, state, state);
1095
+ set$2(id, state, state);
966
1096
  };
967
1097
 
968
1098
  const isEqual$1 = (oldState, newState) => {
@@ -1048,6 +1178,7 @@ const mergeClassNames = (...classNames) => {
1048
1178
  };
1049
1179
  const Button$1 = 1;
1050
1180
  const Div = 4;
1181
+ const Input = 6;
1051
1182
  const Text = 12;
1052
1183
  const Select$2 = 63;
1053
1184
  const Option$1 = 64;
@@ -1055,6 +1186,7 @@ const VirtualDomElements = {
1055
1186
  __proto__: null,
1056
1187
  Button: Button$1,
1057
1188
  Div,
1189
+ Input,
1058
1190
  Option: Option$1,
1059
1191
  Select: Select$2};
1060
1192
  const text = data => {
@@ -1067,7 +1199,7 @@ const text = data => {
1067
1199
 
1068
1200
  const FocusProblems = 19;
1069
1201
 
1070
- const getKeyBindings$1 = () => {
1202
+ const getKeyBindings = () => {
1071
1203
  return [{
1072
1204
  key: KeyCode.DownArrow,
1073
1205
  command: 'Problems.focusNext',
@@ -1115,20 +1247,6 @@ const getKeyBindings$1 = () => {
1115
1247
  }];
1116
1248
  };
1117
1249
 
1118
- const handleData = async state => {
1119
- // TODO
1120
- return {
1121
- ...state
1122
- };
1123
- };
1124
-
1125
- const handleError = async state => {
1126
- // TODO
1127
- return {
1128
- ...state
1129
- };
1130
- };
1131
-
1132
1250
  const rpcs = Object.create(null);
1133
1251
  const set$g = (id, rpc) => {
1134
1252
  rpcs[id] = rpc;
@@ -1162,336 +1280,41 @@ const create = rpcId => {
1162
1280
  }
1163
1281
  };
1164
1282
  };
1165
- const DebugWorker$1 = 55;
1166
1283
  const RendererWorker$1 = 1;
1284
+ const FileSystemWorker$1 = 209;
1167
1285
  const {
1168
- invoke: invoke$3,
1169
- invokeAndTransfer: invokeAndTransfer$3,
1170
- set: set$3,
1171
- dispose: dispose$3
1172
- } = create(RendererWorker$1);
1173
- const searchFileHtml = async uri => {
1174
- return invoke$3('ExtensionHost.searchFileWithHtml', uri);
1286
+ invoke: invoke$7,
1287
+ set: set$7} = create(FileSystemWorker$1);
1288
+ const readFile$1 = async uri => {
1289
+ return invoke$7('FileSystem.readFile', uri);
1175
1290
  };
1176
- const getFilePathElectron = async file => {
1177
- return invoke$3('FileSystemHandle.getFilePathElectron', file);
1291
+ const writeFile$1 = async (uri, content) => {
1292
+ return invoke$7('FileSystem.writeFile', uri, content);
1178
1293
  };
1179
- const showContextMenu = async (x, y, id, ...args) => {
1180
- return invoke$3('ContextMenu.show', x, y, id, ...args);
1181
- };
1182
- const getElectronVersion = async () => {
1183
- return invoke$3('Process.getElectronVersion');
1184
- };
1185
- const applyBulkReplacement = async bulkEdits => {
1186
- await invoke$3('BulkReplacement.applyBulkReplacement', bulkEdits);
1187
- };
1188
- const setColorTheme = async id => {
1189
- // @ts-ignore
1190
- return invoke$3(/* ColorTheme.setColorTheme */'ColorTheme.setColorTheme', /* colorThemeId */id);
1191
- };
1192
- const getNodeVersion = async () => {
1193
- return invoke$3('Process.getNodeVersion');
1194
- };
1195
- const getChromeVersion = async () => {
1196
- return invoke$3('Process.getChromeVersion');
1197
- };
1198
- const getV8Version = async () => {
1199
- return invoke$3('Process.getV8Version');
1200
- };
1201
- const getFileHandles = async fileIds => {
1202
- const files = await invoke$3('FileSystemHandle.getFileHandles', fileIds);
1203
- return files;
1204
- };
1205
- const setWorkspacePath = async path => {
1206
- await invoke$3('Workspace.setPath', path);
1207
- };
1208
- const registerWebViewInterceptor = async (id, port) => {
1209
- await invokeAndTransfer$3('WebView.registerInterceptor', id, port);
1210
- };
1211
- const unregisterWebViewInterceptor = async id => {
1212
- await invoke$3('WebView.unregisterInterceptor', id);
1213
- };
1214
- const sendMessagePortToEditorWorker = async (port, rpcId) => {
1215
- const command = 'HandleMessagePort.handleMessagePort';
1216
- // @ts-ignore
1217
- await invokeAndTransfer$3('SendMessagePortToExtensionHostWorker.sendMessagePortToEditorWorker', port, command, rpcId);
1218
- };
1219
- const sendMessagePortToErrorWorker = async (port, rpcId) => {
1220
- const command = 'HandleMessagePort.handleMessagePort';
1221
- // @ts-ignore
1222
- await invokeAndTransfer$3('SendMessagePortToExtensionHostWorker.sendMessagePortToErrorWorker', port, command, rpcId);
1223
- };
1224
- const sendMessagePortToMarkdownWorker = async (port, rpcId) => {
1225
- const command = 'Markdown.handleMessagePort';
1226
- // @ts-ignore
1227
- await invokeAndTransfer$3('SendMessagePortToExtensionHostWorker.sendMessagePortToMarkdownWorker', port, command, rpcId);
1294
+ const FileSystemWorker = {
1295
+ __proto__: null,
1296
+ readFile: readFile$1,
1297
+ set: set$7,
1298
+ writeFile: writeFile$1
1228
1299
  };
1229
- const sendMessagePortToFileSystemWorker = async (port, rpcId) => {
1300
+ const {
1301
+ invokeAndTransfer: invokeAndTransfer$3,
1302
+ set: set$3} = create(RendererWorker$1);
1303
+ const sendMessagePortToFileSystemWorker$2 = async (port, rpcId) => {
1230
1304
  const command = 'FileSystem.handleMessagePort';
1231
1305
  // @ts-ignore
1232
1306
  await invokeAndTransfer$3('SendMessagePortToExtensionHostWorker.sendMessagePortToFileSystemWorker', port, command, rpcId);
1233
1307
  };
1234
- const readFile = async uri => {
1235
- return invoke$3('FileSystem.readFile', uri);
1236
- };
1237
- const getWebViewSecret = async key => {
1238
- // @ts-ignore
1239
- return invoke$3('WebView.getSecret', key);
1240
- };
1241
- const setWebViewPort = async (uid, port, origin, portType) => {
1242
- return invokeAndTransfer$3('WebView.setPort', uid, port, origin, portType);
1243
- };
1244
- const setFocus = key => {
1245
- return invoke$3('Focus.setFocus', key);
1246
- };
1247
- const getFileIcon = async options => {
1248
- return invoke$3('IconTheme.getFileIcon', options);
1249
- };
1250
- const getColorThemeNames = async () => {
1251
- return invoke$3('ColorTheme.getColorThemeNames');
1252
- };
1253
- const disableExtension = async id => {
1254
- return invoke$3('ExtensionManagement.disable', id);
1255
- };
1256
- const enableExtension = async id => {
1257
- // @ts-ignore
1258
- return invoke$3('ExtensionManagement.enable', id);
1259
- };
1260
- const handleDebugChange = async params => {
1261
- // @ts-ignore
1262
- return invoke$3('Run And Debug.handleChange', params);
1263
- };
1264
- const getFolderIcon = async options => {
1265
- return invoke$3('IconTheme.getFolderIcon', options);
1266
- };
1267
- const closeWidget = async widgetId => {
1268
- return invoke$3('Viewlet.closeWidget', widgetId);
1269
- };
1270
- const sendMessagePortToExtensionHostWorker = async (port, rpcId = 0) => {
1271
- const command = 'HandleMessagePort.handleMessagePort2';
1272
- await invokeAndTransfer$3('SendMessagePortToExtensionHostWorker.sendMessagePortToExtensionHostWorker', port, command, rpcId);
1273
- };
1274
- const sendMessagePortToSearchProcess = async port => {
1275
- await invokeAndTransfer$3('SendMessagePortToElectron.sendMessagePortToElectron', port, 'HandleMessagePortForSearchProcess.handleMessagePortForSearchProcess');
1276
- };
1277
- const confirm = async (message, options) => {
1278
- // @ts-ignore
1279
- const result = await invoke$3('Confirmprompt.prompt', message, options);
1280
- return result;
1281
- };
1282
- const getRecentlyOpened = async () => {
1283
- return invoke$3(/* RecentlyOpened.getRecentlyOpened */'RecentlyOpened.getRecentlyOpened');
1284
- };
1285
- const getKeyBindings = async () => {
1286
- return invoke$3('KeyBindingsInitial.getKeyBindings');
1287
- };
1288
- const writeClipBoardText = async text => {
1289
- await invoke$3('ClipBoard.writeText', /* text */text);
1290
- };
1291
- const writeClipBoardImage = async blob => {
1292
- // @ts-ignore
1293
- await invoke$3('ClipBoard.writeImage', /* text */blob);
1294
- };
1295
- const searchFileMemory = async uri => {
1296
- // @ts-ignore
1297
- return invoke$3('ExtensionHost.searchFileWithMemory', uri);
1298
- };
1299
- const searchFileFetch = async uri => {
1300
- return invoke$3('ExtensionHost.searchFileWithFetch', uri);
1301
- };
1302
- const showMessageBox = async options => {
1303
- return invoke$3('ElectronDialog.showMessageBox', options);
1304
- };
1305
- const handleDebugResumed = async params => {
1306
- await invoke$3('Run And Debug.handleResumed', params);
1307
- };
1308
- const openWidget = async name => {
1309
- await invoke$3('Viewlet.openWidget', name);
1310
- };
1311
- const getIcons = async requests => {
1312
- const icons = await invoke$3('IconTheme.getIcons', requests);
1313
- return icons;
1314
- };
1315
- const activateByEvent = event => {
1316
- return invoke$3('ExtensionHostManagement.activateByEvent', event);
1317
- };
1318
- const setAdditionalFocus = focusKey => {
1319
- // @ts-ignore
1320
- return invoke$3('Focus.setAdditionalFocus', focusKey);
1321
- };
1322
- const getActiveEditorId = () => {
1323
- // @ts-ignore
1324
- return invoke$3('GetActiveEditor.getActiveEditorId');
1325
- };
1326
- const getWorkspacePath = () => {
1327
- return invoke$3('Workspace.getPath');
1328
- };
1329
- const sendMessagePortToRendererProcess = async port => {
1330
- const command = 'HandleMessagePort.handleMessagePort';
1331
- // @ts-ignore
1332
- await invokeAndTransfer$3('SendMessagePortToExtensionHostWorker.sendMessagePortToRendererProcess', port, command, DebugWorker$1);
1333
- };
1334
- const getPreference = async key => {
1335
- return await invoke$3('Preferences.get', key);
1336
- };
1337
- const getAllExtensions = async () => {
1338
- return invoke$3('ExtensionManagement.getAllExtensions');
1339
- };
1340
- const rerenderEditor = async key => {
1341
- // @ts-ignore
1342
- return invoke$3('Editor.rerender', key);
1343
- };
1344
- const handleDebugPaused = async params => {
1345
- await invoke$3('Run And Debug.handlePaused', params);
1346
- };
1347
- const openUri = async (uri, focus, options) => {
1348
- await invoke$3('Main.openUri', uri, focus, options);
1349
- };
1350
- const sendMessagePortToSyntaxHighlightingWorker = async port => {
1351
- await invokeAndTransfer$3(
1352
- // @ts-ignore
1353
- 'SendMessagePortToSyntaxHighlightingWorker.sendMessagePortToSyntaxHighlightingWorker', port, 'HandleMessagePort.handleMessagePort2');
1354
- };
1355
- const handleDebugScriptParsed = async script => {
1356
- await invoke$3('Run And Debug.handleScriptParsed', script);
1357
- };
1358
- const getWindowId = async () => {
1359
- return invoke$3('GetWindowId.getWindowId');
1360
- };
1361
- const getBlob = async uri => {
1362
- // @ts-ignore
1363
- return invoke$3('FileSystem.getBlob', uri);
1364
- };
1365
- const getExtensionCommands = async () => {
1366
- return invoke$3('ExtensionHost.getCommands');
1367
- };
1368
- const showErrorDialog = async errorInfo => {
1369
- // @ts-ignore
1370
- await invoke$3('ErrorHandling.showErrorDialog', errorInfo);
1371
- };
1372
- const getFolderSize = async uri => {
1373
- // @ts-ignore
1374
- return await invoke$3('FileSystem.getFolderSize', uri);
1375
- };
1376
- const getExtension = async id => {
1377
- // @ts-ignore
1378
- return invoke$3('ExtensionManagement.getExtension', id);
1379
- };
1380
- const getMarkdownDom = async html => {
1381
- // @ts-ignore
1382
- return invoke$3('Markdown.getVirtualDom', html);
1383
- };
1384
- const renderMarkdown = async (markdown, options) => {
1385
- // @ts-ignore
1386
- return invoke$3('Markdown.renderMarkdown', markdown, options);
1387
- };
1388
- const openNativeFolder = async uri => {
1389
- // @ts-ignore
1390
- await invoke$3('OpenNativeFolder.openNativeFolder', uri);
1391
- };
1392
- const uninstallExtension = async id => {
1393
- return invoke$3('ExtensionManagement.uninstall', id);
1394
- };
1395
- const installExtension = async id => {
1396
- // @ts-ignore
1397
- return invoke$3('ExtensionManagement.install', id);
1398
- };
1399
- const openExtensionSearch = async () => {
1400
- // @ts-ignore
1401
- return invoke$3('SideBar.openViewlet', 'Extensions');
1402
- };
1403
- const setExtensionsSearchValue = async searchValue => {
1404
- // @ts-ignore
1405
- return invoke$3('Extensions.handleInput', searchValue);
1406
- };
1407
- const openExternal = async uri => {
1408
- // @ts-ignore
1409
- await invoke$3('Open.openExternal', uri);
1410
- };
1411
- const openUrl = async uri => {
1412
- // @ts-ignore
1413
- await invoke$3('Open.openUrl', uri);
1414
- };
1415
- const getAllPreferences = async () => {
1416
- // @ts-ignore
1417
- return invoke$3('Preferences.getAll');
1418
- };
1419
1308
  const RendererWorker = {
1420
1309
  __proto__: null,
1421
- activateByEvent,
1422
- applyBulkReplacement,
1423
- closeWidget,
1424
- confirm,
1425
- disableExtension,
1426
- dispose: dispose$3,
1427
- enableExtension,
1428
- getActiveEditorId,
1429
- getAllExtensions,
1430
- getAllPreferences,
1431
- getBlob,
1432
- getChromeVersion,
1433
- getColorThemeNames,
1434
- getElectronVersion,
1435
- getExtension,
1436
- getExtensionCommands,
1437
- getFileHandles,
1438
- getFileIcon,
1439
- getFilePathElectron,
1440
- getFolderIcon,
1441
- getFolderSize,
1442
- getIcons,
1443
- getKeyBindings,
1444
- getMarkdownDom,
1445
- getNodeVersion,
1446
- getPreference,
1447
- getRecentlyOpened,
1448
- getV8Version,
1449
- getWebViewSecret,
1450
- getWindowId,
1451
- getWorkspacePath,
1452
- handleDebugChange,
1453
- handleDebugPaused,
1454
- handleDebugResumed,
1455
- handleDebugScriptParsed,
1456
- installExtension,
1457
- invoke: invoke$3,
1458
- invokeAndTransfer: invokeAndTransfer$3,
1459
- openExtensionSearch,
1460
- openExternal,
1461
- openNativeFolder,
1462
- openUri,
1463
- openUrl,
1464
- openWidget,
1310
+ sendMessagePortToFileSystemWorker: sendMessagePortToFileSystemWorker$2,
1311
+ set: set$3};
1312
+
1313
+ const {
1314
+ set: set$1,
1465
1315
  readFile,
1466
- registerWebViewInterceptor,
1467
- renderMarkdown,
1468
- rerenderEditor,
1469
- searchFileFetch,
1470
- searchFileHtml,
1471
- searchFileMemory,
1472
- sendMessagePortToEditorWorker,
1473
- sendMessagePortToErrorWorker,
1474
- sendMessagePortToExtensionHostWorker,
1475
- sendMessagePortToFileSystemWorker,
1476
- sendMessagePortToMarkdownWorker,
1477
- sendMessagePortToRendererProcess,
1478
- sendMessagePortToSearchProcess,
1479
- sendMessagePortToSyntaxHighlightingWorker,
1480
- set: set$3,
1481
- setAdditionalFocus,
1482
- setColorTheme,
1483
- setExtensionsSearchValue,
1484
- setFocus,
1485
- setWebViewPort,
1486
- setWorkspacePath,
1487
- showContextMenu,
1488
- showErrorDialog,
1489
- showMessageBox,
1490
- uninstallExtension,
1491
- unregisterWebViewInterceptor,
1492
- writeClipBoardImage,
1493
- writeClipBoardText
1494
- };
1316
+ writeFile
1317
+ } = FileSystemWorker;
1495
1318
 
1496
1319
  const isFileNotFoundError = error => {
1497
1320
  return error.message.includes('File not found');
@@ -1500,7 +1323,7 @@ const isFileNotFoundError = error => {
1500
1323
  const loadLines = async uri => {
1501
1324
  try {
1502
1325
  // TODO use log stream, updating the output when the file is changed
1503
- const content = await RendererWorker.invoke('FileSystem.readFile', uri);
1326
+ const content = await readFile(uri);
1504
1327
  const lines = content.split('\n');
1505
1328
  return {
1506
1329
  error: '',
@@ -1523,6 +1346,90 @@ const loadLines = async uri => {
1523
1346
  }
1524
1347
  };
1525
1348
 
1349
+ const clear = async state => {
1350
+ const {
1351
+ selectedOption,
1352
+ options
1353
+ } = state;
1354
+ const option = options.find(option => option.id === selectedOption);
1355
+ if (!option) {
1356
+ return state;
1357
+ }
1358
+ const {
1359
+ uri
1360
+ } = option;
1361
+ await writeFile(uri, '');
1362
+ const {
1363
+ lines,
1364
+ code,
1365
+ error
1366
+ } = await loadLines(uri);
1367
+ return {
1368
+ ...state,
1369
+ listItems: lines,
1370
+ error,
1371
+ errorCode: code
1372
+ };
1373
+ };
1374
+
1375
+ const Filter = 'filter';
1376
+ const Output$2 = 'output';
1377
+ const MainProcess = 'MainProcess';
1378
+ const SharedProcess = 'SharedProcess';
1379
+ const Clear = 'Clear';
1380
+ const Settings = 'Settings';
1381
+ const ScrollLock = 'ScrollLock';
1382
+
1383
+ const noop = async state => {
1384
+ return state;
1385
+ };
1386
+ const getClickHandler = name => {
1387
+ switch (name) {
1388
+ case Clear:
1389
+ return clear;
1390
+ default:
1391
+ return noop;
1392
+ }
1393
+ };
1394
+
1395
+ const handleButtonClick = async (state, name) => {
1396
+ const fn = getClickHandler(name);
1397
+ return fn(state);
1398
+ };
1399
+
1400
+ const handleData = async state => {
1401
+ // TODO
1402
+ return {
1403
+ ...state
1404
+ };
1405
+ };
1406
+
1407
+ const handleError = async state => {
1408
+ // TODO
1409
+ return {
1410
+ ...state
1411
+ };
1412
+ };
1413
+
1414
+ const filterItems = (items, filterValue) => {
1415
+ if (!filterValue) {
1416
+ return items;
1417
+ }
1418
+ return items.filter(item => item.includes(filterValue));
1419
+ };
1420
+
1421
+ const handleFilterInput = async (state, value) => {
1422
+ const {
1423
+ listItems
1424
+ } = state;
1425
+ const filteredItems = filterItems(listItems, value);
1426
+ return {
1427
+ ...state,
1428
+ filterValue: value,
1429
+ filteredItems: filteredItems
1430
+ };
1431
+ };
1432
+
1526
1433
  const handleSelect = async (state, id) => {
1527
1434
  const {
1528
1435
  options
@@ -1545,16 +1452,54 @@ const handleSelect = async (state, id) => {
1545
1452
  };
1546
1453
  };
1547
1454
 
1548
- const initialize = async () => {};
1455
+ const {
1456
+ sendMessagePortToFileSystemWorker: sendMessagePortToFileSystemWorker$1,
1457
+ set} = RendererWorker;
1458
+
1459
+ const sendMessagePortToFileSystemWorker = async port => {
1460
+ await sendMessagePortToFileSystemWorker$1(port, 0);
1461
+ };
1462
+
1463
+ const createFileSystemWorkerRpc = async () => {
1464
+ try {
1465
+ const rpc = await TransferMessagePortRpcParent.create({
1466
+ commandMap: {},
1467
+ send: sendMessagePortToFileSystemWorker
1468
+ });
1469
+ return rpc;
1470
+ } catch (error) {
1471
+ throw new VError(error, `Failed to create file system worker rpc`);
1472
+ }
1473
+ };
1474
+
1475
+ const initializeFileSystemWorker = async () => {
1476
+ const rpc = await createFileSystemWorkerRpc();
1477
+ set$1(rpc);
1478
+ };
1479
+
1480
+ const initialize = async () => {
1481
+ await initializeFileSystemWorker();
1482
+ };
1549
1483
 
1550
1484
  const getSelectedItem = platform => {
1551
- return 'file:///tmp/log-main-process.txt';
1485
+ return MainProcess;
1552
1486
  };
1553
1487
 
1554
- const Filter = 'filter';
1555
- const Output$2 = 'output';
1556
- const MainProcess = 'MainProcess';
1557
- const SharedProcess = 'SharedProcess';
1488
+ const loadButtons = () => {
1489
+ return [{
1490
+ id: Clear,
1491
+ label: 'Clear',
1492
+ icon: 'MaskIconClearAll'
1493
+ }, {
1494
+ id: ScrollLock,
1495
+ label: 'Scroll Lock',
1496
+ icon: 'MaskIconListFlat'
1497
+ }, {
1498
+ id: Settings,
1499
+ label: 'Settings',
1500
+ icon: 'MaskIconListFlat'
1501
+ }];
1502
+ };
1558
1503
 
1559
1504
  const loadOptions = async platform => {
1560
1505
  return [{
@@ -1579,13 +1524,18 @@ const getSavedCollapsedUris = savedState => {
1579
1524
  };
1580
1525
  const loadContent = async (state, savedState) => {
1581
1526
  const collapsedUris = getSavedCollapsedUris(savedState);
1582
- const selectedUri = getSelectedItem();
1527
+ const selectedId = getSelectedItem();
1583
1528
  const options = await loadOptions();
1529
+ const uri = options.find(option => option.id === selectedId)?.uri;
1530
+ if (!uri) {
1531
+ throw new Error('option not found');
1532
+ }
1584
1533
  const {
1585
1534
  lines,
1586
1535
  error,
1587
1536
  code
1588
- } = await loadLines(selectedUri);
1537
+ } = await loadLines(uri);
1538
+ const buttons = loadButtons();
1589
1539
  return {
1590
1540
  ...state,
1591
1541
  collapsedUris,
@@ -1593,8 +1543,10 @@ const loadContent = async (state, savedState) => {
1593
1543
  errorCode: code,
1594
1544
  inputSource: Script,
1595
1545
  listItems: lines,
1546
+ filteredItems: lines,
1596
1547
  options,
1597
- selectedOption: selectedUri
1548
+ selectedOption: selectedId,
1549
+ buttons
1598
1550
  };
1599
1551
  };
1600
1552
 
@@ -1743,7 +1695,7 @@ const getOutputVirtualDom = (lines, errorCode, error) => {
1743
1695
  };
1744
1696
 
1745
1697
  const renderItems = (oldState, newState) => {
1746
- const dom = getOutputVirtualDom(newState.listItems, newState.errorCode, newState.error);
1698
+ const dom = getOutputVirtualDom(newState.filteredItems, newState.errorCode, newState.error);
1747
1699
  return ['Viewlet.setDom2', dom];
1748
1700
  };
1749
1701
 
@@ -1772,11 +1724,19 @@ const render2 = (uid, diffResult) => {
1772
1724
  oldState,
1773
1725
  newState
1774
1726
  } = get$1(uid);
1775
- set$1(uid, newState, newState);
1727
+ set$2(uid, newState, newState);
1776
1728
  const commands = applyRender(oldState, newState, diffResult);
1777
1729
  return commands;
1778
1730
  };
1779
1731
 
1732
+ const HandleBlur = 'handleBlur';
1733
+ const HandleClearFilterClick = 'handleClearFilterClick';
1734
+ const HandleContextMenu = 'handleContextMenu';
1735
+ const HandleFilterInput = 'handleFilterInput';
1736
+ const HandlePointerDown = 'handlePointerDown';
1737
+ const HandleSelect = 'handleSelect';
1738
+ const HandleButtonClick = 'handleButtonClick';
1739
+
1780
1740
  const getActionButtonVirtualDom = button => {
1781
1741
  const {
1782
1742
  id,
@@ -1788,7 +1748,8 @@ const getActionButtonVirtualDom = button => {
1788
1748
  className: IconButton,
1789
1749
  name: id,
1790
1750
  title: label,
1791
- childCount: 1
1751
+ childCount: 1,
1752
+ onClick: HandleButtonClick
1792
1753
  }, {
1793
1754
  type: VirtualDomElements.Div,
1794
1755
  className: mergeClassNames(MaskIcon, icon)
@@ -1799,12 +1760,20 @@ const getActionButtonsVirtualDom = buttons => {
1799
1760
  return buttons.flatMap(getActionButtonVirtualDom);
1800
1761
  };
1801
1762
 
1802
- const HandleBlur = 'handleBlur';
1803
- const HandleClearFilterClick = 'handleClearFilterClick';
1804
- const HandleContextMenu = 'handleContextMenu';
1805
- const HandleFilterInput = 'handleFilterInput';
1806
- const HandlePointerDown = 'handlePointerDown';
1807
- const HandleSelect = 'handleSelect';
1763
+ const getFilterVirtualDom = () => {
1764
+ const placeholder = 'Filter';
1765
+ return [{
1766
+ type: VirtualDomElements.Div,
1767
+ className: 'Filter',
1768
+ childCount: 1
1769
+ }, {
1770
+ type: VirtualDomElements.Input,
1771
+ className: 'InputBox FilterInput',
1772
+ childCount: 0,
1773
+ placeholder,
1774
+ onInput: HandleFilterInput
1775
+ }];
1776
+ };
1808
1777
 
1809
1778
  const getOptionVirtualDom = option => {
1810
1779
  const {
@@ -1831,36 +1800,25 @@ const getSelectVirtualDom = options => {
1831
1800
 
1832
1801
  const getChildCount = buttonsLength => {
1833
1802
  const selectLength = 1;
1834
- return buttonsLength + selectLength;
1803
+ const filterCount = 1;
1804
+ return buttonsLength + filterCount + selectLength;
1835
1805
  };
1836
- const getActionsVirtualDom = options => {
1837
- const buttons = [{
1838
- id: 'Clear',
1839
- label: 'Clear',
1840
- icon: 'MaskIconClearAll'
1841
- }, {
1842
- id: 'Scroll Lock',
1843
- label: 'Scroll Lock',
1844
- icon: 'MaskIconListFlat'
1845
- }, {
1846
- id: 'Settings',
1847
- label: 'Settings',
1848
- icon: 'MaskIconListFlat'
1849
- }];
1806
+ const getActionsVirtualDom = (options, buttons) => {
1850
1807
  const childCount = getChildCount(buttons.length);
1851
1808
  return [{
1852
1809
  type: VirtualDomElements.Div,
1853
1810
  className: Actions,
1854
1811
  role: AriaRoles.ToolBar,
1855
1812
  childCount
1856
- }, ...getSelectVirtualDom(options), ...getActionButtonsVirtualDom(buttons)];
1813
+ }, ...getFilterVirtualDom(), ...getSelectVirtualDom(options), ...getActionButtonsVirtualDom(buttons)];
1857
1814
  };
1858
1815
 
1859
1816
  const renderActions = state => {
1860
1817
  const {
1861
- options
1818
+ options,
1819
+ buttons
1862
1820
  } = state;
1863
- const dom = getActionsVirtualDom(options);
1821
+ const dom = getActionsVirtualDom(options, buttons);
1864
1822
  return dom;
1865
1823
  };
1866
1824
 
@@ -1868,6 +1826,9 @@ const renderEventListeners = () => {
1868
1826
  return [{
1869
1827
  name: HandleBlur,
1870
1828
  params: ['handleBlur']
1829
+ }, {
1830
+ name: HandleButtonClick,
1831
+ params: ['handleButtonClick', 'event.target.name']
1871
1832
  }, {
1872
1833
  name: HandleSelect,
1873
1834
  params: ['handleSelect', 'event.target.value']
@@ -1919,7 +1880,7 @@ const commandMap = {
1919
1880
  'Output.diff2': diff2,
1920
1881
  'Output.focusIndex': wrapCommand(focusIndex),
1921
1882
  'Output.getCommandIds': getCommandIds,
1922
- 'Output.getKeyBindings': getKeyBindings$1,
1883
+ 'Output.getKeyBindings': getKeyBindings,
1923
1884
  'Output.handleData': wrapCommand(handleData),
1924
1885
  'Output.handleError': wrapCommand(handleError),
1925
1886
  'Output.initialize': initialize,
@@ -1933,12 +1894,11 @@ const commandMap = {
1933
1894
  'Output.setOutputChannel': wrapCommand(setOutputChannel),
1934
1895
  'Output.getActions': getActions,
1935
1896
  'Output.terminate': terminate,
1936
- 'Output.handleSelect': wrapCommand(handleSelect)
1897
+ 'Output.handleSelect': wrapCommand(handleSelect),
1898
+ 'Output.handleFilterInput': wrapCommand(handleFilterInput),
1899
+ 'Output.handleButtonClick': wrapCommand(handleButtonClick)
1937
1900
  };
1938
1901
 
1939
- const {
1940
- set} = RendererWorker;
1941
-
1942
1902
  const listen = async () => {
1943
1903
  Object.assign(commandMapRef, commandMap);
1944
1904
  const rpc = await WebWorkerRpcClient.create({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/output-view",
3
- "version": "1.6.0",
3
+ "version": "1.8.0",
4
4
  "description": "Output View Worker",
5
5
  "repository": {
6
6
  "type": "git",