@lvce-editor/main-area-worker 1.4.0 → 1.6.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.
@@ -102,12 +102,6 @@ const number = value => {
102
102
  throw new AssertionError('expected value to be of type number');
103
103
  }
104
104
  };
105
- const string = value => {
106
- const type = getType(value);
107
- if (type !== String) {
108
- throw new AssertionError('expected value to be of type string');
109
- }
110
- };
111
105
 
112
106
  const isMessagePort = value => {
113
107
  return value && value instanceof MessagePort;
@@ -462,7 +456,7 @@ const getFirstEvent = (eventEmitter, eventMap) => {
462
456
  return promise;
463
457
  };
464
458
  const Message$1 = 3;
465
- const create$5$1 = async ({
459
+ const create$5 = async ({
466
460
  isMessagePortOpen,
467
461
  messagePort
468
462
  }) => {
@@ -513,7 +507,7 @@ const wrap$5 = messagePort => {
513
507
  };
514
508
  const IpcParentWithMessagePort$1 = {
515
509
  __proto__: null,
516
- create: create$5$1,
510
+ create: create$5,
517
511
  signal: signal$1,
518
512
  wrap: wrap$5
519
513
  };
@@ -732,7 +726,7 @@ const getErrorResponse = (id, error, preparePrettyError, logError) => {
732
726
  const errorProperty = getErrorProperty(error, prettyError);
733
727
  return create$1$2(id, errorProperty);
734
728
  };
735
- const create$5 = (message, result) => {
729
+ const create$3 = (message, result) => {
736
730
  return {
737
731
  jsonrpc: Two$1,
738
732
  id: message.id,
@@ -741,7 +735,7 @@ const create$5 = (message, result) => {
741
735
  };
742
736
  const getSuccessResponse = (message, result) => {
743
737
  const resultProperty = result ?? null;
744
- return create$5(message, resultProperty);
738
+ return create$3(message, resultProperty);
745
739
  };
746
740
  const getErrorResponseSimple = (id, error) => {
747
741
  return {
@@ -1065,7 +1059,7 @@ const remove = id => {
1065
1059
  };
1066
1060
 
1067
1061
  /* eslint-disable @typescript-eslint/explicit-function-return-type */
1068
- const create$3 = rpcId => {
1062
+ const create$2 = rpcId => {
1069
1063
  return {
1070
1064
  async dispose() {
1071
1065
  const rpc = get$1(rpcId);
@@ -1103,12 +1097,12 @@ const create$3 = rpcId => {
1103
1097
 
1104
1098
  const {
1105
1099
  set: set$2
1106
- } = create$3(ExtensionHostWorker);
1100
+ } = create$2(ExtensionHostWorker);
1107
1101
 
1108
1102
  const {
1109
1103
  invokeAndTransfer,
1110
1104
  set: set$1
1111
- } = create$3(RendererWorker);
1105
+ } = create$2(RendererWorker);
1112
1106
  const sendMessagePortToExtensionHostWorker$1 = async (port, rpcId = 0) => {
1113
1107
  const command = 'HandleMessagePort.handleMessagePort2';
1114
1108
  await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToExtensionHostWorker', port, command, rpcId);
@@ -1118,7 +1112,7 @@ const toCommandId = key => {
1118
1112
  const dotIndex = key.indexOf('.');
1119
1113
  return key.slice(dotIndex + 1);
1120
1114
  };
1121
- const create$2 = () => {
1115
+ const create$1 = () => {
1122
1116
  const states = Object.create(null);
1123
1117
  const commandMapRef = {};
1124
1118
  return {
@@ -1204,14 +1198,17 @@ const {
1204
1198
  getCommandIds,
1205
1199
  registerCommands,
1206
1200
  set,
1207
- wrapCommand} = create$2();
1201
+ wrapCommand} = create$1();
1208
1202
 
1209
- const create$1 = (uid, uri, x, y, width, height, platform, assetDir) => {
1203
+ const create = (uid, uri, x, y, width, height, platform, assetDir) => {
1210
1204
  const state = {
1211
1205
  assetDir,
1206
+ layout: {
1207
+ activeGroupId: '',
1208
+ direction: 'horizontal',
1209
+ groups: []
1210
+ },
1212
1211
  platform,
1213
- statusBarItemsLeft: [],
1214
- statusBarItemsRight: [],
1215
1212
  uid
1216
1213
  };
1217
1214
  set(uid, state, state);
@@ -1253,6 +1250,16 @@ const handleClick = async (state, name) => {
1253
1250
  return state;
1254
1251
  };
1255
1252
 
1253
+ const handleClickCloseTab = (state, groupId, tabId) => {
1254
+ // TODO
1255
+ return state;
1256
+ };
1257
+
1258
+ const handleClickTab = async (state, groupIndex, index) => {
1259
+ // TODO mark that tab as active (if it is a valid group index and index)
1260
+ return state;
1261
+ };
1262
+
1256
1263
  const id = 7201;
1257
1264
  const sendMessagePortToExtensionHostWorker = async port => {
1258
1265
  await sendMessagePortToExtensionHostWorker$1(port, id);
@@ -1295,7 +1302,7 @@ const loadContent = async state => {
1295
1302
  activeGroupId: '0',
1296
1303
  direction: 'horizontal',
1297
1304
  groups: [{
1298
- activeTabId: '',
1305
+ activeTabId: tabs.length > 0 ? tabs[0].id : undefined,
1299
1306
  direction: 'horizontal',
1300
1307
  focused: false,
1301
1308
  id: '0',
@@ -1306,263 +1313,13 @@ const loadContent = async state => {
1306
1313
  };
1307
1314
  };
1308
1315
 
1309
- let idCounter = 0;
1310
- const create = () => {
1311
- idCounter++;
1312
- return idCounter;
1313
- };
1314
-
1315
- const getTitle = (uri, homeDir) => {
1316
- if (!uri) {
1317
- return '';
1318
- }
1319
- return uri;
1320
- };
1321
- const getLabel = uri => {
1322
- if (uri.startsWith('settings://')) {
1323
- return 'Settings';
1324
- }
1325
- if (uri.startsWith('simple-browser://')) {
1326
- return 'Simple Browser';
1327
- }
1328
- return uri;
1329
- // return Workspace.pathBaseName(uri)
1330
- };
1331
-
1332
- /**
1333
- *
1334
- * @param {string} uri
1335
- * @returns
1336
- */
1337
- const getFileIcon = uri => {
1338
- if (uri === 'app://keybindings') {
1339
- return `MaskIconRecordKey`;
1340
- }
1341
- if (uri.startsWith('extension-detail://')) {
1342
- return `MaskIconExtensions`;
1343
- }
1344
- return '';
1345
- };
1346
-
1347
- const Preview = 1 << 4;
1348
-
1349
- // @ts-nocheck
1350
-
1351
- const focusIndex = async (state, index) => {
1352
- const {
1353
- activeGroupIndex,
1354
- groups,
1355
- tabHeight,
1356
- uid
1357
- } = state;
1358
- const group = groups[activeGroupIndex];
1359
- const {
1360
- editors
1361
- } = group;
1362
- const oldActiveIndex = group.activeIndex;
1363
- if (index === oldActiveIndex) {
1364
- return {
1365
- commands: [],
1366
- newState: state
1367
- };
1368
- }
1369
- const newGroup = {
1370
- ...group,
1371
- activeIndex: index
1372
- };
1373
- const newGroups = [...groups.slice(0, activeGroupIndex), newGroup, ...groups.slice(activeGroupIndex + 1)];
1374
- const newState = {
1375
- ...state,
1376
- groups: newGroups
1377
- };
1378
- const editor = editors[index];
1379
- const {
1380
- x
1381
- } = group;
1382
- const y = group.y + tabHeight;
1383
- const {
1384
- width
1385
- } = group;
1386
- const contentHeight = group.height - tabHeight;
1387
- const id = await ViewletMap.getModuleId(editor.uri);
1388
- const oldEditor = editors[oldActiveIndex];
1389
- const oldId = await ViewletMap.getModuleId(oldEditor.uri);
1390
- // @ts-ignore
1391
- ViewletStates.getInstance(oldId);
1392
- const previousUid = oldEditor.uid;
1393
- number(previousUid);
1394
- const disposeCommands = Viewlet.disposeFunctional(previousUid);
1395
- const maybeHiddenEditorInstance = ViewletStates.getInstance(editor.uid);
1396
- if (maybeHiddenEditorInstance) {
1397
- const commands = Viewlet.showFunctional(editor.uid);
1398
- const allCommands = [...disposeCommands, ...commands];
1399
- return {
1400
- commands: allCommands,
1401
- newState
1402
- };
1403
- }
1404
- const instanceUid = create();
1405
- const instance = ViewletManager.create(ViewletModule.load, id, uid, editor.uri, x, y, width, contentHeight);
1406
- instance.show = false;
1407
- instance.setBounds = false;
1408
- instance.uid = instanceUid;
1409
- editor.uid = instanceUid;
1410
- const resizeCommands = ['Viewlet.setBounds', instanceUid, x, tabHeight, width, contentHeight];
1411
-
1412
- // @ts-ignore
1413
- const commands = await ViewletManager.load(instance);
1414
- // @ts-ignore
1415
- commands.unshift(...disposeCommands);
1416
- // @ts-ignore
1417
- commands.push(resizeCommands);
1418
- // @ts-ignore
1419
- commands.push(['Viewlet.append', uid, instanceUid]);
1420
- return {
1421
- commands,
1422
- newState
1423
- };
1424
- };
1425
-
1426
- // @ts-nocheck
1427
- const openUri = async (state, uri, focus = true, {
1428
- preview = false,
1429
- ...context
1430
- } = {}) => {
1316
+ const openUri = async (state, options) => {
1431
1317
  object(state);
1432
- string(uri);
1433
- const {
1434
- activeGroupIndex,
1435
- groups,
1436
- tabFontFamily,
1437
- tabFontSize,
1438
- tabFontWeight,
1439
- tabHeight,
1440
- tabLetterSpacing
1441
- } = state;
1442
- const {
1443
- x
1444
- } = state;
1445
- const y = state.y + tabHeight;
1446
- const {
1447
- width
1448
- } = state;
1449
- const contentHeight = state.height - tabHeight;
1450
- // @ts-ignore
1451
- const moduleId = await ViewletMap.getModuleId(uri, context.opener);
1452
- let activeGroup = groups[activeGroupIndex];
1453
- activeGroup ||= {
1454
- activeIndex: -1,
1455
- editors: [],
1456
- focusedIndex: -1,
1457
- height: state.height,
1458
- tabsUid: create(),
1459
- uid: create(),
1460
- width,
1461
- x,
1462
- y: 0
1463
- };
1464
- const {
1465
- activeIndex,
1466
- editors
1467
- } = activeGroup;
1468
- const previousEditor = editors[activeIndex];
1469
- let disposeCommands;
1470
- // @ts-ignore
1471
- if (previousEditor && previousEditor.uri === uri && previousEditor.opener === context.opener) {
1472
- return {
1473
- commands: [],
1474
- newState: state
1475
- };
1476
- }
1477
- for (let i = 0; i < editors.length; i++) {
1478
- const editor = editors[i];
1479
- if (editor.uri === uri &&
1480
- // @ts-ignore
1481
- editor.opener === context.opener) {
1482
- return focusIndex(state, i);
1483
- }
1484
- }
1485
- // TODO editor needs to be disposed when closing
1486
- // other tabs and closing all tabs
1487
- if (previousEditor) {
1488
- const previousUid = previousEditor.uid;
1489
- disposeCommands = Viewlet.hideFunctional(previousUid);
1490
- }
1491
- const instanceUid = create();
1492
- const instance = ViewletManager.create(ViewletModule.load, moduleId, state.uid, uri, activeGroup.x, y, activeGroup.width, contentHeight);
1493
- instance.uid = instanceUid;
1494
- // const oldActiveIndex = state.activeIndex
1495
- const tabLabel = getLabel(uri);
1496
- const tabWidth = MeasureTabWidth.measureTabWidth(tabLabel, tabFontWeight, tabFontSize, tabFontFamily, tabLetterSpacing);
1497
- const tabTitle = getTitle(uri);
1498
- const icon = getFileIcon(uri);
1499
- const newEditor = {
1500
- flags: Preview,
1501
- icon,
1502
- label: tabLabel,
1503
- moduleId,
1504
- tabWidth,
1505
- title: tabTitle,
1506
- uid: instanceUid,
1507
- uri
1508
- };
1509
- const newEditors = [...activeGroup.editors, newEditor];
1510
- const newActiveIndex = newEditors.length - 1;
1511
- const newGroup = {
1512
- ...activeGroup,
1513
- activeIndex: newActiveIndex,
1514
- editors: newEditors
1515
- };
1516
- const newGroups = [...groups.slice(0, activeGroupIndex), newGroup, ...groups.slice(activeGroupIndex + 1)];
1517
- // @ts-ignore
1518
- instance.show = false;
1519
- instance.setBounds = false;
1520
- ViewletStates.setState(state.uid, {
1521
- ...state,
1522
- activeGroupIndex: 0,
1523
- groups: newGroups,
1524
- pendingUid: instanceUid
1525
- });
1526
- if (context) {
1527
- instance.args = [context];
1528
- }
1529
- // @ts-ignore
1530
- const commands = await ViewletManager.load(instance, focus);
1531
- commands.push(['Viewlet.setBounds', instanceUid, activeGroup.x, tabHeight, activeGroup.width, contentHeight]);
1532
- let {
1533
- tabsUid
1534
- } = state;
1535
- if (tabsUid === -1) {
1536
- tabsUid = create();
1537
- }
1538
- if (disposeCommands) {
1539
- commands.push(...disposeCommands);
1540
- }
1541
- commands.push(['Viewlet.append', state.uid, instanceUid]);
1542
- if (focus) {
1543
- commands.push(['Viewlet.focus', instanceUid]);
1544
- }
1545
- const latestState = ViewletStates.getState(state.uid);
1546
- const latestPendingUid = latestState.pendingUid;
1547
- if (latestPendingUid !== instanceUid) {
1548
- return {
1549
- commands: [],
1550
- newState: state
1551
- };
1552
- }
1553
- if (!ViewletStates.hasInstance(instanceUid)) {
1554
- return {
1555
- commands,
1556
- newState: state
1557
- };
1558
- }
1318
+ object(options);
1319
+
1320
+ // TODO
1559
1321
  return {
1560
- commands,
1561
- newState: {
1562
- ...state,
1563
- groups: newGroups,
1564
- tabsUid
1565
- }
1322
+ ...state
1566
1323
  };
1567
1324
  };
1568
1325
 
@@ -1577,28 +1334,6 @@ const text = data => {
1577
1334
  const CSS_CLASSES = {
1578
1335
  EDITOR_GROUPS_CONTAINER: 'editor-groups-container'};
1579
1336
 
1580
- const renderTab = (tab, isActive) => {
1581
- return [{
1582
- childCount: 2,
1583
- className: 'MainTab',
1584
- type: Div
1585
- }, {
1586
- childCount: 1,
1587
- className: 'TabTitle',
1588
- type: Span
1589
- }, text(tab.isDirty ? `*${tab.title}` : tab.title), {
1590
- childCount: 1,
1591
- className: 'TabCloseButton',
1592
- type: Button
1593
- }, text('×')];
1594
- };
1595
- const renderTabBar = group => {
1596
- return [{
1597
- childCount: group.tabs.length,
1598
- className: 'MainTabs',
1599
- type: Div
1600
- }, ...group.tabs.flatMap(tab => renderTab(tab))];
1601
- };
1602
1337
  const renderEditor = tab => {
1603
1338
  if (!tab) {
1604
1339
  return [text('Tab not found')];
@@ -1620,6 +1355,37 @@ const renderEditor = tab => {
1620
1355
  type: Pre
1621
1356
  }, text(tab.content || '')];
1622
1357
  };
1358
+
1359
+ const HandleClick = 11;
1360
+ const HandleClickClose = 12;
1361
+ const HandleClickTab = 13;
1362
+
1363
+ const renderTab = (tab, isActive) => {
1364
+ return [{
1365
+ childCount: 2,
1366
+ className: isActive ? 'MainTab MainTabActive' : 'MainTab',
1367
+ onClick: HandleClickTab,
1368
+ type: Div
1369
+ }, {
1370
+ childCount: 1,
1371
+ className: 'TabTitle',
1372
+ type: Span
1373
+ }, text(tab.isDirty ? `*${tab.title}` : tab.title), {
1374
+ childCount: 1,
1375
+ className: 'EditorTabCloseButton',
1376
+ onClick: HandleClickClose,
1377
+ type: Button
1378
+ }, text('×')];
1379
+ };
1380
+
1381
+ const renderTabBar = group => {
1382
+ return [{
1383
+ childCount: group.tabs.length,
1384
+ className: 'MainTabs',
1385
+ type: Div
1386
+ }, ...group.tabs.flatMap(tab => renderTab(tab, tab.id === group.activeTabId))];
1387
+ };
1388
+
1623
1389
  const renderEditorGroup = group => {
1624
1390
  const activeTab = group.tabs.find(tab => tab.id === group.activeTabId);
1625
1391
  return [{
@@ -1632,6 +1398,7 @@ const renderEditorGroup = group => {
1632
1398
  type: Div
1633
1399
  }, ...renderEditor(activeTab)];
1634
1400
  };
1401
+
1635
1402
  const getMainAreaVirtualDom = layout => {
1636
1403
  return [{
1637
1404
  childCount: 1,
@@ -1684,12 +1451,16 @@ const render2 = (uid, diffResult) => {
1684
1451
  return commands;
1685
1452
  };
1686
1453
 
1687
- const HandleClick = 11;
1688
-
1689
1454
  const renderEventListeners = () => {
1690
1455
  return [{
1691
1456
  name: HandleClick,
1692
1457
  params: ['handleClick', TargetName]
1458
+ }, {
1459
+ name: HandleClickClose,
1460
+ params: ['handleClickCloseTab', 'event.target.dataset.groupIndex', 'event.target.dataset.index']
1461
+ }, {
1462
+ name: HandleClickClose,
1463
+ params: ['handleClickTab', 'event.target.dataset.groupIndex', 'event.target.dataset.index']
1693
1464
  }];
1694
1465
  };
1695
1466
 
@@ -1717,10 +1488,12 @@ const saveState = uid => {
1717
1488
  };
1718
1489
 
1719
1490
  const commandMap = {
1720
- 'MainArea.create': create$1,
1491
+ 'MainArea.create': create,
1721
1492
  'MainArea.diff2': diff2,
1722
1493
  'MainArea.getCommandIds': getCommandIds,
1723
1494
  'MainArea.handleClick': wrapCommand(handleClick),
1495
+ 'MainArea.handleClickCloseTab': wrapCommand(handleClickCloseTab),
1496
+ 'MainArea.handleClickTab': wrapCommand(handleClickTab),
1724
1497
  'MainArea.initialize': initialize,
1725
1498
  'MainArea.loadContent': wrapCommand(loadContent),
1726
1499
  'MainArea.openUri': wrapCommand(openUri),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/main-area-worker",
3
- "version": "1.4.0",
3
+ "version": "1.6.0",
4
4
  "description": "Main Area Worker",
5
5
  "repository": {
6
6
  "type": "git",