@lvce-editor/main-area-worker 1.1.0 → 1.2.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.
@@ -508,7 +508,7 @@ const IpcParentWithMessagePort$1 = {
508
508
 
509
509
  const Two$1 = '2.0';
510
510
  const callbacks = Object.create(null);
511
- const get$3 = id => {
511
+ const get$2 = id => {
512
512
  return callbacks[id];
513
513
  };
514
514
  const remove$1 = id => {
@@ -657,7 +657,7 @@ const warn = (...args) => {
657
657
  console.warn(...args);
658
658
  };
659
659
  const resolve = (id, response) => {
660
- const fn = get$3(id);
660
+ const fn = get$2(id);
661
661
  if (!fn) {
662
662
  console.log(response);
663
663
  warn(`callback ${id} may already be disposed`);
@@ -1028,12 +1028,9 @@ const createMockRpc = ({
1028
1028
  return mockRpc;
1029
1029
  };
1030
1030
 
1031
- const Button$1 = 'button';
1032
-
1033
1031
  const Button = 1;
1034
1032
  const Div = 4;
1035
1033
  const Span = 8;
1036
- const Text = 12;
1037
1034
  const Pre = 51;
1038
1035
 
1039
1036
  const TargetName = 'event.target.name';
@@ -1047,7 +1044,7 @@ const rpcs = Object.create(null);
1047
1044
  const set$3 = (id, rpc) => {
1048
1045
  rpcs[id] = rpc;
1049
1046
  };
1050
- const get$2 = id => {
1047
+ const get$1 = id => {
1051
1048
  return rpcs[id];
1052
1049
  };
1053
1050
  const remove = id => {
@@ -1058,18 +1055,18 @@ const remove = id => {
1058
1055
  const create$2 = rpcId => {
1059
1056
  return {
1060
1057
  async dispose() {
1061
- const rpc = get$2(rpcId);
1058
+ const rpc = get$1(rpcId);
1062
1059
  await rpc.dispose();
1063
1060
  },
1064
1061
  // @ts-ignore
1065
1062
  invoke(method, ...params) {
1066
- const rpc = get$2(rpcId);
1063
+ const rpc = get$1(rpcId);
1067
1064
  // @ts-ignore
1068
1065
  return rpc.invoke(method, ...params);
1069
1066
  },
1070
1067
  // @ts-ignore
1071
1068
  invokeAndTransfer(method, ...params) {
1072
- const rpc = get$2(rpcId);
1069
+ const rpc = get$1(rpcId);
1073
1070
  // @ts-ignore
1074
1071
  return rpc.invokeAndTransfer(method, ...params);
1075
1072
  },
@@ -1092,12 +1089,10 @@ const create$2 = rpcId => {
1092
1089
  };
1093
1090
 
1094
1091
  const {
1095
- invoke: invoke$1,
1096
1092
  set: set$2
1097
1093
  } = create$2(ExtensionHostWorker);
1098
1094
 
1099
1095
  const {
1100
- invoke,
1101
1096
  invokeAndTransfer,
1102
1097
  set: set$1
1103
1098
  } = create$2(RendererWorker);
@@ -1105,12 +1100,6 @@ const sendMessagePortToExtensionHostWorker$1 = async (port, rpcId = 0) => {
1105
1100
  const command = 'HandleMessagePort.handleMessagePort2';
1106
1101
  await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToExtensionHostWorker', port, command, rpcId);
1107
1102
  };
1108
- const activateByEvent$1 = (event, assetDir, platform) => {
1109
- return invoke('ExtensionHostManagement.activateByEvent', event, assetDir, platform);
1110
- };
1111
- const getPreference = async key => {
1112
- return await invoke('Preferences.get', key);
1113
- };
1114
1103
 
1115
1104
  const toCommandId = key => {
1116
1105
  const dotIndex = key.indexOf('.');
@@ -1198,11 +1187,11 @@ const terminate = () => {
1198
1187
  };
1199
1188
 
1200
1189
  const {
1201
- get: get$1,
1202
- getCommandIds: getCommandIds$1,
1203
- registerCommands: registerCommands$1,
1190
+ get,
1191
+ getCommandIds,
1192
+ registerCommands,
1204
1193
  set,
1205
- wrapCommand: wrapCommand$1} = create$1();
1194
+ wrapCommand} = create$1();
1206
1195
 
1207
1196
  const create = (uid, uri, x, y, width, height, platform, assetDir) => {
1208
1197
  const state = {
@@ -1216,7 +1205,7 @@ const create = (uid, uri, x, y, width, height, platform, assetDir) => {
1216
1205
  };
1217
1206
 
1218
1207
  const isEqual = (oldState, newState) => {
1219
- return oldState.statusBarItemsLeft === newState.statusBarItemsLeft && oldState.statusBarItemsRight === newState.statusBarItemsRight;
1208
+ return oldState.layout === newState.layout;
1220
1209
  };
1221
1210
 
1222
1211
  const RenderItems = 4;
@@ -1239,65 +1228,15 @@ const diff2 = uid => {
1239
1228
  const {
1240
1229
  newState,
1241
1230
  oldState
1242
- } = get$1(uid);
1231
+ } = get(uid);
1243
1232
  const result = diff(oldState, newState);
1244
1233
  return result;
1245
1234
  };
1246
1235
 
1247
- const getMatchingItem = (itemsLeft, itemsRight, name) => {
1248
- for (const item of itemsLeft) {
1249
- if (item.name === name) {
1250
- return item;
1251
- }
1252
- }
1253
- for (const item of itemsRight) {
1254
- if (item.name === name) {
1255
- return item;
1256
- }
1257
- }
1258
- return undefined;
1259
- };
1260
-
1261
- const handleClickExtensionStatusBarItem = async name => {
1262
- // @ts-ignore
1263
- await invoke$1(`ExtensionHostStatusBar.executeCommand`, name);
1264
- };
1265
-
1266
- const handleClickNotification = async () => {
1267
- // TODO toggle notifications
1268
- };
1269
-
1270
- const handleClickProblems = async () => {
1271
- // @ts-ignore
1272
- await invoke('Layout.showPanel');
1273
- // @ts-ignore
1274
- await invoke('Panel.toggleView', 'Problems');
1275
- };
1276
-
1277
- const Notifications = 'Notifications';
1278
- const Problems = 'Problems';
1279
-
1280
1236
  const handleClick = async (state, name) => {
1281
1237
  if (!name) {
1282
1238
  return state;
1283
1239
  }
1284
- const {
1285
- statusBarItemsLeft,
1286
- statusBarItemsRight
1287
- } = state;
1288
- const item = getMatchingItem(statusBarItemsLeft, statusBarItemsRight, name);
1289
- if (!item) {
1290
- return state;
1291
- }
1292
- if (item.name === Notifications) {
1293
- await handleClickNotification();
1294
- } else if (item.name === Problems) {
1295
- await handleClickProblems();
1296
- } else {
1297
- await handleClickExtensionStatusBarItem(name);
1298
- }
1299
- // TODO
1300
- // sendExtensionWorker([/* statusBarItemHandleClick */ 7657, /* name */ name])
1301
1240
  return state;
1302
1241
  };
1303
1242
 
@@ -1323,282 +1262,14 @@ const initialize = async () => {
1323
1262
  set$2(rpc);
1324
1263
  };
1325
1264
 
1326
- const getIndex = (items, item) => {
1327
- for (let i = 0; i < items.length; i++) {
1328
- if (items[i].name === item.name) {
1329
- return i;
1330
- }
1331
- }
1332
- return -1;
1333
- };
1334
-
1335
- const updateArray = (items, newItem) => {
1336
- const index = getIndex(items, newItem);
1337
- const before = items.slice(0, index);
1338
- const after = items.slice(index + 1);
1339
- return [...before, newItem, ...after];
1340
- };
1341
-
1342
- const itemLeftUpdate = (state, newItem) => {
1343
- return {
1344
- ...state,
1345
- statusBarItemsLeft: updateArray([...state.statusBarItemsLeft], newItem)
1346
- };
1347
- };
1348
-
1349
- const itemRightCreate = (state, newItem) => {
1350
- const {
1351
- statusBarItemsRight
1352
- } = state;
1353
- const newStatusBarItemsRight = [...statusBarItemsRight, newItem];
1354
- return {
1355
- ...state,
1356
- statusBarItemsRight: newStatusBarItemsRight
1357
- };
1358
- };
1359
-
1360
- const itemRightUpdate = (state, newItem) => {
1361
- const {
1362
- statusBarItemsRight
1363
- } = state;
1364
- const newStatusBarItemsRight = updateArray([...statusBarItemsRight], newItem);
1365
- return {
1366
- ...state,
1367
- statusBarItemsRight: newStatusBarItemsRight
1368
- };
1369
- };
1370
-
1371
- const ProblemsErrorIcon = 'ProblemsErrorIcon';
1372
- const ProblemsWarningIcon = 'ProblemsWarningIcon';
1373
- const StatusBarItem = 'StatusBarItem';
1374
- const StatusBarItemsLeft = 'StatusBarItemsLeft';
1375
- const StatusBarItemsRight = 'StatusBarItemsRight';
1376
-
1377
- const OnStatusBarItem = 'onStatusBarItem';
1378
-
1379
- const GetStatusBarItems = 'ExtensionHost.getStatusBarItems2';
1380
-
1381
- const activateByEvent = (event, assetDir, platform) => {
1382
- // @ts-ignore
1383
- return activateByEvent$1(event, assetDir, platform);
1384
- };
1385
-
1386
- const executeProviders = async ({
1387
- assetDir,
1388
- combineResults,
1389
- event,
1390
- method,
1391
- noProviderFoundMessage = 'No provider found',
1392
- noProviderFoundResult,
1393
- params,
1394
- platform
1395
- }) => {
1396
- await activateByEvent(event, assetDir, platform);
1397
- // @ts-ignore
1398
- const result = await invoke$1(method, ...params);
1399
- return result;
1400
- };
1401
-
1402
- const combineResults = results => {
1403
- return results.flat();
1404
- };
1405
- const getStatusBarItems$1 = (assetDir, platform) => {
1406
- return executeProviders({
1407
- assetDir,
1408
- combineResults,
1409
- event: OnStatusBarItem,
1410
- method: GetStatusBarItems,
1411
- noProviderFoundMessage: 'No status bar item provider found',
1412
- noProviderFoundResult: [],
1413
- params: [],
1414
- platform
1415
- });
1416
- };
1417
-
1418
- const toStatusBarItem = uiStatusBarItem => {
1419
- const elements = [];
1420
- if (uiStatusBarItem.icon) {
1421
- elements.push({
1422
- type: 'icon',
1423
- value: uiStatusBarItem.icon
1424
- });
1425
- }
1426
- if (uiStatusBarItem.text) {
1427
- elements.push({
1428
- type: 'text',
1429
- value: uiStatusBarItem.text
1430
- });
1431
- }
1432
- if (elements.length === 0) {
1433
- elements.push({
1434
- type: 'text',
1435
- value: ''
1436
- });
1437
- }
1438
- return {
1439
- command: uiStatusBarItem.command || undefined,
1440
- elements,
1441
- name: uiStatusBarItem.name,
1442
- tooltip: uiStatusBarItem.tooltip
1443
- };
1444
- };
1445
-
1446
- const toUiStatusBarItem = extensionHostStatusBarItem => {
1447
- return {
1448
- command: extensionHostStatusBarItem.command || '',
1449
- icon: extensionHostStatusBarItem.icon || '',
1450
- name: extensionHostStatusBarItem.id || extensionHostStatusBarItem.name || '',
1451
- text: extensionHostStatusBarItem.text || '',
1452
- tooltip: extensionHostStatusBarItem.tooltip || ''
1453
- };
1454
- };
1455
-
1456
- const toUiStatusBarItems = statusBarItems => {
1457
- if (!statusBarItems) {
1458
- return [];
1459
- }
1460
- return statusBarItems.map(toUiStatusBarItem);
1461
- };
1462
-
1463
- const getStatusBarItems = async (showItems, assetDir, platform) => {
1464
- if (!showItems) {
1465
- return [];
1466
- }
1467
- await activateByEvent('onSourceControl', assetDir, platform);
1468
- const extensionStatusBarItems = await getStatusBarItems$1(assetDir, platform);
1469
- const uiStatusBarItems = toUiStatusBarItems(extensionStatusBarItems);
1470
- const extraItems = [{
1471
- command: undefined,
1472
- elements: [{
1473
- type: 'text',
1474
- value: 'Notifications'
1475
- }],
1476
- name: Notifications,
1477
- tooltip: ''
1478
- }, {
1479
- command: undefined,
1480
- elements: [{
1481
- type: 'icon',
1482
- value: ProblemsErrorIcon
1483
- }, {
1484
- type: 'text',
1485
- value: '0'
1486
- }, {
1487
- type: 'icon',
1488
- value: ProblemsWarningIcon
1489
- }, {
1490
- type: 'text',
1491
- value: '0'
1492
- }],
1493
- name: Problems,
1494
- tooltip: ''
1495
- }];
1496
- return [...uiStatusBarItems.map(toStatusBarItem), ...extraItems];
1497
- };
1498
-
1499
- const get = async key => {
1500
- return getPreference(key);
1501
- };
1502
-
1503
- const itemsVisible = async () => {
1504
- const statusBarItemsPreference = (await get('statusBar.itemsVisible')) ?? true;
1505
- return statusBarItemsPreference;
1506
- };
1507
-
1508
1265
  const loadContent = async state => {
1509
- const {
1510
- assetDir,
1511
- platform
1512
- } = state;
1513
- const statusBarItemsPreference = await itemsVisible();
1514
- const statusBarItems = await getStatusBarItems(statusBarItemsPreference, assetDir, platform);
1515
- return {
1516
- ...state,
1517
- statusBarItemsLeft: [...statusBarItems],
1518
- statusBarItemsRight: []
1519
- };
1520
- };
1521
-
1522
- const text = data => {
1523
1266
  return {
1524
- childCount: 0,
1525
- text: data,
1526
- type: Text
1267
+ ...state
1527
1268
  };
1528
1269
  };
1529
1270
 
1530
- const HandleClick = 11;
1531
-
1532
- const getElementVirtualDom = element => {
1533
- if (element.type === 'text') {
1534
- return [text(element.value)];
1535
- }
1536
- if (element.type === 'icon') {
1537
- return [{
1538
- childCount: 0,
1539
- className: element.value,
1540
- type: Div
1541
- }];
1542
- }
1543
- return [];
1544
- };
1545
- const getStatusBarItemVirtualDom = statusBarItem => {
1546
- const {
1547
- elements,
1548
- name,
1549
- tooltip
1550
- } = statusBarItem;
1551
- const elementNodes = elements.flatMap(getElementVirtualDom);
1552
- return [{
1553
- childCount: elementNodes.length,
1554
- className: StatusBarItem,
1555
- name,
1556
- role: Button$1,
1557
- tabIndex: -1,
1558
- title: tooltip,
1559
- type: Button
1560
- }, ...elementNodes];
1561
- };
1562
-
1563
- const getStatusBarItemsVirtualDom = (items, className) => {
1564
- if (items.length === 0) {
1565
- return [];
1566
- }
1567
- return [{
1568
- childCount: items.length,
1569
- className,
1570
- type: Div
1571
- }, ...items.flatMap(getStatusBarItemVirtualDom)];
1572
- };
1573
-
1574
- const getChildCount = (leftCount, rightCount) => {
1575
- let count = 0;
1576
- if (leftCount > 0) {
1577
- count++;
1578
- }
1579
- if (rightCount > 0) {
1580
- count++;
1581
- }
1582
- return count;
1583
- };
1584
- const getStatusBarVirtualDom = (statusBarItemsLeft, statusBarItemsRight) => {
1585
- const dom = [{
1586
- childCount: getChildCount(statusBarItemsLeft.length, statusBarItemsRight.length),
1587
- className: 'StatusBar',
1588
- onClick: HandleClick,
1589
- type: Div
1590
- }, ...getStatusBarItemsVirtualDom(statusBarItemsLeft, StatusBarItemsLeft), ...getStatusBarItemsVirtualDom(statusBarItemsRight, StatusBarItemsRight)];
1591
- return dom;
1592
- };
1593
-
1594
1271
  const renderItems = (oldState, newState) => {
1595
- const {
1596
- statusBarItemsLeft,
1597
- statusBarItemsRight,
1598
- uid
1599
- } = newState;
1600
- const dom = getStatusBarVirtualDom(statusBarItemsLeft, statusBarItemsRight);
1601
- return [SetDom2, uid, dom];
1272
+ return [SetDom2, newState.uid, []];
1602
1273
  };
1603
1274
 
1604
1275
  const getRenderer = diffType => {
@@ -1626,12 +1297,14 @@ const render2 = (uid, diffResult) => {
1626
1297
  const {
1627
1298
  newState,
1628
1299
  oldState
1629
- } = get$1(uid);
1300
+ } = get(uid);
1630
1301
  set(uid, newState, newState);
1631
1302
  const commands = applyRender(oldState, newState, diffResult);
1632
1303
  return commands;
1633
1304
  };
1634
1305
 
1306
+ const HandleClick = 11;
1307
+
1635
1308
  const renderEventListeners = () => {
1636
1309
  return [{
1637
1310
  name: HandleClick,
@@ -1648,7 +1321,7 @@ const resize = (state, dimensions) => {
1648
1321
 
1649
1322
  const saveState = uid => {
1650
1323
  number(uid);
1651
- const value = get$1(uid);
1324
+ const value = get(uid);
1652
1325
  const {
1653
1326
  newState
1654
1327
  } = value;
@@ -1663,24 +1336,21 @@ const saveState = uid => {
1663
1336
  };
1664
1337
 
1665
1338
  const commandMap = {
1666
- 'StatusBar.create': create,
1667
- 'StatusBar.diff2': diff2,
1668
- 'StatusBar.getCommandIds': getCommandIds$1,
1669
- 'StatusBar.handleClick': wrapCommand$1(handleClick),
1670
- 'StatusBar.initialize': initialize,
1671
- 'StatusBar.itemLeftUpdate': wrapCommand$1(itemLeftUpdate),
1672
- 'StatusBar.itemRightCreate': wrapCommand$1(itemRightCreate),
1673
- 'StatusBar.itemRightUpdate': wrapCommand$1(itemRightUpdate),
1674
- 'StatusBar.loadContent': wrapCommand$1(loadContent),
1675
- 'StatusBar.render2': render2,
1676
- 'StatusBar.renderEventListeners': renderEventListeners,
1677
- 'StatusBar.resize': wrapCommand$1(resize),
1678
- 'StatusBar.saveState': saveState,
1679
- 'StatusBar.terminate': terminate
1339
+ 'MainArea.create': create,
1340
+ 'MainArea.diff2': diff2,
1341
+ 'MainArea.getCommandIds': getCommandIds,
1342
+ 'MainArea.handleClick': wrapCommand(handleClick),
1343
+ 'MainArea.initialize': initialize,
1344
+ 'MainArea.loadContent': wrapCommand(loadContent),
1345
+ 'MainArea.render2': render2,
1346
+ 'MainArea.renderEventListeners': renderEventListeners,
1347
+ 'MainArea.resize': wrapCommand(resize),
1348
+ 'MainArea.saveState': saveState,
1349
+ 'MainArea.terminate': terminate
1680
1350
  };
1681
1351
 
1682
1352
  const listen = async () => {
1683
- registerCommands$1(commandMap);
1353
+ registerCommands(commandMap);
1684
1354
  const rpc = await WebWorkerRpcClient.create({
1685
1355
  commandMap: commandMap
1686
1356
  });
@@ -2176,11 +1846,6 @@ const endTabDrag = (state, dragState) => {
2176
1846
  return state;
2177
1847
  };
2178
1848
 
2179
- const {
2180
- getCommandIds,
2181
- registerCommands,
2182
- wrapCommand} = create$1();
2183
-
2184
1849
  const openTab = (state, groupId, tab) => {
2185
1850
  const newTab = {
2186
1851
  ...tab,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/main-area-worker",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "Main Area Worker",
5
5
  "repository": {
6
6
  "type": "git",