@lvce-editor/file-system-worker 1.25.0 → 2.1.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.
@@ -535,13 +535,13 @@ const create$4$1 = (method, params) => {
535
535
  };
536
536
  };
537
537
  const callbacks = Object.create(null);
538
- const set$2 = (id, fn) => {
538
+ const set$5 = (id, fn) => {
539
539
  callbacks[id] = fn;
540
540
  };
541
541
  const get$1 = id => {
542
542
  return callbacks[id];
543
543
  };
544
- const remove$2 = id => {
544
+ const remove$3 = id => {
545
545
  delete callbacks[id];
546
546
  };
547
547
  let id = 0;
@@ -554,7 +554,7 @@ const registerPromise = () => {
554
554
  resolve,
555
555
  promise
556
556
  } = Promise.withResolvers();
557
- set$2(id, resolve);
557
+ set$5(id, resolve);
558
558
  return {
559
559
  id,
560
560
  promise
@@ -726,7 +726,7 @@ const resolve = (id, response) => {
726
726
  return;
727
727
  }
728
728
  fn(response);
729
- remove$2(id);
729
+ remove$3(id);
730
730
  };
731
731
  const E_COMMAND_NOT_FOUND = 'E_COMMAND_NOT_FOUND';
732
732
  const getErrorType = prettyError => {
@@ -899,10 +899,10 @@ const send = (transport, method, ...params) => {
899
899
  const message = create$4$1(method, params);
900
900
  transport.send(message);
901
901
  };
902
- const invoke$2 = (ipc, method, ...params) => {
902
+ const invoke$4 = (ipc, method, ...params) => {
903
903
  return invokeHelper(ipc, method, params, false);
904
904
  };
905
- const invokeAndTransfer$1 = (ipc, method, ...params) => {
905
+ const invokeAndTransfer$3 = (ipc, method, ...params) => {
906
906
  return invokeHelper(ipc, method, params, true);
907
907
  };
908
908
 
@@ -938,10 +938,10 @@ const createRpc = ipc => {
938
938
  send(ipc, method, ...params);
939
939
  },
940
940
  invoke(method, ...params) {
941
- return invoke$2(ipc, method, ...params);
941
+ return invoke$4(ipc, method, ...params);
942
942
  },
943
943
  invokeAndTransfer(method, ...params) {
944
- return invokeAndTransfer$1(ipc, method, ...params);
944
+ return invokeAndTransfer$3(ipc, method, ...params);
945
945
  },
946
946
  async dispose() {
947
947
  await ipc?.dispose();
@@ -1074,8 +1074,27 @@ const WebWorkerRpcClient = {
1074
1074
  __proto__: null,
1075
1075
  create: create$3
1076
1076
  };
1077
+ const createMockRpc = ({
1078
+ commandMap
1079
+ }) => {
1080
+ const invocations = [];
1081
+ const invoke = (method, ...params) => {
1082
+ invocations.push([method, ...params]);
1083
+ const command = commandMap[method];
1084
+ if (!command) {
1085
+ throw new Error(`command ${method} not found`);
1086
+ }
1087
+ return command(...params);
1088
+ };
1089
+ const mockRpc = {
1090
+ invoke,
1091
+ invokeAndTransfer: invoke,
1092
+ invocations
1093
+ };
1094
+ return mockRpc;
1095
+ };
1077
1096
 
1078
- const readFile$3 = async uri => {
1097
+ const readFile$5 = async uri => {
1079
1098
  const response = await fetch(uri);
1080
1099
  if (!response.ok) {
1081
1100
  throw new Error(response.statusText);
@@ -1091,7 +1110,7 @@ const readFileAsBlob$1 = async uri => {
1091
1110
  const result = await response.blob();
1092
1111
  return result;
1093
1112
  };
1094
- const exists$2 = async uri => {
1113
+ const exists$3 = async uri => {
1095
1114
  const response = await fetch(uri);
1096
1115
  if (response.ok) {
1097
1116
  return true;
@@ -1107,16 +1126,19 @@ const readJson$4 = async uri => {
1107
1126
  return json;
1108
1127
  };
1109
1128
 
1129
+ const DebugWorker = 55;
1130
+ const FileSystemProcess$1 = 210;
1131
+ const FileSystemWorker = 209;
1132
+ const RendererWorker$1 = 1;
1133
+
1110
1134
  const rpcs = Object.create(null);
1111
- const set$g = (id, rpc) => {
1135
+ const set$4 = (id, rpc) => {
1112
1136
  rpcs[id] = rpc;
1113
1137
  };
1114
1138
  const get = id => {
1115
1139
  return rpcs[id];
1116
1140
  };
1117
1141
 
1118
- /* eslint-disable @typescript-eslint/explicit-function-return-type */
1119
-
1120
1142
  const create = rpcId => {
1121
1143
  return {
1122
1144
  // @ts-ignore
@@ -1132,7 +1154,7 @@ const create = rpcId => {
1132
1154
  return rpc.invokeAndTransfer(method, ...params);
1133
1155
  },
1134
1156
  set(rpc) {
1135
- set$g(rpcId, rpc);
1157
+ set$4(rpcId, rpc);
1136
1158
  },
1137
1159
  async dispose() {
1138
1160
  const rpc = get(rpcId);
@@ -1140,99 +1162,451 @@ const create = rpcId => {
1140
1162
  }
1141
1163
  };
1142
1164
  };
1143
- const RendererWorker$1 = 1;
1144
- const FileSystemWorker$1 = 209;
1145
- const FileSystemProcess$1 = 210;
1146
- const RpcId = {
1147
- __proto__: null,
1148
- FileSystemWorker: FileSystemWorker$1};
1165
+
1149
1166
  const {
1150
- invoke: invoke$8,
1151
- set: set$8} = create(FileSystemProcess$1);
1152
- const remove$1$1 = async uri => {
1153
- return invoke$8('FileSystem.remove', uri);
1154
- };
1155
- const readFile$2$1 = async uri => {
1156
- return invoke$8('FileSystem.readFile', uri);
1157
- };
1158
- const appendFile$1$1 = async (uri, text) => {
1167
+ invoke: invoke$3,
1168
+ invokeAndTransfer: invokeAndTransfer$2,
1169
+ set: set$3,
1170
+ dispose: dispose$1
1171
+ } = create(FileSystemProcess$1);
1172
+ const remove$2 = async uri => {
1173
+ return invoke$3('FileSystem.remove', uri);
1174
+ };
1175
+ const readFile$4 = async uri => {
1176
+ return invoke$3('FileSystem.readFile', uri);
1177
+ };
1178
+ const appendFile$2 = async (uri, text) => {
1159
1179
  // @ts-ignore
1160
- return invoke$8('FileSystem.appendFile', uri, text);
1180
+ return invoke$3('FileSystem.appendFile', uri, text);
1161
1181
  };
1162
- const readDirWithFileTypes$1$1 = async uri => {
1163
- return invoke$8('FileSystem.readDirWithFileTypes', uri);
1182
+ const readDirWithFileTypes$2 = async uri => {
1183
+ return invoke$3('FileSystem.readDirWithFileTypes', uri);
1164
1184
  };
1165
- const getPathSeparator$1$1 = async root => {
1185
+ const getPathSeparator$2 = async root => {
1166
1186
  // @ts-ignore
1167
- return invoke$8('FileSystem.getPathSeparator', root);
1187
+ return invoke$3('FileSystem.getPathSeparator', root);
1168
1188
  };
1169
1189
  const readJson$3 = async root => {
1170
1190
  // @ts-ignore
1171
- return invoke$8('FileSystem.readJson', root);
1191
+ return invoke$3('FileSystem.readJson', root);
1172
1192
  };
1173
- const getRealPath$1$1 = async path => {
1193
+ const getRealPath$2 = async path => {
1174
1194
  // @ts-ignore
1175
- return invoke$8('FileSystem.getRealPath', path);
1195
+ return invoke$3('FileSystem.getRealPath', path);
1176
1196
  };
1177
- const stat$1$1 = async path => {
1197
+ const stat$2 = async path => {
1178
1198
  // @ts-ignore
1179
- return invoke$8('FileSystem.stat', path);
1199
+ return invoke$3('FileSystem.stat', path);
1180
1200
  };
1181
- const writeFile$1$1 = async (path, content) => {
1201
+ const writeFile$3 = async (path, content) => {
1182
1202
  // @ts-ignore
1183
- return invoke$8('FileSystem.writeFile', path, content);
1203
+ return invoke$3('FileSystem.writeFile', path, content);
1184
1204
  };
1185
- const mkdir$1$1 = async path => {
1205
+ const mkdir$2 = async path => {
1186
1206
  // @ts-ignore
1187
- return invoke$8('FileSystem.mkdir', path);
1207
+ return invoke$3('FileSystem.mkdir', path);
1188
1208
  };
1189
- const rename$1$1 = async (oldUri, newUri) => {
1209
+ const rename$2 = async (oldUri, newUri) => {
1190
1210
  // @ts-ignore
1191
- return invoke$8('FileSystem.rename', oldUri, newUri);
1211
+ return invoke$3('FileSystem.rename', oldUri, newUri);
1192
1212
  };
1193
- const copy$1$1 = async (oldUri, newUri) => {
1213
+ const copy$2 = async (oldUri, newUri) => {
1194
1214
  // @ts-ignore
1195
- return invoke$8('FileSystem.copy', oldUri, newUri);
1215
+ return invoke$3('FileSystem.copy', oldUri, newUri);
1196
1216
  };
1197
- const getFolderSize$2 = async uri => {
1217
+ const getFolderSize$3 = async uri => {
1198
1218
  // @ts-ignore
1199
- return invoke$8('FileSystem.getFolderSize', uri);
1219
+ return invoke$3('FileSystem.getFolderSize', uri);
1200
1220
  };
1201
- const exists$1$1 = async uri => {
1221
+ const exists$2 = async uri => {
1202
1222
  // @ts-ignore
1203
- return invoke$8('FileSystem.exists', uri);
1223
+ return invoke$3('FileSystem.exists', uri);
1204
1224
  };
1225
+ const registerMockRpc$1 = commandMap => {
1226
+ const mockRpc = createMockRpc({
1227
+ commandMap
1228
+ });
1229
+ set$3(mockRpc);
1230
+ return mockRpc;
1231
+ };
1232
+
1205
1233
  const FileSystemProcess = {
1206
1234
  __proto__: null,
1207
- appendFile: appendFile$1$1,
1208
- copy: copy$1$1,
1209
- exists: exists$1$1,
1210
- getFolderSize: getFolderSize$2,
1211
- getPathSeparator: getPathSeparator$1$1,
1212
- getRealPath: getRealPath$1$1,
1213
- invoke: invoke$8,
1214
- mkdir: mkdir$1$1,
1215
- readDirWithFileTypes: readDirWithFileTypes$1$1,
1216
- readFile: readFile$2$1,
1235
+ appendFile: appendFile$2,
1236
+ copy: copy$2,
1237
+ dispose: dispose$1,
1238
+ exists: exists$2,
1239
+ getFolderSize: getFolderSize$3,
1240
+ getPathSeparator: getPathSeparator$2,
1241
+ getRealPath: getRealPath$2,
1242
+ invoke: invoke$3,
1243
+ invokeAndTransfer: invokeAndTransfer$2,
1244
+ mkdir: mkdir$2,
1245
+ readDirWithFileTypes: readDirWithFileTypes$2,
1246
+ readFile: readFile$4,
1217
1247
  readJson: readJson$3,
1218
- remove: remove$1$1,
1219
- rename: rename$1$1,
1220
- set: set$8,
1221
- stat: stat$1$1,
1222
- writeFile: writeFile$1$1
1248
+ registerMockRpc: registerMockRpc$1,
1249
+ remove: remove$2,
1250
+ rename: rename$2,
1251
+ set: set$3,
1252
+ stat: stat$2,
1253
+ writeFile: writeFile$3
1223
1254
  };
1255
+
1224
1256
  const {
1225
- invokeAndTransfer: invokeAndTransfer$3,
1226
- set: set$3} = create(RendererWorker$1);
1257
+ invoke: invoke$2,
1258
+ invokeAndTransfer: invokeAndTransfer$1,
1259
+ set: set$2,
1260
+ dispose
1261
+ } = create(RendererWorker$1);
1262
+ const searchFileHtml = async uri => {
1263
+ return invoke$2('ExtensionHost.searchFileWithHtml', uri);
1264
+ };
1265
+ const getFilePathElectron = async file => {
1266
+ return invoke$2('FileSystemHandle.getFilePathElectron', file);
1267
+ };
1268
+ const showContextMenu = async (x, y, id, ...args) => {
1269
+ return invoke$2('ContextMenu.show', x, y, id, ...args);
1270
+ };
1271
+ const getElectronVersion = async () => {
1272
+ return invoke$2('Process.getElectronVersion');
1273
+ };
1274
+ const applyBulkReplacement = async bulkEdits => {
1275
+ await invoke$2('BulkReplacement.applyBulkReplacement', bulkEdits);
1276
+ };
1277
+ const setColorTheme = async id => {
1278
+ // @ts-ignore
1279
+ return invoke$2(/* ColorTheme.setColorTheme */'ColorTheme.setColorTheme', /* colorThemeId */id);
1280
+ };
1281
+ const getNodeVersion = async () => {
1282
+ return invoke$2('Process.getNodeVersion');
1283
+ };
1284
+ const getChromeVersion = async () => {
1285
+ return invoke$2('Process.getChromeVersion');
1286
+ };
1287
+ const getV8Version = async () => {
1288
+ return invoke$2('Process.getV8Version');
1289
+ };
1290
+ const getFileHandles = async fileIds => {
1291
+ const files = await invoke$2('FileSystemHandle.getFileHandles', fileIds);
1292
+ return files;
1293
+ };
1294
+ const setWorkspacePath = async path => {
1295
+ await invoke$2('Workspace.setPath', path);
1296
+ };
1297
+ const registerWebViewInterceptor = async (id, port) => {
1298
+ await invokeAndTransfer$1('WebView.registerInterceptor', id, port);
1299
+ };
1300
+ const unregisterWebViewInterceptor = async id => {
1301
+ await invoke$2('WebView.unregisterInterceptor', id);
1302
+ };
1303
+ const sendMessagePortToEditorWorker = async (port, rpcId) => {
1304
+ const command = 'HandleMessagePort.handleMessagePort';
1305
+ // @ts-ignore
1306
+ await invokeAndTransfer$1('SendMessagePortToExtensionHostWorker.sendMessagePortToEditorWorker', port, command, rpcId);
1307
+ };
1308
+ const sendMessagePortToErrorWorker = async (port, rpcId) => {
1309
+ const command = 'Errors.handleMessagePort';
1310
+ // @ts-ignore
1311
+ await invokeAndTransfer$1('SendMessagePortToExtensionHostWorker.sendMessagePortToErrorWorker', port, command, rpcId);
1312
+ };
1313
+ const sendMessagePortToMarkdownWorker = async (port, rpcId) => {
1314
+ const command = 'Markdown.handleMessagePort';
1315
+ // @ts-ignore
1316
+ await invokeAndTransfer$1('SendMessagePortToExtensionHostWorker.sendMessagePortToMarkdownWorker', port, command, rpcId);
1317
+ };
1318
+ const sendMessagePortToIconThemeWorker = async (port, rpcId) => {
1319
+ const command = 'IconTheme.handleMessagePort';
1320
+ // @ts-ignore
1321
+ await invokeAndTransfer$1('SendMessagePortToExtensionHostWorker.sendMessagePortToIconThemeWorker', port, command, rpcId);
1322
+ };
1323
+ const sendMessagePortToFileSystemWorker = async (port, rpcId) => {
1324
+ const command = 'FileSystem.handleMessagePort';
1325
+ // @ts-ignore
1326
+ await invokeAndTransfer$1('SendMessagePortToExtensionHostWorker.sendMessagePortToFileSystemWorker', port, command, rpcId);
1327
+ };
1328
+ const readFile$3 = async uri => {
1329
+ return invoke$2('FileSystem.readFile', uri);
1330
+ };
1331
+ const getWebViewSecret = async key => {
1332
+ // @ts-ignore
1333
+ return invoke$2('WebView.getSecret', key);
1334
+ };
1335
+ const setWebViewPort = async (uid, port, origin, portType) => {
1336
+ return invokeAndTransfer$1('WebView.setPort', uid, port, origin, portType);
1337
+ };
1338
+ const setFocus = key => {
1339
+ return invoke$2('Focus.setFocus', key);
1340
+ };
1341
+ const getFileIcon = async options => {
1342
+ return invoke$2('IconTheme.getFileIcon', options);
1343
+ };
1344
+ const getColorThemeNames = async () => {
1345
+ return invoke$2('ColorTheme.getColorThemeNames');
1346
+ };
1347
+ const disableExtension = async id => {
1348
+ // @ts-ignore
1349
+ return invoke$2('ExtensionManagement.disable', id);
1350
+ };
1351
+ const enableExtension = async id => {
1352
+ // @ts-ignore
1353
+ return invoke$2('ExtensionManagement.enable', id);
1354
+ };
1355
+ const handleDebugChange = async params => {
1356
+ // @ts-ignore
1357
+ return invoke$2('Run And Debug.handleChange', params);
1358
+ };
1359
+ const getFolderIcon = async options => {
1360
+ return invoke$2('IconTheme.getFolderIcon', options);
1361
+ };
1362
+ const closeWidget = async widgetId => {
1363
+ return invoke$2('Viewlet.closeWidget', widgetId);
1364
+ };
1227
1365
  const sendMessagePortToExtensionHostWorker$1 = async (port, rpcId = 0) => {
1228
1366
  const command = 'HandleMessagePort.handleMessagePort2';
1229
- await invokeAndTransfer$3('SendMessagePortToExtensionHostWorker.sendMessagePortToExtensionHostWorker', port, command, rpcId);
1367
+ await invokeAndTransfer$1('SendMessagePortToExtensionHostWorker.sendMessagePortToExtensionHostWorker', port, command, rpcId);
1368
+ };
1369
+ const sendMessagePortToSearchProcess = async port => {
1370
+ await invokeAndTransfer$1('SendMessagePortToElectron.sendMessagePortToElectron', port, 'HandleMessagePortForSearchProcess.handleMessagePortForSearchProcess');
1371
+ };
1372
+ const confirm = async (message, options) => {
1373
+ // @ts-ignore
1374
+ const result = await invoke$2('ConfirmPrompt.prompt', message, options);
1375
+ return result;
1376
+ };
1377
+ const getRecentlyOpened = async () => {
1378
+ return invoke$2(/* RecentlyOpened.getRecentlyOpened */'RecentlyOpened.getRecentlyOpened');
1379
+ };
1380
+ const getKeyBindings = async () => {
1381
+ return invoke$2('KeyBindingsInitial.getKeyBindings');
1382
+ };
1383
+ const writeClipBoardText = async text => {
1384
+ await invoke$2('ClipBoard.writeText', /* text */text);
1385
+ };
1386
+ const writeClipBoardImage = async blob => {
1387
+ // @ts-ignore
1388
+ await invoke$2('ClipBoard.writeImage', /* text */blob);
1389
+ };
1390
+ const searchFileMemory = async uri => {
1391
+ // @ts-ignore
1392
+ return invoke$2('ExtensionHost.searchFileWithMemory', uri);
1393
+ };
1394
+ const searchFileFetch = async uri => {
1395
+ return invoke$2('ExtensionHost.searchFileWithFetch', uri);
1396
+ };
1397
+ const showMessageBox = async options => {
1398
+ return invoke$2('ElectronDialog.showMessageBox', options);
1399
+ };
1400
+ const handleDebugResumed = async params => {
1401
+ await invoke$2('Run And Debug.handleResumed', params);
1402
+ };
1403
+ const openWidget = async name => {
1404
+ await invoke$2('Viewlet.openWidget', name);
1405
+ };
1406
+ const getIcons = async requests => {
1407
+ const icons = await invoke$2('IconTheme.getIcons', requests);
1408
+ return icons;
1409
+ };
1410
+ const activateByEvent = event => {
1411
+ return invoke$2('ExtensionHostManagement.activateByEvent', event);
1412
+ };
1413
+ const setAdditionalFocus = focusKey => {
1414
+ // @ts-ignore
1415
+ return invoke$2('Focus.setAdditionalFocus', focusKey);
1416
+ };
1417
+ const getActiveEditorId = () => {
1418
+ // @ts-ignore
1419
+ return invoke$2('GetActiveEditor.getActiveEditorId');
1420
+ };
1421
+ const getWorkspacePath = () => {
1422
+ return invoke$2('Workspace.getPath');
1423
+ };
1424
+ const sendMessagePortToRendererProcess = async port => {
1425
+ const command = 'HandleMessagePort.handleMessagePort';
1426
+ // @ts-ignore
1427
+ await invokeAndTransfer$1('SendMessagePortToExtensionHostWorker.sendMessagePortToRendererProcess', port, command, DebugWorker);
1428
+ };
1429
+ const getPreference = async key => {
1430
+ return await invoke$2('Preferences.get', key);
1431
+ };
1432
+ const getAllExtensions = async () => {
1433
+ return invoke$2('ExtensionManagement.getAllExtensions');
1434
+ };
1435
+ const rerenderEditor = async key => {
1436
+ // @ts-ignore
1437
+ return invoke$2('Editor.rerender', key);
1438
+ };
1439
+ const handleDebugPaused = async params => {
1440
+ await invoke$2('Run And Debug.handlePaused', params);
1441
+ };
1442
+ const openUri = async (uri, focus, options) => {
1443
+ await invoke$2('Main.openUri', uri, focus, options);
1444
+ };
1445
+ const sendMessagePortToSyntaxHighlightingWorker = async port => {
1446
+ await invokeAndTransfer$1(
1447
+ // @ts-ignore
1448
+ 'SendMessagePortToSyntaxHighlightingWorker.sendMessagePortToSyntaxHighlightingWorker', port, 'HandleMessagePort.handleMessagePort2');
1449
+ };
1450
+ const handleDebugScriptParsed = async script => {
1451
+ await invoke$2('Run And Debug.handleScriptParsed', script);
1452
+ };
1453
+ const getWindowId = async () => {
1454
+ return invoke$2('GetWindowId.getWindowId');
1455
+ };
1456
+ const getBlob = async uri => {
1457
+ // @ts-ignore
1458
+ return invoke$2('FileSystem.getBlob', uri);
1459
+ };
1460
+ const getExtensionCommands = async () => {
1461
+ return invoke$2('ExtensionHost.getCommands');
1462
+ };
1463
+ const showErrorDialog = async errorInfo => {
1464
+ // @ts-ignore
1465
+ await invoke$2('ErrorHandling.showErrorDialog', errorInfo);
1466
+ };
1467
+ const getFolderSize$2 = async uri => {
1468
+ // @ts-ignore
1469
+ return await invoke$2('FileSystem.getFolderSize', uri);
1470
+ };
1471
+ const getExtension = async id => {
1472
+ // @ts-ignore
1473
+ return invoke$2('ExtensionManagement.getExtension', id);
1474
+ };
1475
+ const getMarkdownDom = async html => {
1476
+ // @ts-ignore
1477
+ return invoke$2('Markdown.getVirtualDom', html);
1478
+ };
1479
+ const renderMarkdown = async (markdown, options) => {
1480
+ // @ts-ignore
1481
+ return invoke$2('Markdown.renderMarkdown', markdown, options);
1230
1482
  };
1483
+ const openNativeFolder = async uri => {
1484
+ // @ts-ignore
1485
+ await invoke$2('OpenNativeFolder.openNativeFolder', uri);
1486
+ };
1487
+ const uninstallExtension = async id => {
1488
+ return invoke$2('ExtensionManagement.uninstall', id);
1489
+ };
1490
+ const installExtension = async id => {
1491
+ // @ts-ignore
1492
+ return invoke$2('ExtensionManagement.install', id);
1493
+ };
1494
+ const openExtensionSearch = async () => {
1495
+ // @ts-ignore
1496
+ return invoke$2('SideBar.openViewlet', 'Extensions');
1497
+ };
1498
+ const setExtensionsSearchValue = async searchValue => {
1499
+ // @ts-ignore
1500
+ return invoke$2('Extensions.handleInput', searchValue);
1501
+ };
1502
+ const openExternal = async uri => {
1503
+ // @ts-ignore
1504
+ await invoke$2('Open.openExternal', uri);
1505
+ };
1506
+ const openUrl = async uri => {
1507
+ // @ts-ignore
1508
+ await invoke$2('Open.openUrl', uri);
1509
+ };
1510
+ const getAllPreferences = async () => {
1511
+ // @ts-ignore
1512
+ return invoke$2('Preferences.getAll');
1513
+ };
1514
+ const showSaveFilePicker = async () => {
1515
+ // @ts-ignore
1516
+ return invoke$2('FilePicker.showSaveFilePicker');
1517
+ };
1518
+ const getLogsDir = async () => {
1519
+ // @ts-ignore
1520
+ return invoke$2('PlatformPaths.getLogsDir');
1521
+ };
1522
+ const registerMockRpc = commandMap => {
1523
+ const mockRpc = createMockRpc({
1524
+ commandMap
1525
+ });
1526
+ set$2(mockRpc);
1527
+ return mockRpc;
1528
+ };
1529
+
1231
1530
  const RendererWorker = {
1232
1531
  __proto__: null,
1233
- invokeAndTransfer: invokeAndTransfer$3,
1532
+ activateByEvent,
1533
+ applyBulkReplacement,
1534
+ closeWidget,
1535
+ confirm,
1536
+ disableExtension,
1537
+ dispose,
1538
+ enableExtension,
1539
+ getActiveEditorId,
1540
+ getAllExtensions,
1541
+ getAllPreferences,
1542
+ getBlob,
1543
+ getChromeVersion,
1544
+ getColorThemeNames,
1545
+ getElectronVersion,
1546
+ getExtension,
1547
+ getExtensionCommands,
1548
+ getFileHandles,
1549
+ getFileIcon,
1550
+ getFilePathElectron,
1551
+ getFolderIcon,
1552
+ getFolderSize: getFolderSize$2,
1553
+ getIcons,
1554
+ getKeyBindings,
1555
+ getLogsDir,
1556
+ getMarkdownDom,
1557
+ getNodeVersion,
1558
+ getPreference,
1559
+ getRecentlyOpened,
1560
+ getV8Version,
1561
+ getWebViewSecret,
1562
+ getWindowId,
1563
+ getWorkspacePath,
1564
+ handleDebugChange,
1565
+ handleDebugPaused,
1566
+ handleDebugResumed,
1567
+ handleDebugScriptParsed,
1568
+ installExtension,
1569
+ invoke: invoke$2,
1570
+ invokeAndTransfer: invokeAndTransfer$1,
1571
+ openExtensionSearch,
1572
+ openExternal,
1573
+ openNativeFolder,
1574
+ openUri,
1575
+ openUrl,
1576
+ openWidget,
1577
+ readFile: readFile$3,
1578
+ registerMockRpc,
1579
+ registerWebViewInterceptor,
1580
+ renderMarkdown,
1581
+ rerenderEditor,
1582
+ searchFileFetch,
1583
+ searchFileHtml,
1584
+ searchFileMemory,
1585
+ sendMessagePortToEditorWorker,
1586
+ sendMessagePortToErrorWorker,
1234
1587
  sendMessagePortToExtensionHostWorker: sendMessagePortToExtensionHostWorker$1,
1235
- set: set$3};
1588
+ sendMessagePortToFileSystemWorker,
1589
+ sendMessagePortToIconThemeWorker,
1590
+ sendMessagePortToMarkdownWorker,
1591
+ sendMessagePortToRendererProcess,
1592
+ sendMessagePortToSearchProcess,
1593
+ sendMessagePortToSyntaxHighlightingWorker,
1594
+ set: set$2,
1595
+ setAdditionalFocus,
1596
+ setColorTheme,
1597
+ setExtensionsSearchValue,
1598
+ setFocus,
1599
+ setWebViewPort,
1600
+ setWorkspacePath,
1601
+ showContextMenu,
1602
+ showErrorDialog,
1603
+ showMessageBox,
1604
+ showSaveFilePicker,
1605
+ uninstallExtension,
1606
+ unregisterWebViewInterceptor,
1607
+ writeClipBoardImage,
1608
+ writeClipBoardText
1609
+ };
1236
1610
 
1237
1611
  const getPortTuple = () => {
1238
1612
  const {
@@ -1312,6 +1686,7 @@ const {
1312
1686
  const Http = 'http:';
1313
1687
  const Memory = 'memfs:';
1314
1688
  const Https = 'https:';
1689
+ const File = 'file:';
1315
1690
 
1316
1691
  const isHttp = uri => {
1317
1692
  return uri.startsWith(Http) || uri.startsWith(Https);
@@ -1326,7 +1701,7 @@ const remove = async dirent => {
1326
1701
  };
1327
1702
  const readFile = async uri => {
1328
1703
  if (isHttp(uri)) {
1329
- return readFile$3(uri);
1704
+ return readFile$5(uri);
1330
1705
  }
1331
1706
  if (isMemory(uri)) {
1332
1707
  return readFile$2(uri);
@@ -1375,7 +1750,7 @@ const stat = async dirent => {
1375
1750
  };
1376
1751
  const exists = async uri => {
1377
1752
  if (isHttp(uri)) {
1378
- return exists$2(uri);
1753
+ return exists$3(uri);
1379
1754
  }
1380
1755
  return exists$1(uri);
1381
1756
  };
@@ -1401,28 +1776,47 @@ const getFolderSize = async uri => {
1401
1776
  return getFolderSize$1(uri);
1402
1777
  };
1403
1778
 
1779
+ const RE_PROTOCOL = /^([a-z-]+):\/\//;
1780
+ const assertUri = uri => {
1781
+ const protocolMatch = uri.match(RE_PROTOCOL);
1782
+ if (!protocolMatch) {
1783
+ throw new Error(`uri must be a valid uri`);
1784
+ }
1785
+ };
1786
+
1404
1787
  const watchCallbacks = Object.create(null);
1405
- const registerWatchCallback = (id, fn) => {
1406
- watchCallbacks[id] = fn;
1788
+ const registerWatchCallback = (id, rpcId, commandId) => {
1789
+ watchCallbacks[id] = {
1790
+ rpcId,
1791
+ commandId
1792
+ };
1407
1793
  };
1408
1794
  const executeWatchCallBack = async id => {
1409
- await watchCallbacks[id]();
1795
+ const entry = watchCallbacks[id];
1796
+ if (!entry) {
1797
+ throw new Error(`watch callback ${id} not found`);
1798
+ }
1799
+ const {
1800
+ rpcId,
1801
+ commandId
1802
+ } = entry;
1803
+ const rpc = get(rpcId);
1804
+ await rpc.invoke(commandId, id);
1410
1805
  };
1411
1806
  const unregisterWatchCallback = id => {
1412
1807
  delete watchCallbacks[id];
1413
1808
  };
1414
1809
 
1810
+ // TODO support file watchers for differenr protocols like memfs, http
1811
+
1415
1812
  const watchFile = async (id, uri, rpcId) => {
1813
+ assertUri(uri);
1416
1814
  const commandId = 'Output.executeWatchCallback';
1417
- registerWatchCallback(id, async () => {
1418
- const rpc = get(rpcId);
1419
- if (!rpc) {
1420
- return;
1421
- }
1422
- await rpc.invoke(commandId, id);
1423
- });
1424
- // @ts-ignore
1425
- await invoke('FileSystem.watchFile', id, uri);
1815
+ registerWatchCallback(id, rpcId, commandId);
1816
+ if (uri.startsWith(File)) {
1817
+ // @ts-ignore
1818
+ await invoke('FileSystem.watchFile', id, uri);
1819
+ }
1426
1820
  };
1427
1821
  const executeWatchCallback = async id => {
1428
1822
  try {
@@ -1433,6 +1827,7 @@ const executeWatchCallback = async id => {
1433
1827
  };
1434
1828
  const unwatchFile = async id => {
1435
1829
  unregisterWatchCallback(id);
1830
+ // TODO only if it is a file uri
1436
1831
  // @ts-ignore
1437
1832
  await invoke('FileSystem.unwatchFile', id);
1438
1833
  };
@@ -1443,13 +1838,13 @@ const handleMessagePort = async (port, rpcId) => {
1443
1838
  messagePort: port
1444
1839
  });
1445
1840
  if (rpcId) {
1446
- set$g(rpcId, rpc);
1841
+ set$4(rpcId, rpc);
1447
1842
  }
1448
1843
  };
1449
1844
 
1450
1845
  const sendMessagePortToFileSystemProcess = async port => {
1451
1846
  const command = 'HandleMessagePortForFileSystemProcess.handleMessagePortForFileSystemProcess';
1452
- await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToSharedProcess', port, command, RpcId.FileSystemWorker);
1847
+ await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToSharedProcess', port, command, FileSystemWorker);
1453
1848
  };
1454
1849
 
1455
1850
  const createFileSystemProcessRpcElectron = async () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/file-system-worker",
3
- "version": "1.25.0",
3
+ "version": "2.1.0",
4
4
  "description": "File System Worker",
5
5
  "keywords": [
6
6
  "Lvce Editor"